[BUG] Mouse-tracking modes left enabled after session exit — bare shell floods with SGR sequences on mouse move (macOS Terminal.app)

Open 💬 2 comments Opened Jul 1, 2026 by edmiidz

Summary

When a Claude Code session exits back to the shell, the terminal's mouse-tracking modes (?1000/?1002/?1003, SGR ?1006) are not disabled on exit. Control returns to a bare zsh prompt with tracking still active, so every subsequent mouse movement over the window is echoed as raw SGR escape sequences onto the command line. Within seconds of moving the mouse, the prompt is flooded with thousands of <button>;<col>;<row>M fragments.

This is the classic "restore terminal modes on exit" defect, but for the clean-exit-to-shell path on native macOS Terminal.app — which existing reports don't cover (see "Related" below).

Environment

| | |
|---|---|
| Claude Code | 2.1.197 |
| OS | macOS 26.5.1 |
| Terminal | Apple Terminal.app build 470.2 (native, not a browser/WSL terminal) |
| TERM | xterm-256color |
| Shell | zsh |

Repro

  1. Run a Claude Code session in macOS Terminal.app.
  2. Let the session exit back to the shell prompt (normal exit; the session in my case had a task title set — window title read Investigate GitHub issue #1987).
  3. Move the mouse over the terminal window.

Expected

On exit, Claude Code disables the mouse-tracking modes it enabled (printf '\e[?1000l\e[?1002l\e[?1003l\e[?1006l'), leaving the shell in a clean state. Mouse movement produces nothing.

Actual

Tracking is left on. The bare zsh prompt receives raw mouse reports as literal text and echoes them, e.g.:

M65;92;11M65;92;11M65;92;11M64;92;11M64;92;11...M35;27;5M

(button 64/65 = scroll/move events; the trailing col;row pairs drift as the mouse moves — a literal trace of the cursor path). The prompt fills with thousands of these until reset is run.

Workaround

reset, or the surgical version:

printf '\e[?1000l\e[?1002l\e[?1003l\e[?1006l'

Related

  • #58653 (closed) — same class of leak but during agent view while scrolling, not on exit
  • #59720 — "leak on kill" but Windows + agent-view-specific, bundled with other defects
  • #72268 / #72269 — leak on resize/suspend, explicitly WSL2-only ("does NOT reproduce on macOS")
  • #66289 — browser-based xterm.js terminals only

None cover the native-macOS clean-exit path, which is what this reports: the fix is ensuring the mouse-mode teardown runs on the normal exit handler for all platforms.

View original on GitHub ↗

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