Kitty keyboard protocol not disabled on exit (CSI u sequences leak to shell)

Resolved 💬 3 comments Opened Mar 26, 2026 by khw1031 Closed Mar 29, 2026

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

  1. Open a terminal with TERM=xterm-ghostty (e.g., cmux or Ghostty)
  2. Run claude
  3. Exit Claude Code normally
  4. Press Ctrl+D or Ctrl+C in the shell
  5. Raw escape sequences like 615;5u are 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).

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗