claude-code - 💡(How to fix) Fix ctrl-z suspend leaves terminal in kitty keyboard protocol mode, printing raw escape sequences [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47125Fetched 2026-04-13 05:40:48
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

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.

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.

Fix Action

Workaround

After ctrl-z, run one of:

  • printf '\e[?1u\e[?2004l' && stty sane
  • reset
RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

To fix the issue where Claude Code doesn't restore terminal state after suspension, trap SIGTSTP to disable the kitty keyboard protocol before suspending and re-enable it on SIGCONT.

Guidance

  • Trap SIGTSTP in Claude Code to restore terminal state, including disabling the kitty keyboard protocol, before suspending.
  • On SIGCONT, re-enable the kitty keyboard protocol and any other alternate modes to ensure proper terminal functionality.
  • As a temporary workaround, users can run printf '\e[?1u\e[?2004l' && stty sane or reset after suspending Claude Code with ctrl-z to manually restore terminal state.
  • Verify the fix by checking that pressing Escape in the shell after suspending and resuming Claude Code works as expected, without printing the raw CSI-u escape sequence.

Example

# Example signal handler in bash to trap SIGTSTP and SIGCONT
trap 'printf '\e[?1u\e[?2004l' && stty sane' TSTP
trap 'printf '\e[?1h\e[?2004h'' CONT

Note: This example is a simplified illustration and may need adjustments based on the actual implementation of Claude Code.

Notes

The provided workaround suggests that the issue is specific to terminals supporting the kitty keyboard protocol. The fix should ensure that Claude Code properly handles job control signals to restore terminal state.

Recommendation

Apply the workaround by running printf '\e[?1u\e[?2004l' && stty sane or reset after suspending Claude Code, until a proper fix is implemented in the code to trap SIGTSTP and SIGCONT signals.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix ctrl-z suspend leaves terminal in kitty keyboard protocol mode, printing raw escape sequences [1 comments, 2 participants]