claude-code - 💡(How to fix) Fix [BUG] SGR sequences leak into Windows terminal [3 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#48629Fetched 2026-04-16 06:55:14
View on GitHub
Comments
3
Participants
2
Timeline
6
Reactions
0
Timeline (top)
commented ×3labeled ×3

Error Message

Error Messages/Logs

Code Example

;1M35;24;;1M35;25;1M35;26;
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

I run claude code on Debian through a Windows terminal. After I undock and redock the laptop, I get weird caracters popping up randomly in the terminal, like: ";1M35;24;;1M35;25;1M35;26;".

AFAIU, these are SGR mouse tracking escape sequences leaking into the terminal as raw text. The seems to be due to Claude Code not having the chance to shut down mouse tracking before the terminal geometry changed, and the terminal is then stuck in tracking mode.

What Should Happen?

Claude Could should exit more gracefully when ssh connection is lost.

Error Messages/Logs

;1M35;24;;1M35;25;1M35;26;

Steps to Reproduce

  1. Open Windows terminal, ssh to Debian host, run Claude Code
  2. Undock laptop without stopping Claude Code
  3. Redock, network connection is reset, Claude Code has stopped, terminal is left in SGR mode

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.109

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

No response

extent analysis

TL;DR

The issue can be mitigated by properly shutting down mouse tracking in Claude Code before the terminal geometry changes, potentially through a more graceful exit when the SSH connection is lost.

Guidance

  • Investigate how Claude Code handles SSH connection loss and terminal geometry changes to identify why mouse tracking is not being shut down correctly.
  • Consider adding a hook or signal handler to Claude Code to detect when the SSH connection is lost and clean up any active mouse tracking.
  • Look into using a library or function that can help manage terminal modes and escape sequences, such as tty or termios, to ensure that the terminal is properly reset after Claude Code exits.
  • Test the issue with different terminal emulators or configurations to see if the problem is specific to Windows Terminal.

Example

No specific code example can be provided without more information about the Claude Code internals, but a general approach might involve using a signal handler to catch the SIGPIPE signal sent when the SSH connection is lost, and then calling a function to reset the terminal mode.

Notes

The exact solution will depend on the specifics of how Claude Code interacts with the terminal and handles SSH connections. Without more information about the codebase, it's difficult to provide a precise fix.

Recommendation

Apply a workaround, such as manually resetting the terminal mode after Claude Code exits, until a proper fix can be implemented in the code. This is because the issue seems to be related to how Claude Code handles connection loss and terminal geometry changes, and a workaround can provide a temporary solution until the root cause is addressed.

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