fix(terminal): stop mouse-aware apps (Claude Code) from double-opening clicked links - #132
Merged
Merged
Conversation
frenchie4111
approved these changes
Jun 1, 2026
Collaborator
There was a problem hiding this comment.
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
force-pushed
the
fix-terminal-url-double-open
branch
from
June 1, 2026 21:48
73ed66b to
3832764
Compare
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
force-pushed
the
fix-terminal-url-double-open
branch
from
June 1, 2026 21:51
3832764 to
0621826
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Clicking a URL in a Claude Code terminal tab opens it twice:
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 andshell:openExternalfired 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:linkHandlerand theWebLinksAddon) through one shared closure so routing can't drift.hover/leavecallbacks.Testing
npm run typecheck,npx electron-vite build,npx vitest run(1345 passing) all green.npm run dev:🤖 Generated with Claude Code