ctrl-z suspend leaves terminal in kitty keyboard protocol mode, printing raw escape sequences
Description
When Claude Code is suspended with ctrl-z (SIGTSTP), it does not restore the terminal state before suspending. Since Claude Code enables the kitty keyboard protocol for enhanced keyboard input, this protocol remains active in the shell after suspension.
Steps to Reproduce
- Run Claude Code in a terminal that supports the kitty keyboard protocol (e.g. Ghostty, kitty, WezTerm)
- Press
ctrl-zto background Claude Code - Press
Escapein the shell
Expected Behavior
Pressing Escape works normally in the shell.
Actual Behavior
The raw CSI-u escape sequence [27u] is printed to the terminal instead of Escape being interpreted, because the kitty keyboard protocol was not disabled on suspend.
Root Cause
Claude Code should trap SIGTSTP, restore terminal state (disable kitty keyboard protocol and any other alternate modes) before suspending, and re-enable them on SIGCONT resume — similar to how terminal applications like vim handle job control.
Workaround
After ctrl-z, run one of:
printf '\e[?1u\e[?2004l' && stty sanereset
Environment
- Terminal: Ghostty (also reproducible in kitty, likely any kitty-protocol-capable terminal)
- OS: macOS
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗