Open feature request

Webview follows chat: clicking an AI chat tab should bring that chat's webview forward

noah · 5d ago

ah 1.0.705 insiders (build fcc15c44) · adom-vscode 1.1.124 · adom/core 4.15.3 · Claude Code 2.1.318 · Windows

The ask

I run one Claude Code chat per project and one Hydrogen webview per chat: the project's AI Flow viewer, its wiki page, its editor. The webview should follow the chat. When I click a chat tab in VS Code, that chat's webview should come to the front of the right pane at once, and my typing should stay in the chat.

What exists today

Nothing is built in. Claude built a prototype in my workspace, Context Keeper, a small Python service that will be published as adom/context-keeper. It works now, but it has to guess things Hydrogen already knows, so it would be better as a Hydrogen feature.

The prototype uses three things:

  • The active chat: adom-vscode's tab census, GET /tabs and the SSE GET /tabs/events on :8821.
  • The webviews: the workspace API. It polls GET /api/workspaces/editor/local/workspace/current/tabs once a second (about 3 ms per call) and switches with POST .../active-tab {panelId, tabId}.
  • Focus: active-tab also moves focusedPanelId to the webview's pane. So after each switch it activates the VS Code tab again, which keeps keyboard focus in the chat.

What a day of use taught us (three rewrites)

  1. "The webview in front when you leave a chat" is the wrong rule. Other chats' AIs open and refresh their own webviews (adom-cli hydrogen webview open-or-refresh, adom-aiflow, hero-studio). That pushes them to the front while you are in a different chat.
  2. "The last tab you clicked in this chat" is also wrong. People click through tabs just to look. 15 clicks in 30 s relinked a chat to whatever tab came last.
  3. Guessing who opened a tab is unreliable. The prototype searches the last few seconds of Claude Code transcripts for a tool call that names the tab.
    • adom-aiflow ... prompt brings its viewer forward without printing the viewer's name.
    • Two AI Flow tabs share the URL http://8893.localhost:47083/, so the port doesn't identify one either.
    • So the prototype took the viewer coming forward for a user click.
  4. VS Code reports bursts of chat changes. The census reports 5 to 7 changes of active chat within one second, several times an hour, with no click. Each one causes a webview switch. The cause is unknown: it could be the census or a pane relayout.
  5. The switch has to be instant. A 0.4 s wait to absorb the bursts was rejected as obnoxious.

What works now (Context Keeper v0.3.1):

  • Links are sticky, and each webview belongs to one chat.
  • A chat with no webview takes the tab its own AI opens, or the tab you stay on for 8 s.
  • Switching is instant.

What would make it exact

  1. Record who opened a tab. When a webview tab is created or refreshed through the workspace API or open-or-refresh, store the calling AI thread on the tab, for example panelState.openedBy {thread, sessionId, at}.
    • Take it from X-Adom-Caller-* / ADOM_AI_THREAD, plus CLAUDE_CODE_SESSION_ID when present.
    • Return it from GET /tabs.
    • This replaces all the guessing behind points 1 to 3.
  2. Say who changed the active tab. The workspace_updated SSE event carries no detail. An event like {type: "tab_activated", panelId, tabId, source: "user" | "api", caller} would let a follower tell your click from an AI's open.
  3. Add an activate call that keeps focus. For example POST /active-tab {panelId, tabId, focus: false}: it brings the tab forward without moving focusedPanelId. A follower would then not need a second call to hand focus back to VS Code.
  4. Or build it in, as a "Webview follows chat" setting. Hydrogen already knows the AI chat tabs (the AI Threads census) and, with 1, which tabs each thread opened. It could do this with no guessing:
    • When a chat gets focus, bring forward the webview that chat's thread opened most recently, or the one the user pinned to it.
    • Never take a webview that belongs to another open chat.
    • Never hide the AI Threads panel.

Related, not the same: adom/hydrogen#40 (durable app tags for AI threads).

The prototype's rules and tests (28 cases) are ready to share if they help with a PR against hydrogen-desktop.

0 Replies

Log in to reply.