plandex-ai/plandex · error

failed to read keypress: %s

Error message

failed to read keypress: %s

What it means

GetUserKeyInput wraps failures from keyboard.GetKey — the terminal was successfully put in raw mode but reading a keystroke failed. This is rarer than open failure and usually indicates the input stream closed or a low-level read error.

Source

Thrown at app/cli/term/prompt.go:81

	if err != nil && err.Error() == "user quit prompt" {
		os.Exit(0)
	}

	return res, err
}

func GetUserKeyInput() (rune, keyboard.Key, error) {
	if err := keyboard.Open(); err != nil {
		return 0, 0, fmt.Errorf("failed to open keyboard: %s", err)
	}
	defer func() {
		_ = keyboard.Close()
	}()

	char, key, err := keyboard.GetKey()
	if err != nil {
		return 0, 0, fmt.Errorf("failed to read keypress: %s", err)
	}

	return char, key, nil
}

func ConfirmYesNo(fmtStr string, fmtArgs ...interface{}) (bool, error) {
	color.New(ColorHiMagenta, color.Bold).Printf(fmtStr+" (y)es | (n)o", fmtArgs...)
	color.New(ColorHiMagenta, color.Bold).Print("> ")

	char, key, err := GetUserKeyInput()
	if err != nil {
		return false, fmt.Errorf("failed to get user input: %s", err)
	}

	// ctrl+c == no
	if key == keyboard.KeyCtrlC {
		return false, nil
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Re-run the command; transient read interruptions usually don't recur
  2. Make sure the terminal stays open while the prompt is active
  3. Check tmux/screen/SSH connection stability if running remotely
  4. If reproducible, test in a plain terminal without multiplexers to isolate the cause

Example fix

null
Defensive patterns

Strategy: retry

Try / catch

for attempt := 0; attempt < 2; attempt++ {
    char, key, err := term.GetUserKeyInput()
    if err == nil { use(char, key); break }
    if attempt == 1 { return fmt.Errorf("keypress unavailable: %w", err) }
}

Prevention

When it happens

Trigger: keyboard.GetKey() returns an error: stdin EOF (terminal closed, Ctrl+D on some platforms), read interrupted fatally, or device error during raw read.

Common situations: Terminal window closed while prompt waits; stdin detached mid-prompt; unusual terminal emulators or tmux/screen edge cases interrupting the raw read.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/7c8aa9da1d877842. Report an issue: GitHub.