ahmetb/kubectx · error
failed to create temp kubeconfig file: %w
Error message
failed to create temp kubeconfig file: %w
What it means
Returned by run when os.CreateTemp fails to create a temporary file for the per-context kubeconfig extracted earlier in the session setup. This happens when the OS cannot provide a temp file — typically a full/writable-missing TMPDIR, permission problems, or resource exhaustion — meaning the isolated shell session cannot be started, so the whole shell-session operation aborts with this wrapped error.
Source
Thrown at cmd/kubectx/shell_session.go:82
return fmt.Errorf("failed to extract kubeconfig for context: %w", err)
}
// Optionally transform the kubeconfig (e.g. rewrite for readonly proxy).
var cleanup func()
if s.transformKubeconfig != nil {
data, cleanup, err = s.transformKubeconfig(data)
if err != nil {
return err
}
if cleanup != nil {
defer cleanup()
}
}
// Write kubeconfig to temp file.
tmpFile, err := os.CreateTemp("", "kubectx-shell-*.yaml")
if err != nil {
return fmt.Errorf("failed to create temp kubeconfig file: %w", err)
}
tmpPath := tmpFile.Name()
defer os.Remove(tmpPath)
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
return fmt.Errorf("failed to write temp kubeconfig: %w", err)
}
tmpFile.Close()
// Print entry message.
s.printEntry(stderr, s.target)
// Detect and start shell.
shellBin := detectShell()
cmd := exec.Command(shellBin)
cmd.Stdin = os.Stdin
cmd.Stdout = os.StdoutView on GitHub (pinned to 12ad6fb22e)
Solutions
- Check TMPDIR is writable and has free space (df -h /tmp)
- Set TMPDIR to a writable directory and retry
- Check for inode exhaustion if disk space looks fine
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubectx/shell_session.go:82 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ahmetb/kubectx@12ad6fb22e (2026-09-02).
Data as JSON: /api/errors/0c08090837ab4f8f.
Report an issue: GitHub.