ahmetb/kubectx · error

you are in a locked single-context shell, use 'exit' to leav

Error message

you are in a locked single-context shell, use 'exit' to leave

What it means

Guard error in checkIsolatedMode: the isolated-shell env var is set, but kc.Parse() failed, so the guard cannot even read the locked context name. It returns this generic message telling the user they are inside a locked single-context shell and modifications are blocked until they exit it.

Source

Thrown at cmd/kubectx/isolated_shell_guard.go:19

package main

import (
	"fmt"
	"os"

	"github.com/ahmetb/kubectx/internal/env"
	"github.com/ahmetb/kubectx/internal/kubeconfig"
)

func checkIsolatedMode() error {
	if os.Getenv(env.EnvIsolatedShell) != "1" {
		return nil
	}

	kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
	defer kc.Close()
	if err := kc.Parse(); err != nil {
		return fmt.Errorf("you are in a locked single-context shell, use 'exit' to leave")
	}

	cur, _ := kc.GetCurrentContext()
	return fmt.Errorf("you are in a locked single-context shell (\"%s\"), use 'exit' to leave", cur)
}

View on GitHub (pinned to 12ad6fb22e)

Solutions

  1. Type 'exit' to leave the isolated shell before running kubectx mutations
  2. Fix the underlying kubeconfig parse error if the shell should have started correctly
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at cmd/kubectx/isolated_shell_guard.go:19 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/805ebfbd42de59a7. Report an issue: GitHub.