Vim mode: pressing Escape in INSERT mode on agent screen clears the entire prompt
Description
When vim mode is enabled and you're on the agent screen (accessed via claude agents, left arrow, or Ctrl-Z), typing a prompt and pressing Escape to switch from INSERT to NORMAL mode clears the entire prompt text instead of just switching vim modes.
Steps to reproduce
- Enable vim mode in Claude Code settings
- Open the agent screen (e.g. press left arrow or Ctrl-Z from the main prompt)
- Type any text (e.g.
hello world) - Press Escape to switch from INSERT to NORMAL vim mode
- The entire prompt is wiped
Expected behavior
Pressing Escape should transition from INSERT to NORMAL vim mode, leaving the typed text intact — the same behavior as on the main prompt screen.
Actual behavior
The entire prompt text is cleared and the view navigates away from the agent screen (back to the main prompt).
Root cause (from binary analysis)
The uc function (inner key handler) contains this logic:
function uc(G$) {
let F8 = Gp() && G$.name === "escape";
if ((hH === 0 || F8) && (G$.name === "escape" || G$.name === "backspace" || G$.name === "delete" || G$.ctrl && G$.key === "u"))
L("prompt"), YH(!1);
// ...
}
Gp() returns true when on the agent screen. So F8 is true whenever the user presses Escape on the agent screen — regardless of whether vim mode is active or what vim mode state (INSERT vs NORMAL) the user is in. This causes L("prompt"), YH(!1) (navigate to prompt / clear) to fire unconditionally on any Escape keypress on the agent screen, racing against and overriding the vim mode's INSERT→NORMAL transition.
The fix should gate F8 on vim mode state: only allow the escape-to-cancel behavior when vim is disabled or already in NORMAL mode (i.e. a second Escape in NORMAL mode should cancel, but the first Escape from INSERT should not).
Environment
- Claude Code 2.1.179
- Vim mode: enabled
- OS: Linux (Fedora)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗