KBCodeKB
Claude CodeUnverified

Fix Claude Code Terminal Enhanced Keyboard Mode Persisting After Exit — Kitty Keyboard Protocol / modifyOtherKeys Breaks Ctrl-C, Ctrl-D in Ghostty, Kitty, WezTerm, and tmux

After exiting Claude Code (v2.1.84 and earlier), the terminal remains in an enhanced keyboard input mode (kitty keyboard protocol / modifyOtherKeys). This causes Ctrl-C (SIGINT), Ctrl-D (EOF), and other control key combinations to stop working — they produce escape sequences like '9;5u' instead of sending the expected signals. The bug affects modern terminal emulators that support the kitty keyboard protocol (Ghostty, Kitty, WezTerm) and terminal multiplexers (tmux). The root cause is that Claude Code enables these enhanced keyboard protocols for richer input handling but fails to properly restore the terminal state on exit — specifically, it does not send the kitty keyboard pop sequence (\e[<u) or disable XTMODKEYS (\e[>4;0m). This is a regression introduced in recent v2.1.x releases. Anthropic staff (@ashwin-ant) confirmed the fix landed in v2.1.86 (March 27, 2026). Impact: 63+ reactions, 22+ comments across macOS, Linux, and Windows users. Workarounds exist — a one-line terminal reset or a Stop hook — but the definitive fix is upgrading to v2.1.86+.

Symptoms

  • Ctrl-C produces escape sequence '9;5u' instead of sending SIGINT
  • Ctrl-D produces '0;5u' instead of sending EOF
  • Terminal remains in enhanced keyboard mode after exiting Claude Code
  • Arrow keys and function keys produce unexpected escape sequences after exiting
  • Bug manifests in Ghostty, Kitty, WezTerm, and other terminal emulators that support the kitty keyboard protocol
  • Also affects tmux sessions running inside affected terminals

Error signatures

9;5u
0;5u
kitty keyboard protocol
modifyOtherKeys
enhanced keyboard mode

Possible causes

  • Claude Code enables the kitty keyboard protocol (\e[>1u push) for enhanced input handling but does not send the corresponding pop sequence (\e[<u) on exit, leaving the protocol active in the terminal
  • Claude Code enables XTMODKEYS (\e[>4;1m) for modifyOtherKeys support but does not restore it to disabled state (\e[>4;0m) on exit
  • The bug is a regression introduced in v2.1.x — earlier versions properly restored terminal state on exit
  • Modern terminal emulators (Ghostty, Kitty, WezTerm) that support these enhanced protocols are affected; older terminals that ignore the escape sequences are not

Solutions

Automatic Restoration via Claude Code Stop Hook

risk: lowgithubpublished

For users who frequently encounter this bug and cannot upgrade, a Claude Code Stop hook can automatically restore terminal state on every exit. Add a Stop hook to ~/.claude/settings.json that runs the terminal reset escape sequences whenever a Claude Code session ends.

  1. Step 1: Open or create '~/.claude/settings.json'
  2. Step 2: Add a Stop hook that sends the kitty keyboard pop and XTMODKEYS reset sequences
  3. Step 3: The hook fires on every session exit, restoring terminal state automatically
  4. Step 4: This approach also protects against future regressions that might reintroduce the bug

Commands

mkdir -p ~/.claude
cat ~/.claude/settings.json

Config examples

{
  "hooks": {
    "Stop": [{
      "matcher": "",
      "hooks": [{
        "type": "command",
        "command": "printf '\\e[<u\\e[>4;0m\\e[>0m'"
      }]
    }]
  }
}

Risks

  • Adds a small delay on every exit (printf is near-instant though)
  • Must be configured per-user — not a system-wide fix
  • The hook fires even when exiting normally, which is harmless but unnecessary on fixed versions

Verification

  • Step 1: Add the Stop hook to ~/.claude/settings.json as shown above
  • Step 2: Run 'cat ~/.claude/settings.json' → expect: the Stop hook configuration is present
  • Step 3: Start Claude Code, do some work, exit with /exit
  • Step 4: Press Ctrl-C in the shell → expect: normal SIGINT behavior (automatic restoration)
0 verified0 failed

Manual Terminal Reset — One-Line Fix for Affected Sessions

risk: lowgithubpublished

If you cannot upgrade immediately, you can manually restore the terminal to normal mode. The simplest universal fix is running the 'reset' command, which reinitializes the terminal. Alternatively, send the specific escape sequences to pop the kitty keyboard protocol stack and disable XTMODKEYS.

  1. Step 1: After exiting Claude Code (when Ctrl-C produces escape sequences), type 'reset' and press Enter
  2. Step 2: Alternatively, run 'printf "\\e[<u"' to pop the kitty keyboard protocol stack
  3. Step 3: For tmux users who find the kitty pop doesn't work: run 'printf "\\e[=0u"' to disable kitty keyboard protocol
  4. Step 4: To also reset modifyOtherKeys: run 'printf "\\e[>4;0m\\e[>0m"'
  5. Step 5: Test with Ctrl-C → expect: normal SIGINT behavior

Commands

reset
printf '\e[<u'
printf '\e[=0u'
printf '\e[>4;0m\e[>0m'

Risks

  • Temporary workaround only — must be run after every Claude Code session
  • The 'reset' command may clear terminal scrollback buffer
  • Kitty pop (\e[<u) may not work inside tmux — use \e[=0u instead

Verification

  • Step 1: Exit Claude Code, observe broken Ctrl-C (produces '9;5u')
  • Step 2: Run 'reset' or 'printf "\\e[<u"' → expect: command executes without error
  • Step 3: Press Ctrl-C → expect: displays '^C' (normal SIGINT, no escape sequence)
  • Step 4: Press Ctrl-D → expect: sends EOF normally
0 verified0 failed

Upgrade to Latest Claude Code (v2.1.86+) — Official Fix

risk: lowofficialpublished

The definitive fix: upgrade Claude Code to v2.1.86 or later. Anthropic staff confirmed the terminal's enhanced keyboard mode is now properly disabled on exit, so Ctrl-C/Ctrl-D work normally in the shell afterwards. This is the recommended solution for all users.

  1. Step 1: Check current version with 'claude --version'
  2. Step 2: If version < 2.1.86, run 'npm install -g @anthropic-ai/claude-code@latest'
  3. Step 3: Verify upgrade with 'claude --version' → expect: 2.1.86 or higher
  4. Step 4: Open a new terminal session, run claude, exit, and test Ctrl-C/Ctrl-D → expect: normal behavior (SIGINT/EOF)

Commands

claude --version
npm install -g @anthropic-ai/claude-code@latest
npm view @anthropic-ai/claude-code version

Risks

  • Upgrading may introduce other bugs from newer versions
  • If using npm version pinning, update your package.json constraint

Verification

  • Step 1: Run 'claude --version' → expect: version 2.1.86 or higher (e.g., 2.1.177 as of June 2026)
  • Step 2: Open a new terminal window and run 'claude', then type '/exit' to exit
  • Step 3: Press Ctrl-C in the shell → expect: displays '^C' (SIGINT signal, no escape sequence)
  • Step 4: Press Ctrl-D in the shell → expect: sends EOF (closes shell if at empty prompt)
0 verified0 failed

Agent JSON

Canonical machine-readable representation of this issue:

{
  "issue_id": "7b426967-7d3a-4902-bfb7-beb55068489a",
  "slug": "fix-claude-code-terminal-enhanced-keyboard-mode-persisting-after-exit-kitty-keyboard-protocol-modifyotherkeys-breaks-ctr-q5znmz",
  "verification_status": "unverified",
  "canonical_json": "https://codekb.dev/v1/issues/fix-claude-code-terminal-enhanced-keyboard-mode-persisting-after-exit-kitty-keyboard-protocol-modifyotherkeys-breaks-ctr-q5znmz"
}
← Back to all issuesPowered by CodeKB