{"record":{"id":"d208912359bccd5d","repo":"ahmetb/kubectx","slug":"kubectl-is-required-for-shell-but-was-not-found","errorCode":null,"errorMessage":"kubectl is required for --shell but was not found in PATH","messagePattern":"kubectl is required for --shell but was not found in PATH","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/shell.go","lineNumber":55,"sourceCode":"\t\tprintEntry: func(w io.Writer, ctxName string) {\n\t\t\tfmt.Fprintf(w, \"%s kubectl context is %s in this shell — type 'exit' to leave.\\n\",\n\t\t\t\tbadgeColor.Sprint(\"[ISOLATED SHELL]\"), printer.WarningColor.Sprint(ctxName))\n\t\t},\n\t\tprintExit: func(w io.Writer, prevCtx string) {\n\t\t\tfmt.Fprintf(w, \"%s kubectl context is now %s.\\n\",\n\t\t\t\tbadgeColor.Sprint(\"[ISOLATED SHELL EXITED]\"), printer.WarningColor.Sprint(prevCtx))\n\t\t},\n\t}\n\treturn s.run(stderr)\n}\n\nfunc resolveKubectl() (string, error) {\n\tif v := os.Getenv(\"KUBECTL\"); v != \"\" {\n\t\treturn v, nil\n\t}\n\tpath, err := exec.LookPath(\"kubectl\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"kubectl is required for --shell but was not found in PATH\")\n\t}\n\treturn path, nil\n}\n\nfunc extractMinimalKubeconfig(kubectlPath, contextName string) ([]byte, error) {\n\tcmd := exec.Command(kubectlPath, \"config\", \"view\", \"--minify\", \"--flatten\",\n\t\t\"--context\", contextName)\n\tcmd.Env = os.Environ()\n\tdata, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"kubectl config view failed: %w\", err)\n\t}\n\treturn data, nil\n}\n\nfunc detectShell() string {\n\tif runtime.GOOS == \"windows\" {\n\t\t// cmd.exe always sets the PROMPT env var, so if it is present","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/shell.go#L37-L73","documentation":"Validation guard in resolveKubectl: neither the KUBECTL environment variable nor the kubectl binary in PATH could be found. The --shell feature shells out to kubectl config view to build an isolated kubeconfig, so it aborts before doing anything when kubectl is unavailable.","triggerScenarios":"Thrown at cmd/kubectx/shell.go:55 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Install kubectl and ensure it is on PATH (verify with kubectl version --client)","Alternatively set KUBECTL to the absolute path of a kubectl binary","If kubectl is installed but not found, fix PATH in your shell profile"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}