[BUG] `claude attach` ignores CLAUDE_CODE_DISABLE_MOUSE and CLAUDE_CODE_DISABLE_MOUSE_CLICKS — mouse capture always on in attached background sessions

Status Open
Reported on v2.1.270
Maintainer reply None cached
Activity 1 comment · opened Sep 13, 2026

Preflight Checklist

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

What's Wrong?

Attached background sessions (claude attach <id>) enable xterm mouse reporting unconditionally, ignoring both documented opt-outs. A directly-launched claude in the same terminal, same shell, same version honors them correctly.

Practical effect on Linux: middle-click PRIMARY-selection paste is swallowed for the entire time you are attached, and there is no way to opt out. Shift+middle-click (the terminal's own escape hatch) is the only workaround, and it isn't available in every terminal.

This is the same root cause named in the comment that closed #73443 on 2026-08-17 — "background/attached sessions ignored the CLAUDE_CODE_DISABLE_MOUSE / CLAUDE_CODE_DISABLE_MOUSE_CLICKS opt-outs" — so either that fix regressed, or it never covered the claude attach entry point.

What Should Happen?

CLAUDE_CODE_DISABLE_MOUSE=1 should suppress mouse capture in attached sessions as it does in directly-launched ones, per https://code.claude.com/docs/en/fullscreen#keep-native-text-selection ("set CLAUDE_CODE_DISABLE_MOUSE=1 to opt out of mouse capture ... your terminal handles selection natively"). The docs carve out tui and CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN as not applying to attached background sessions, but state no such exception for the mouse opt-outs.

Error Messages/Logs

Steps to Reproduce

Steps to reproduce

# 1. control — direct session honors the opt-out (no tracking sequences)
( sleep 14; printf '/exit\n' ) | script -q -c \
  "env CLAUDE_CODE_NO_FLICKER=1 CLAUDE_CODE_DISABLE_MOUSE=1 claude" direct.log

# 2. the bug — attached session ignores it
claude --bg "reply with just: ok"    # prints a session id, e.g. 3e14dbe1
id=<that id>                         # the printed output is colorized, so set this by hand
( sleep 20 ) | timeout 26 script -q -c \
  "env CLAUDE_CODE_DISABLE_MOUSE=1 claude attach $id" attached.log

# 3. scan both
for f in direct.log attached.log; do
  echo "$f:"; for m in 1000 1002 1003 1006; do
    printf '  ESC[?%s enable=%s\n' "$m" \
      "$(grep -c -a -P "\x1b\[\?${m}h" "$f")"
  done
done

direct.log shows zero enables; attached.log shows non-zero for all four modes. (grep -c counts matching lines, so treat the numbers as zero vs. non-zero rather than exact occurrence counts.)

Interactively: attach to any background session with CLAUDE_CODE_DISABLE_MOUSE=1 set, select text elsewhere so it lands in PRIMARY, then middle-click in the prompt. Nothing pastes. Detach or exit and middle-click paste works again immediately in the same terminal.

Evidence

Each run is a script(1) pty capture of process startup, scanned for DEC private mode sets. Mouse capture is on iff ESC[?1000h/1002h/1003h/1006h appear.

| Run | Session | Env | 1000h/1002h/1003h/1006h |
|-----|-------------------------------------|-------------------------------------|---------------------------|
| C | claude (direct, fullscreen) | (none) | emitted — capture on |
| D | claude (direct, fullscreen) | CLAUDE_CODE_DISABLE_MOUSE=1 | not emitted — correct |
| F | claude attach <id> | (none) | emitted |
| E | claude attach <id> | CLAUDE_CODE_DISABLE_MOUSE=1 | emitted — BUG |
| G | claude attach <id> | CLAUDE_CODE_DISABLE_MOUSE_CLICKS=1| emitted — BUG |

D vs. E is the whole report: identical terminal, shell, version and variable; only the session type differs.

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.270

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

Notes / ruled out

  • Terminal modes are restored correctly on exit — middle-click paste works again in the same terminal the moment the session ends. No stale-state bug here.
  • Not #73320: DO_NOT_TRACK, DISABLE_TELEMETRY and CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC are all unset.
  • Not renderer-related: /tui default doesn't help, which is consistent with the docs — attached background sessions always use the fullscreen renderer.
  • vim in the same terminals has working middle-click paste throughout.
  • xclip, xsel and wl-copy are all installed.
  • Reproduces both under su claude and when logged in directly as the desktop user.

Not a duplicate of #91142 — the opposite symptom on the same code path

#91142 ("Attach to background session never enables mouse tracking") reports that claude attach enters the alt screen and enables no mouse modes, so terminals fall back to alternate-scroll and the wheel emits arrow keys. This report is the inverse: attach enables all four mouse modes and ignores the opt-outs meant to prevent that.

Byte-level captures of the mode sequence written on attach:

#91142, 2.1.241 / 2.1.252, Windows (ConPTY):
  ?1004h ?9001h ?1049h ?2004h ?1004h ?2031h ?25l …       ← no mouse modes

this report, 2.1.270, Linux/X11:
  ?1049h ?1000h ?1002h ?1003h ?1006h ?2004h ?2031h ?1004h …   ← all four, twice

Note ?9001h (win32-input-mode) in the first, absent in mine, so at minimum these are different platforms; it may also be a behavior change between 2.1.252 and 2.1.270. Either way the two reports need different fixes, and a fix for one could reintroduce the other: the direction suggested in #91142 — "have the attach client enable SGR mouse reporting itself" — is essentially what 2.1.270 does on Linux, and doing it without consulting CLAUDE_CODE_DISABLE_MOUSE / CLAUDE_CODE_DISABLE_MOUSE_CLICKS is exactly the defect reported here. Whatever lands should enable mouse reporting on attach and honor both opt-outs.

Related

  • #91142 (open) — attach enables no mouse modes at all on Windows; inverse symptom, same code path.
  • #73443 (closed 2026-08-17) — same stated root cause; this looks like a regression or an uncovered entry point.
  • #66957 (closed 2026-08-17) — the original Linux PRIMARY middle-click report, closed by pointing at CLAUDE_CODE_DISABLE_MOUSE=1; that opt-out doesn't reach attached sessions.
  • #71687 — docs gap: neither mouse variable appears on the env-vars reference page; both are documented only on the fullscreen page.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗