kubectx -c fails: current-context is not set
Routes kubectx --current failures with no selected context. Use when kubectx -c or kubectx --current reports current-context is not set. Not for unknown names or missing kubeconfig.
Nothing is selected as the current context - a fresh kubeconfig, or one where the selection was unset. kubectx -c has nothing to print, so it errors. Pick a context: run bare kubectx, choose one with kubectx [name], and kubectx -c prints it from then on.
The error
current-context is not setWhat to do
- See the available contexts:
kubectxExpected: Lists the contexts in the file.
- Select one:
kubectx [name] Expected: Prints Switched to context "[name]"..
- Verify:
kubectx -cExpected: Prints the context name, exit 0.
When this applies
- the exact current-context is not set message from kubectx -c / --current
- fresh kubeconfigs that define contexts but select none
- after kubectx -u unsets the context
When it does NOT apply
- no context exists with the name (the name is wrong)
- every kubectl command failing (the whole config is missing)
Works with
kubectx (ahmetb/kubectx)
error: current-context is not set (kubectl config current-context)
kubectl's version of the same state. Same fix: use-context with a real name.
Why it happens
current-context is just a field in the kubeconfig. Tools that merge or regenerate configs can leave it empty, and anything asking for the current selection then fails.
Edge cases
- kubectx -u deliberately unsets the context - this error right after is expected, not a bug.
- Some automation unsets the context to force an explicit choice; set it once per shell instead.
Resolved from
gh:nao1215/atago (e2e kubectx behavior spec) - https://github.com/nao1215/atago/blob/HEAD/doc/e2e/kubectx.md
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.