Skip to content

fix(terminal): stop mouse-aware apps (Claude Code) from double-opening clicked links - #132

Merged
big-guy merged 2 commits into
ness-dev:mainfrom
big-guy:fix-terminal-url-double-open
Jun 1, 2026
Merged

fix(terminal): stop mouse-aware apps (Claude Code) from double-opening clicked links#132
big-guy merged 2 commits into
ness-dev:mainfrom
big-guy:fix-terminal-url-double-open

Conversation

@big-guy

@big-guy big-guy commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Problem

Clicking a URL in a Claude Code terminal tab opens it twice:

  • single click → two external browser tabs
  • Cmd / Cmd+Shift click → one external and one in-Harness browser tab

A raw shell tab behaves correctly.

Root cause (confirmed live)

A Claude Code tab enables xterm mouse tracking. On macOS, xterm only treats Alt+click as a selection-force gesture, so plain / Cmd / Cmd+Shift clicks are all forwarded to the PTY as SGR mouse reports (\x1b[<btn;col;row M/m). Claude Code then opens the clicked URL itself — always external, since the report carries no Cmd bit — in addition to Harness's own xterm link handler firing.

So a single click is consumed by two processes: Harness's renderer (modifier-aware) and the Claude CLI (modifier-blind external). A shell has no mouse mode, so the click is never forwarded → single, correct open.

Verified with instrumentation in npm run dev: on each Claude-tab click, Harness's handler fired once and shell:openExternal fired once, while the same click was forwarded to the PTY as a mouse report — the invisible second opener was Claude.

Fix

src/renderer/components/XTerminal.tsx:

  • Route both link providers (the OSC 8 linkHandler and the WebLinksAddon) through one shared closure so routing can't drift.
  • Track the URL under the pointer via the providers' hover/leave callbacks.
  • In the terminal→PTY data path, withhold a click's mouse-report bytes while the pointer is over a link. Claude never sees the click (can't open the URL); Harness's link handling still fires → the link opens exactly once and honors the Cmd/Ctrl modifier. Non-link clicks and motion/wheel reports pass through untouched, so the app's mouse UI keeps working.

Testing

  • npm run typecheck, npx electron-vite build, npx vitest run (1345 passing) all green.
  • Manually verified live in npm run dev:
    • Claude tab: single click → one external tab; Cmd / Cmd+Shift → one in-Harness tab only.
    • Shell tab: unchanged.
    • Objective log confirmation that the click's mouse-report was withheld from the PTY on each link click.

🤖 Generated with Claude Code

@big-guy
big-guy marked this pull request as ready for review May 30, 2026 03:29
@big-guy
big-guy requested a review from frenchie4111 May 30, 2026 03:29
@big-guy big-guy self-assigned this May 30, 2026

@frenchie4111 frenchie4111 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Tightly scoped, well-explained fix with the right comments and a sensible activateUri consolidation. The release-without-press and right-click-swallow edges are theoretical — not blocking. A vitest for isMouseButtonReport would be a nice follow-up.

Comment left on behalf of @frenchie4111 by Claude via Harness.

@big-guy
big-guy force-pushed the fix-terminal-url-double-open branch from 73ed66b to 3832764 Compare June 1, 2026 21:48
big-guy and others added 2 commits June 1, 2026 17:50
Root cause (confirmed live): a Claude Code tab enables xterm mouse
tracking. On macOS xterm only treats Alt+click as a selection-force
gesture, so plain / Cmd / Cmd+Shift clicks are all forwarded to the PTY
as SGR mouse reports. Claude Code then opens the clicked URL itself
(always external — the report carries no Cmd bit) *in addition* to
Harness's own xterm link handler firing. Result: a single click opens
twice (two external; or external + in-app with a modifier). A shell tab
has no mouse mode, so the click is never forwarded and it behaved
correctly — which is why this only reproduced in Claude tabs.

Fix: route both link providers (the OSC 8 linkHandler and the
WebLinksAddon) through one shared closure, and track the URL under the
pointer via their hover/leave callbacks. In the terminal→PTY data path,
withhold a click's mouse-report bytes while the pointer is over a link.
Claude no longer sees the click (so it can't open the URL), while
Harness's link handling still fires — the link opens exactly once and
honors the Cmd/Ctrl modifier. Non-link clicks (and motion/wheel reports)
pass through untouched so the app's mouse UI keeps working.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Export the helper and add a vitest exercising the SGR mouse-report
matcher: button presses/releases (incl. modifier bits) match; motion
(0x20) and wheel (0x40) reports are excluded so hover/scroll still
reach a mouse-aware app; non-SGR and embedded/legacy encodings are
rejected. Follow-up requested in PR review.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@big-guy
big-guy force-pushed the fix-terminal-url-double-open branch from 3832764 to 0621826 Compare June 1, 2026 21:51
@big-guy
big-guy merged commit f9ea376 into ness-dev:main Jun 1, 2026
1 check passed
@big-guy
big-guy deleted the fix-terminal-url-double-open branch June 1, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants