[Bug] Terminal state not restored on exit, causing broken keyboard input

Status Fixed / completed
Reported on v2.1.84
Maintainer reply None cached
Activity 5 comments · opened Mar 26, 2026 · closed Apr 7, 2026

Bug Description
Claude is not restoring terminal state on exit. When I press ctrl-modified keys I just get something like 4;5u on the terminal. Claude suggested workaround to printf '\e[>0u', which worked.

Environment Info

  • Platform: darwin
  • Terminal: WezTerm
  • Version: 2.1.84
  • Feedback ID: b4e01cc0-228c-4f57-b611-38515a9881f2

Errors

[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/dimfeld/.local/share/claude/versions/2.1.84 (expected in multi-process scenarios)\n    at Jm_ (/$bunfs/root/src/entrypoints/cli.js:2740:2168)\n    at tlT (/$bunfs/root/src/entrypoints/cli.js:2740:1326)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-26T02:02:22.334Z"}]

View original on GitHub ↗

5 Comments

github-actions[bot] · 5 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/38761
  2. https://github.com/anthropics/claude-code/issues/38647
  3. https://github.com/anthropics/claude-code/issues/38840

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

dodeca-6-tope · 5 months ago

Same issue on Ghostty. This workaround in ~/.zshrc fixes it:

reset_kitty_protocol() { printf '\e[<u' >/dev/tty 2>/dev/null }
precmd_functions+=(reset_kitty_protocol)

Resets the kitty keyboard protocol before each prompt. No-op when already in normal mode.

witchof0x20 · 5 months ago

Same issue on Alacritty

yurukusa · 5 months ago

This happens when Claude Code exits without resetting the Kitty keyboard protocol, leaving your terminal in a state where key sequences like 4;5u appear instead of Ctrl+key bindings.

Fix with a PostStop hook (automatic reset on every exit):

{
  "hooks": {
    "PostStop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "printf '\\e[<u' > /dev/tty 2>/dev/null || true"
          }
        ]
      }
    ]
  }
}

This sends the Kitty protocol disable sequence (CSI < u) every time Claude Code exits, whether cleanly or not.

For immediate recovery (if your terminal is already broken):

printf '\e[<u'

Shell-level fix (belt-and-suspenders):

For zsh (~/.zshrc):

reset_kitty_protocol() { printf '\e[<u' > /dev/tty 2>/dev/null; }
precmd_functions+=(reset_kitty_protocol)

For bash (~/.bashrc):

PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND;}printf '\e[<u' > /dev/tty 2>/dev/null"

This resets the protocol before every prompt, so even if Claude Code crashes, your next prompt will be clean.

Affected terminals: WezTerm, Ghostty, Alacritty, Kitty — any terminal that supports the Kitty keyboard protocol. iTerm2 and macOS Terminal are unaffected since they don't implement it.

github-actions[bot] · 4 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.