kubehop
Fast Kubernetes context and namespace switcher. Drop-in replacement for kubectx/kubens with a built-in fuzzy finder, sub-50ms startup, and no runtime dependencies. Written in Rust.
Features
- Built-in fuzzy picker powered by nucleo (from the Helix editor) and ratatui -- no fzf required
- Single kubeconfig parse per invocation -- parsed once, used for the entire operation
- Selective parsing -- reads only
current-contextand context names; skips clusters, users, and certificates - Multi-file
KUBECONFIGsupport -- when names overlap, the first file wins - Sub-50ms startup on standard kubeconfig files
- Batch operations -- delete multiple contexts in one command
- k9s plugin support via a
picksubcommand - Shell completions for bash, zsh, and fish
- Optional fzf
fallback via
--fzfflag
Install
Homebrew
Shell installer (macOS / Linux)
|
Cargo
Pre-built binaries and a PowerShell installer are also available on the releases page.
Optional: kubectx/kubens symlinks
To use the familiar kubectx/kubens command names, create
symlinks pointing to khop. For example, with a Cargo
install:
The binary name (argv0) determines the mode:
| Invoked as | Mode |
|---|---|
khop, kubectx, kubectl-ctx |
Context switching |
kubens, kubectl-ns |
Namespace switching |
Usage
Context switching
khop List contexts (interactive if TTY)
khop <name> Switch to context
khop - Switch to previous context
khop <new>=<old> Rename context ('.' for current)
khop -c, --current Show current context name
khop -d, --delete NAME [NAME...] Delete context(s) ('.' for current)
khop -u, --unset Unset current context
khop --fzf Use external fzf for selection
khop --completion <shell> Output shell completion (bash/zsh/fish)
Namespace switching
Namespace switching requires invoking the binary as kubens
or kubectl-ns (see
symlinks above):
kubens List namespaces (interactive if TTY)
kubens <name> Switch namespace
kubens - Switch to previous namespace
kubens -f, --force <name> Switch without existence check
kubens <name> -f Same, trailing form
kubens -c, --current Show current namespace
kubens -u, --unset Reset namespace to "default"
kubens --fzf Use external fzf for selection
Shell completions
# bash
# zsh
# fish
The completion/ directory has pre-generated scripts for
both kubectx and kubens.
k9s plugin
kubehop works as a
k9s plugin for context
switching. Add this to your k9s plugins.yaml:
plugins:
kubehop:
shortCut: Ctrl-K
description: Switch context
scopes:
- all
command: khop
args:
- pick
- --switch
Architecture
src/
main.rs Entry point (~10 lines)
lib.rs Crate root, module declarations
cli.rs Arg parsing and command dispatch
dispatch.rs Argv0-based mode detection
completion.rs Shell completion generation
kubeconfig/ Selective serde parser, multi-file merge
context/ Current, switch, mutate (rename/delete), state
namespace/ List, switch, unset, per-context state
picker/ Fuzzy scoring (nucleo) + inline TUI (ratatui)
integration/ k9s plugin subcommand
Design decisions:
- Selective serde for reads, full
serde_yaml::Valueround-trip for writes, preserving fields the tool does not use - No async runtime -- all operations are local file I/O on small files
thiserrorin library modules,anyhowin the CLI layer- State file compatibility -- shares its state file path
with kubectx, so
khop -works after migrating
License
Apache-2.0