Vim mode: Ctrl+[ doesn't work as Esc equivalent (modifyOtherKeys CSI encoding not recognized)
Description
In Claude Code's vim editor mode (editorMode: "vim"), pressing Ctrl+[
does not exit insert mode, even though it's a standard, near-universal
vim keybinding equivalent to Esc. Plain Esc works fine.
Root cause
Claude Code appears to enable xterm's modifyOtherKeys terminal mode
(likely to support disambiguating Shift+Enter, Ctrl+Enter, etc.). Under
this mode, terminals that support it (confirmed on iTerm2 3.6.11) encode
Ctrl+[ as a distinct CSI sequence rather than a plain ESC byte:
- Plain Esc key:
\x1b(single byte, as always) - Ctrl+[ under modifyOtherKeys:
\x1b[27;5;91~(CSI 27 ; mod=5 (Ctrl) ;
keycode=91 ('[') ~)
Outside of an app that requests modifyOtherKeys, Ctrl+[ and Esc are
byte-identical (\x1b), which is why Ctrl+[ works fine everywhere else
(shells, vim itself, cat -v, tmux, etc.) but not inside Claude Code.
It looks like Claude Code's vim-mode Esc handling only recognizes the
literal 0x1b byte and doesn't map the modifyOtherKeys-encoded Ctrl+[
sequence back to Esc.
Repro
- Set
editorMode: "vim"in Claude Code settings. - In a terminal that supports
modifyOtherKeys(e.g. iTerm2), enter
insert mode in the vim-mode input.
- Press Ctrl+[.
- Nothing happens — still in insert mode. Esc works normally.
Verification
Confirmed via a raw pty test enabling modifyOtherKeys level 2
(\x1b[>4;2m) independent of Claude Code:
Ctrl+[ → '\x1b' '[' '2' '7' ';' '5' ';' '9' '1' '~'
Esc → '\x1b'
This isolates the behavior to the terminal's modifyOtherKeys encoding,
not tmux (escape-time, key-table bindings) or the Kitty keyboard
protocol (iTerm2 3.6.11 doesn't support Kitty protocol and a Kitty-mode
test on this terminal produced plain \x1b for Ctrl+[, ruling it out).
Environment
- Terminal: iTerm2 Build 3.6.11
- Multiplexer: tmux (escape-time 10ms; confirmed not a factor)
Expected behavior
Ctrl+[ should be treated as equivalent to Esc in vim mode, matching
standard vim/Neovim behavior, by recognizing the modifyOtherKeys-encoded
form of Ctrl+[ (and ideally Ctrl+[key] combos generally) in addition to
the plain ESC byte.