ctrl-z suspend leaves terminal in kitty keyboard protocol mode, printing raw escape sequences

Resolved 💬 3 comments Opened Apr 12, 2026 by Oishe Closed Apr 16, 2026

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

  1. Run Claude Code in a terminal that supports the kitty keyboard protocol (e.g. Ghostty, kitty, WezTerm)
  2. Press ctrl-z to background Claude Code
  3. Press Escape in 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 sane
  • reset

Environment

  • Terminal: Ghostty (also reproducible in kitty, likely any kitty-protocol-capable terminal)
  • OS: macOS

View original on GitHub ↗

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