kx is a kubectl wrapper that adds index-based resource selection. Run kx get <resource> once, then reference any result by number instead of typing full resource names.
Install
Requires Python 3.11+ and kubectl on your PATH.
With uv (recommended):
uv tool install kx-cli
With pipx:
pipx install kx-cli
With pip:
pip install kx-cli
As a kubectl plugin via krew (no Python required; pending krew-index acceptance):
kubectl krew install kx
alias kx="kubectl kx"
Standalone binaries (linux/macOS, amd64/arm64, no Python required) are attached to each GitHub Release.
Or try it without installing (the package is kx-cli, the command is kx):
uvx --from kx-cli kx get pods
pipx run --spec kx-cli kx get pods
Usage
List resources
kx get <resource> [--match|-m <substring>] [kubectl flags...]
Fetches resources and assigns index numbers. Any extra flags (e.g. -n <namespace>, -A) are passed through to kubectl. Use --match/-m to filter results by name (substring, case-insensitive). All-namespace listings (-A) are display-only — rows aren't indexed, since names aren't unique across namespaces; scope to a namespace to select.
Known kinds can drop the get: kx pods, kx deploy -n kube-system, kx svc --match api. This covers the built-in kinds and their kubectl shorthands (po, deploy, svc, sts, ...); existing commands take precedence, so kx ns 3 still switches namespaces (bare kx ns lists them). CRDs and other resource types still use kx get <resource>. An integer after a kind is an index into the current state: kx po 3 (or kx get po 3) relists just that pod, erroring if index 3 isn't a pod. Multiple indexes work too: kx po 1 3.
$ kx get pods
Pods · default · 3 items
X NAME READY STATUS RESTARTS AGE
1 api-7d9f4b8c6-xkp2q 1/1 Running 0 2d
2 worker-6c8b5f7d9-mnt4r 1/1 Running 3 5h
3 postgres-0 1/1 Running 0 12d
All subsequent commands reference resources by their X index from the last kx get.
Global flags: --no-color disables styled output, -v/--version prints the installed version, and --help on any command shows usage, examples, and aliases.
Commands
| Command | Description |
|---|---|
kx get <resource> [--match/-m str] [kubectl flags...] |
List resources and assign index numbers for use with other commands; shorthand: kx (e.g. kx pods, kx po 3). |
kx describe <indexes>... [kubectl flags...] |
Show full kubectl describe output for one or more indexed resources. |
kx events <indexes>... |
Show Kubernetes events for one or more indexed resources. |
kx logs <index> [kubectl flags...] |
Stream logs for an indexed resource; aggregates across pods for Deployments, StatefulSets, DaemonSets, and Services. |
kx labels <indexes>... [--selector/-s] |
Show labels for one or more indexed resources; --selector formats output as a label selector. |
kx yaml <indexes>... [--show str] |
Print the raw YAML manifest for one or more indexed resources; --show filters to specific top-level fields. |
kx delete <indexes>... [--yes/-y] |
Delete one or more indexed resources (prompts for confirmation unless --yes). |
kx edit <index> [kubectl flags...] |
Open an indexed resource in your editor via kubectl edit. |
kx exec <index> [<cmd>...] [kubectl flags...] |
Open an interactive shell in an indexed pod (bash, falling back to sh). |
kx tree <index> [--index/-i] |
Show the ownership graph for an indexed resource; --index assigns indexes to tree nodes. |
kx rollout <action> <index> |
Run a rollout action (status, restart, pause, resume, history, undo) on a Deployment, StatefulSet, or DaemonSet. |
kx scale <index> <replicas> |
Scale an indexed Deployment, StatefulSet, or ReplicaSet to a given replica count. |
kx port-forward <index> <port> [kubectl flags...] |
Forward a local port to an indexed resource (Pod, Deployment, ReplicaSet, StatefulSet, DaemonSet, Service). |
kx diagnostic <index> |
Run read-only health diagnostics on an indexed Deployment, StatefulSet, DaemonSet, or Pod; alias: kx diag. |
kx namespace [<index>] |
List namespaces, or switch to an indexed one; alias: kx ns. |
kx theme [<name>] |
List available color themes or persist a choice by name or index. |
kx state [<position>] [--all/-a] |
Show current state, jump to a history position, or list all entries with --all. |
kx drop <position> |
Remove a history entry by position (shown in kx state --all). |
kx back |
Navigate to the previous kx get result. |
kx forward |
Navigate to the next kx get result. |
Example workflow
# list deployments, pick index 2
kx get deployments
kx describe 2
# check events on that deployment
kx events 2
# drill into a pod
kx get pods
kx logs 1
kx exec 1 # opens bash/sh
kx exec 1 -- env # run a specific command
# forward local port 8080 to port 80 on a service
kx get services
kx port-forward 2 8080:80
# navigate history after multiple gets
kx get pods
kx get deployments
kx logs 1 # logs from pod index 1
kx state --all # review full history
# clean up
kx delete 3
State
kx maintains a history of up to 10 kx get results in ~/.kx/state.json. A cursor tracks your current position; index-based commands always resolve against the entry at the cursor.
$ kx get pods # saves a new entry, cursor advances
$ kx get deployments # saves another entry, cursor advances
$ kx logs 1 # resolves index 1 from the pods result
$ kx state --all # lists all history entries and the current position
Use kx state <position> to jump directly to any history entry, and kx drop <position> to remove one.
Configuration
kx reads ~/.kx/config.toml; environment variables override file settings.
| Key | Env var | Default | Description |
|---|---|---|---|
max_history |
KX_MAX_HISTORY |
10 |
Number of kx get results kept in history. |
shells |
KX_SHELLS (comma-separated) |
["bash", "sh"] |
Shell candidates for kx exec. |
no_color |
KX_NO_COLOR |
false |
Disable styled output (same as --no-color). |
theme |
KX_THEME |
"github-dark" |
Color theme for all output. |
Styled output is emitted only when stdout is a terminal — piped or redirected output is plain text, so kx get pods | grep worker stays clean. The NO_COLOR convention is honored as well.
Themes
kx theme # list available themes (indexed) with a preview of each
kx theme nord # persist a theme to ~/.kx/config.toml
kx theme 3 # same, selecting by index from the kx theme listing
Prefab themes: github-dark (default), dracula, nord, gruvbox, solarized-dark, catppuccin-mocha, tokyo-night, rose-pine, mono, light (for light terminal backgrounds), and plain (no styling at all).
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
Run the CLI directly:
python -m kx.main --help
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kx_cli-0.0.7.tar.gz.
File metadata
- Download URL: kx_cli-0.0.7.tar.gz
- Upload date:
- Size: 65.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1024bfac348b7896dca35046db2fb760e088bfd97f8b1175f588bb7f8be098ce
|
|
| MD5 |
7b7310b7071f871f15ff4f735a574a0c
|
|
| BLAKE2b-256 |
c82f0f10213e18dea7f531b3bd1a1ad035a8dfd82cb13636c0da1b597ea891da
|
File details
Details for the file kx_cli-0.0.7-py3-none-any.whl.
File metadata
- Download URL: kx_cli-0.0.7-py3-none-any.whl
- Upload date:
- Size: 45.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e04ae8a422a2cc507097b81cc60509a38a796a5ff42dd8c2d02cb72e165bf27c
|
|
| MD5 |
b69c651a3da9e3e80094d3aed714b014
|
|
| BLAKE2b-256 |
faaa1718b3a5e93e2831b7d2474211afd11f654200a7318aa6c879647eecb2b6
|