Mouse click events leak as raw SGR escape sequences in terminal

Resolved 💬 3 comments Opened Apr 16, 2026 by HuMoran Closed Apr 19, 2026

Description

When running Claude Code in a terminal (macOS), mouse click events (e.g., clicking to switch windows) produce raw SGR mouse tracking escape sequences that are printed as garbled text in the Claude Code UI.

Mouse movement alone does NOT trigger the issue — only click events do.

Reproduction Steps

  1. Run claude in a terminal (iTerm2 / Terminal.app on macOS)
  2. While Claude Code is running (e.g., waiting for input, or showing "Save and close editor to continue..." after Ctrl+G), click with the mouse to switch to another window
  3. Switch back to the terminal

Observed Behavior

Raw SGR mouse tracking escape sequences appear as garbled text:

^[[0^[[<35;15;42M^[[<35;11;44M^[[<35;9;45M^[[<35;6;48M^[[<35;3;50M...

These are SGR extended mouse protocol sequences (^[[<button;x;yM) — the TUI enables mouse tracking but does not properly consume click events when the terminal loses/regains focus.

Expected Behavior

Mouse click events should be silently consumed by the TUI, not printed as raw escape sequences.

Environment

  • OS: macOS (Darwin 25.3.0, arm64)
  • Claude Code: latest channel
  • Terminal: tested in multiple terminal emulators
  • TUI mode: reproduces with both "tui": "fullscreen", CLAUDE_CODE_NO_FLICKER=1, and default renderer

Additional Context

  • Only click events produce garbled output; mouse movement is handled correctly
  • The issue is particularly noticeable when using Ctrl+G (external editor) and clicking to switch back
  • Removing all custom hooks/settings does not resolve the issue

View original on GitHub ↗

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