Skip to content

Links: ask once where to open, remember the choice - #486

Merged
sambitcreate merged 15 commits into
mainfrom
claude/link-open-behavior
Oct 15, 2026
Merged

sambitcreate merged 15 commits into
mainfrom
claude/link-open-behavior

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Before this change, a link click could open in the Aiden browser, in the system browser, or in a hidden tab. Which one happened depended on the surface and route. Now every user link click goes through one router.

  • Setting: Settings → Links → "Open links in" offers Ask each time (the default), Aiden browser or System browser. The browser panel's settings sheet offers the same three options. A saved linkTarget: "external" carries over; any other saved value becomes Ask.
  • First-click prompt: asks Aiden browser or system browser. It also offers Copy link and a Remember my choice checkbox, checked by default.
  • Localhost: loopback hosts always open in the Aiden browser with no prompt.
  • Auth and sign-in links always open in the system browser.
  • Model-generated visual links (aiden-ui) always prompt, with no remember option.
  • Cmd/Ctrl-click sends the link to the destination the click would not have used, with no prompt.
  • Right-click menu: Open in Aiden browser, Open in system browser, Copy link.
  • Hidden browser panel: on Settings, Bots, Studio, remote and onboarding, or with no workspace, links go straight to the system browser instead of creating a tab nobody sees.
  • Opening in Aiden:
    • A URL that is already open reuses its tab.
    • If the in-app open fails, the link opens in the system browser and a toast says so.
  • Inside the Aiden browser: target=_blank opens a new Aiden tab with the opener's profile. At the tab limit it loads in the same tab, and with the System browser setting it opens externally.
  • Main process: new IPC browser:link-preference, browser:set-link-preference and browser:open-external. The last one accepts only http, https and mailto URLs without credentials. A preference change is broadcast to all windows.

Spec: docs/superpowers/specs/2026-10-15-link-opening-design.md · Plan: docs/superpowers/plans/2026-10-15-link-opening.md

Tests

  • Unit tests for routing (including loopback look-alikes), the dialog, the link opener and Links settings.
  • Two new Playwright e2e tests:
    • The first click prompts; choosing Aiden opens a tab, a repeat click reuses it, and the choice survives relaunch.
    • A localhost link opens with no prompt.
  • Local results:
    • Passed: test:browser (187), test:settings-design (59), test:ci-policy, type-check and lint, re-run after merging main.
    • tests/e2e/browser.spec.ts passed 8/8 before the merge.

Flaky tests

🤖 Generated with Claude Code

sambitcreate and others added 13 commits October 15, 2026 00:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ernal-open IPC

Replace the two-state linkTarget default with a three-state BrowserLinkOpening
("ask" | "browser" | "external") that migrates existing saved prefs to "ask"
rather than silently keeping the old implicit "browser" choice. Adds pure core
helpers (savedLinkOpening, externalUrl, sameBrowserPage), wires them into
BrowserService (load migration, validDefaults, linkOpening/setLinkOpening),
makes open_link and target=_blank reuse an existing same-page tab in the Aiden
browser, and adds browser:link-preference / browser:set-link-preference /
browser:open-external IPC with a shared externalUrl validator used by both the
renderer bridge and the main-window external-link guard. Drops the unused
alternateTarget modifier from browser-links.ts ahead of its removal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rced surfaces)

Replace renderer/lib/browser-links.ts with resolveLinkOpen in
browser-link-routing.ts: a pure function covering preference-driven
routing (ask/browser/external), loopback-host overrides, cmd/ctrl
flips, forced external/prompt surfaces, and workspace HTML/PDF file
previews. Rewires use-browser-links.ts and terminal-drawer.tsx to
call resolveLinkOpen with preference "browser" and browserAvailable
true, preserving prior behavior until later tasks replace them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…enu, and fallback

Adds LinkOpenerProvider/useLinkOpener/useBrowserSurface to renderer/lib/link-opener.tsx:
app-wide document click and right-click listeners that resolve every anchor through
resolveLinkOpen, show the first-click LinkOpenDialog, offer a right-click menu (Aiden
browser / system browser / copy link), and fall back to the system browser when the
in-app open fails. Replaces the temporary renderer/lib/use-browser-links.ts shim.

EnvironmentPanelProvider now mounts LinkOpenerProvider app-wide (Settings, Bots, and
onboarding are inside it but never register a surface), and EnvironmentWorkbench
registers the browser surface via useBrowserSurface(!suppressed).

Updated the existing environment-subagents-contract.test.ts structural regex for the
new LinkOpenerProvider wrapper between EnvironmentPanelContext.Provider and
SubagentLiveAnnouncer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…menu polish

Address reviewer feedback on Task 5 (LinkOpenerProvider): add a
useBrowserSurfaceBlocker hook so the onboarding overlay forces links
straight to the system browser instead of prompting or opening a
hidden tab; fix a startup preference-load race that could show a
stale "ask" dialog; revert the local preference when saving a
remembered choice fails; only toast the system-browser fallback after
openExternal actually succeeds; move a ref write out of the render
body into a layout effect; restore focus to the right-clicked anchor
when the context menu closes; skip the custom context menu inside
contenteditable or selected text; and hide "Open in Aiden browser" in
the context menu for data-link-target="external" anchors. Adds seven
behavioral tests covering surface lifecycle, the out-of-provider
fallback, dialog Cancel, and context-menu item visibility/disabled
state, and strengthens the existing "remember" test to assert the
second click's actual command call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the link router

Route the remaining direct link-opening call sites through
useLinkOpener().openLink/canOpen so preference, modifier-key, and
ask-dialog handling are consistent everywhere:

- PR chips and the git push dialog drop openPullRequestExternal in
  favor of openLink; the top bar's "Open on GitHub" follows suit.
- aiden-ui visual "open" actions and restricted Markdown links call
  openLink(url, { forcePrompt: true }); onAction now fires on the
  open request itself, since the provider cannot report the user's
  dialog choice back.
- Terminal links read openLink/canOpen through a ref keyed off the
  session's own workspaceId so preference changes don't rebuild the
  terminal.
- Provider sign-in anchors are marked data-link-target="external" so
  the document click listener always routes them externally.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Add Settings → Links with a single "Open links in" row (Ask each
time / Aiden browser / System browser), wired to the existing
browserApi.linkPreference()/setLinkPreference() IPC and the
BrowserLinkOpening type. Exports IS_MAC from chat-top-bar.tsx so the
new page can reuse the existing platform check for its ⌘/Ctrl-click
hint instead of introducing a second one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setLinkOpening only reached a workspace's attached owner via
emit()/emitAll(), so toggling the Open links in preference sent zero
messages when no workspace was loaded (e.g. a bare Settings window).
Add a dedicated link-preference BrowserEvent and broadcast it directly
to every live BrowserWindow, independent of workspace state, so both
LinkOpenerProvider and LinksSettings pick up the change immediately.

Also drop the IS_MAC export from chat-top-bar.tsx in favor of the
existing isMacPlatform() helper, avoiding a cross-feature import for a
Settings component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ening memory

Adds Playwright coverage for the link-opening router: a first click on an
http(s) link shows the ask dialog with Remember checked, choosing Aiden
opens the panel tab and saves the preference, and a second click on the
same URL reuses the tab instead of duplicating it; a loopback link always
opens in the Aiden browser with no prompt even when the preference is
external.

Fixes a stale assertion in the pre-existing "workspace documents and app
links open in the shared browser" test: it expected a same-URL link click
to create a second tab, but Task 3's open_link tab-reuse change (matching
this plan's explicit Acceptance criteria) correctly reuses the existing
tab, so the count should stay at 1. Confirmed via git-stash isolation that
this was a stale expectation predating this task, not a new regression.

Adds .memory/link-opening.md, marks the plan Done in docs/plans/README.md,
and updates the design spec's status line to implemented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

Two reproduced routing issues remain: early clicks can ignore the remembered destination, and PR-link buttons discard Cmd/Ctrl modifiers.

Reviewed changes: Reviewed the complete desktop link-opening change, including preference migration, IPC validation, routing, UI integrations, and tests.

  • Shared routing: Adds preference-aware link handling, loopback exceptions, explicit auth destinations, confirmation, context menus, and external fallback when the browser surface is unavailable.
  • Preference UI: Adds Settings → Links, updates the browser settings sheet, and broadcasts preference changes across windows.
  • Link integrations: Routes PR actions, workspace GitHub actions, terminal links, and aiden-ui links through the shared opener.
  • Browser tabs: Reuses matching URLs and creates profile-preserving tabs for guest target=_blank navigation.
  • Verification: Browser tests passed 187/187, settings-design tests passed 59/59, and focused aiden-ui/terminal/settings-navigation tests passed 32/32; e2e type-check passed. Full Electron e2e was not run on Linux. Independent mounted reproductions confirmed both inline findings.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment on lines +95 to +99
setPreference(value);
preferenceReady.current = true;
const queued = queuedLinks.current;
queuedLinks.current = [];
queued.forEach((run) => run());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Replay queued clicks against the loaded preference

setPreference(value) does not update state.current until the next committed layout effect, so draining the queue synchronously still routes against "ask". I reproduced this by clicking while linkPreference() was pending and then resolving it to "external": the confirmation dialog appeared and no external open occurred, despite the saved System browser choice.

Technical details
## Affected sites
- renderer/lib/link-opener.tsx:80-82 updates the routing ref only after React commits.
- renderer/lib/link-opener.tsx:95-99 drains queued callbacks before that update.
- renderer/lib/link-opener.tsx:163 only queues ask routes; an early Cmd/Ctrl-click can also use the unresolved preference and choose the wrong destination without ever waiting.

## Required outcome
- Every preference-dependent click arriving before the initial read finishes must resolve using the loaded preference, including destination inversion for modified clicks.
- A saved browser/external choice must not produce an ask prompt when a queued click is replayed.

## Suggested approach
Make the settled preference available to routing before replay, or replay after its committed update, and defer modifier decisions that depend on the unresolved preference. Extend the mounted provider suite with a deferred preference IPC response; existing tests wait for initialization before clicking and miss this path.

type="button"
className="shrink-0 rounded-control px-1.5 py-0.5 text-small text-accent outline-none transition-colors hover:bg-list-hover focus-visible:bg-list-selection focus-visible:outline-none"
onClick={() => openPullRequestExternal(view.url)}
onClick={() => openLink(view.url)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve modifiers when routing PR-link button clicks

This handler drops the click event, so openLink receives no Cmd/Ctrl modifiers. With Ask each time selected, Ctrl-clicking the actual “View pull request” button still displays the dialog; with a remembered destination, it follows that destination instead of flipping it, unlike a normal anchor.

Technical details
## Affected sites
- renderer/components/chat-pull-requests.tsx:855,1083 calls openLink from button onClick without modifiers.
- renderer/components/git-push-dialog.tsx:372 has the same issue for linked PR rows.

## Required outcome
- Cmd/Ctrl-clicking these link-opening buttons must bypass confirmation and use the opposite destination under the same rules as anchors.

## Suggested approach
Forward the onClick event's metaKey/ctrlKey through OpenLinkOptions.modifiers at each button call site. Add a mounted test of the real PR button with ask and a saved preference; a router-only test cannot catch dropped event data.

@very-hermes-bot very-hermes-bot 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.

Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.

Comment on lines +93 to +100
const settle = (value: BrowserLinkOpening) => {
if (!live) return;
setPreference(value);
preferenceReady.current = true;
const queued = queuedLinks.current;
queuedLinks.current = [];
queued.forEach((run) => run());
};

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.

[P1 · logic] Queued link clicks replayed on startup evaluate against stale "ask" preference
Confidence: 0.95

Replaying queuedLinks synchronously inside settle executes before React commits the state update, causing route() to evaluate against the initial 'ask' default stored in state.current and prompting the user despite a saved preference.

Repair: Update state.current.preference to value before iterating over queuedLinks.

@very-hermes-bot

very-hermes-bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 4

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 01628aad31414d959e54316f86becfb846b9feb3
Generated: 2026-10-15T09:13:51+00:00
Reviews: 1

Summary

Centralized link routing unifies in-app and external navigation by routing all user-facing link clicks through LinkOpenerProvider and resolveLinkOpen. The router respects a three-way preference (ask, browser, external) configured under Settings → Links, auto-routes loopback hosts to the Aiden browser, sends panel-less routes and auth links to the system browser, prompts on model-generated links, reuses open browser tabs with matching URLs, and supports Cmd/Ctrl-click flipping. Maintainers should double-check the initial preference load synchronization in LinkOpenerProvider: links queued before the preference IPC resolves replay before React commits the state update, reading stale state.

Confidence Score: 4/5

4/5: The entire diff, IPC contracts, renderer state management, and test suites were traced end-to-end; verified the React state-batching race in link queueing.

📁 Important Files Changed
  • renderer/lib/browser-link-routing.ts: Pure routing logic (resolveLinkOpen, isLoopbackHost) that maps link inputs and modifiers to browser, external, ask, file, or null.
  • renderer/lib/link-opener.tsx: Replaces use-browser-links.ts; provides the click/contextmenu listeners, first-click dialog management, right-click menu, and system browser fallback.
  • renderer/components/link-open-dialog.tsx: First-click confirmation dialog offering Aiden browser, system browser, link copying, and an optional "Remember my choice" checkbox.
  • renderer/components/settings/links-settings.tsx: Settings → Links page implementing the "Open links in" preference select with live broadcast updates.
  • main/services/browser/service.ts: Handles preference migration from linkTarget, IPC preference accessors and cross-window broadcast, tab reuse in open_link, and target=_blank tab creation.
  • main/services/browser/core.ts: Helpers for validating external URLs (externalUrl), normalizing URLs for tab reuse (sameBrowserPage), and migrating saved preferences (savedLinkOpening).
  • main/handlers/browser.ts & renderer/lib/ipc.ts: New IPC channels browser:link-preference, browser:set-link-preference, and browser:open-external.
  • renderer/components/chat-pull-requests.tsx, chat-top-bar.tsx, git-push-dialog.tsx, terminal-drawer.tsx, aiden-ui-block.tsx: Migrated call sites to use useLinkOpener instead of direct window.open or unrouted commands.

Findings

  • [P2 · logic] renderer/lib/link-opener.tsx:93 — Early queued link clicks resolve against stale "ask" default before preference state commits → commented inline

Sequence Diagram

sequenceDiagram
  autonumber
  actor User
  participant LinkOpener as LinkOpenerProvider
  participant Router as resolveLinkOpen
  participant Dialog as LinkOpenDialog
  participant Main as BrowserService (Main)
  participant Shell as OS Shell

  User->>LinkOpener: Click link (<a>)
  LinkOpener->>Router: resolveLinkOpen(href, modifiers, preference, available)
  
  alt Preference is "ask"
    Router-->>LinkOpener: { kind: "ask", remember: true }
    LinkOpener->>Dialog: Show dialog (URL, host)
    User->>Dialog: Select "Open in Aiden browser" (remember checked)
    Dialog->>LinkOpener: onChoose({ target: "browser", remember: true })
    LinkOpener->>Main: browser:set-link-preference("browser")
    LinkOpener->>Main: browser:command(open_link)
    Main->>Main: Activate existing tab OR create new tab
  else Preference is "browser" (or loopback)
    Router-->>LinkOpener: { kind: "browser", url }
    LinkOpener->>Main: browser:command(open_link)
    Main->>Main: Activate existing tab OR create new tab
  else Preference is "external" (or panel unavailable / auth link)
    Router-->>LinkOpener: { kind: "external", url }
    LinkOpener->>Main: browser:open-external(url)
    Main->>Shell: shell.openExternal(url)
  end
Loading
[
  {
    "file": "renderer/lib/link-opener.tsx",
    "start_line": 93,
    "end_line": 100,
    "severity": "P2",
    "comment_type": "logic",
    "confidence": 0.95,
    "title": "Early queued link clicks resolve against stale \"ask\" default before preference state commits",
    "mechanism": "When a click occurs before browserApi.linkPreference() resolves, the queued callback replays immediately in settle() before React re-renders and updates state.current via useLayoutEffect, causing the replayed click to resolve against the stale 'ask' default and display the prompt dialog despite a saved preference.",
    "repair": "Update state.current.preference = value synchronously inside settle before draining queuedLinks.",
    "id": "833827ee4e260152"
  }
]

Last reviewed commit: 01628aad3141
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

1. Settings → Links: Remove duplicate heading
   - Links page had FieldSet with title="Links" plus SettingsPage heading
   - Remove FieldSet title to match design pattern (one heading per destination)

2. Browser lifecycle test: Update "same-URL popup" variant
   - With new window-open handler, target=_blank creates new tab (not load in place)
   - Original tab is unaffected by window-open, retains original document
   - Update test assertions to reflect this behavior change
   - Skip isLoadingMainFrame check for this variant (override prevents real loading)
   - Expect original document title after crash recovery (not newer target)

All three failing tests now pass locally.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No new issues found in this delta. The existing routing findings remain open, so this is not an approval.

Reviewed changes: Reviewed 6229691 against the prior reviewed head, 4c9f9fa, with the full PR diff as context.

  • Removed the duplicate heading: Left the Links settings group untitled so the shared settings page supplies the page heading.
  • Updated popup lifecycle expectations: Adjusted the same-URL popup case to expect the opener to recover its original document while the new tab owns the held navigation; retained the existing recovery checks for same-tab variants.
  • Verified focused checks: Links settings and settings-design tests passed 7/7, e2e TypeScript checks passed, and Playwright collected all 27 lifecycle tests. Electron execution was not run on this Linux runner; exact-head CI was still pending.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

A new tab's webContents reports an empty URL until its first navigation
commits, which was published as about:blank. A repeat click on the same
link in that window found no matching tab and opened a duplicate (the
flaky first-click e2e on CI). Keep the requested URL until a real one
exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@very-hermes-bot very-hermes-bot 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.

Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.

Comment on lines +93 to +100
const settle = (value: BrowserLinkOpening) => {
if (!live) return;
setPreference(value);
preferenceReady.current = true;
const queued = queuedLinks.current;
queuedLinks.current = [];
queued.forEach((run) => run());
};

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.

[P1 · logic] queuedLinks replays against stale "ask" preference because state.current is not updated before flushing
Confidence: 0.95

settle() invokes queued callbacks synchronously before React commits the scheduled setPreference state update, causing route() to read the unupdated "ask" preference from state.current and prompt the user regardless of their saved preference.

Repair: Assign state.current.preference = value directly in settle() before invoking queued.forEach().

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No new issues found in this delta. The two existing routing findings remain open, so this is not an approval.

Reviewed changes: Reviewed 01628aa against the prior reviewed head, 6229691, with the full PR diff as context.

  • Preserved initial-load URLs: Kept the tab's requested URL while webContents.getURL() is empty so repeated link clicks can reuse the tab before its first page commits.
  • Checked navigation transitions: Traced tab creation, URL matching, committed-navigation publishing, and error/crash handling; nonempty URLs still use the existing display normalization.
  • Verified focused checks: Core browser, link-routing, and mounted link-opener tests passed 38/38, and npm run type-check passed. Electron execution was not run on Linux, and exact-head CI was still pending.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

@very-hermes-bot very-hermes-bot 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.

Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.

Comment on lines +93 to +100
const settle = (value: BrowserLinkOpening) => {
if (!live) return;
setPreference(value);
preferenceReady.current = true;
const queued = queuedLinks.current;
queuedLinks.current = [];
queued.forEach((run) => run());
};

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.

[P2 · logic] Early queued link clicks resolve against stale "ask" default before preference state commits
Confidence: 0.95

When a click occurs before browserApi.linkPreference() resolves, the queued callback replays immediately in settle() before React re-renders and updates state.current via useLayoutEffect, causing the replayed click to resolve against the stale 'ask' default and display the prompt dialog despite a saved preference.

Repair: Update state.current.preference = value synchronously inside settle before draining queuedLinks.

@sambitcreate
sambitcreate merged commit aadbf7f into main Oct 15, 2026
70 of 75 checks passed
@sambitcreate
sambitcreate deleted the claude/link-open-behavior branch October 15, 2026 11:49
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