Kitty keyboard protocol not disabled on exit (CSI u sequences leak to shell)
Bug Description
After exiting Claude Code, the kitty keyboard protocol remains active in the terminal. This causes raw CSI u escape sequences (e.g., 615;5u) to be printed in the shell instead of normal key input handling for Ctrl+key combinations.
Environment
- Claude Code: 2.1.84
- Terminal: cmux 0.62.2 (libghostty engine)
- TERM:
xterm-ghostty - OS: macOS (Darwin 25.2.0)
- Shell: zsh
Steps to Reproduce
- Open a terminal with
TERM=xterm-ghostty(e.g., cmux or Ghostty) - Run
claude - Exit Claude Code normally
- Press
Ctrl+DorCtrl+Cin the shell - Raw escape sequences like
615;5uare printed instead of the expected behavior
Expected Behavior
Claude Code should send the kitty keyboard protocol disable sequence (\e[>0u) on exit, restoring the terminal to its previous keyboard mode.
Actual Behavior
The kitty keyboard protocol remains active after exit. The terminal continues to send CSI u encoded key events, which zsh/readline does not understand, resulting in raw sequences printed to the terminal.
Workaround
Manually reset the protocol after exiting:
printf '\e[>0u'
Or add to ~/.zshrc as a safety net:
printf '\e[>0u' 2>/dev/null
Analysis
Claude Code likely enables the kitty keyboard protocol (via \e[>1u or similar) during startup for enhanced key input handling, but does not properly restore the previous mode on exit — particularly on non-clean exits (e.g., Ctrl+C, crash, or SIGTERM).
The fix should ensure the disable sequence is sent in all exit paths (normal exit, signal handlers, cleanup hooks).
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗