-
Notifications
You must be signed in to change notification settings - Fork 229
Description
Problem
When using dev-browser in extension mode (connecting to the user's existing Chrome browser), multiple Claude Code instances cannot safely share the same relay server. If two agents both create a page named "github", they collide. Events from one agent's pages leak to all connected clients.
This is a real pain point for users running orchestrated multi-agent workflows where sub-agents need browser access to the user's logged-in sessions.
Existing Solutions Don't Cover This
I'm aware of the excellent work in:
- PR feat: add multi-port support for parallel server instances #15 (multi-port support) - Gives each agent its own server/browser
- PR Multi-agent concurrency and external browser mode #24 (multi-agent concurrency) - Dynamic port allocation for external browser mode
Both solve multi-agent for standalone/external browser modes. But for extension mode, where the user wants agents to share their logged-in Chrome browser, there's no solution. Running multiple relay servers doesn't help since the extension can only connect to one relay at a time.
Proposed Solution
Add session-based isolation to the relay server:
Claude Code 1 (session: abc) ──┐
├──► Relay Server ──► Extension ──► User's Chrome
Claude Code 2 (session: xyz) ──┘
Each client gets an auto-generated session ID. Pages are namespaced internally (session:pagename), so two agents can both have a page named "github" without collision. CDP events are routed only to the owning session.
Implementation Highlights
- Backward compatible: No session header = "default" session (existing behavior)
- No extension changes: Session logic is entirely in relay server
- Minimal API change: Optional
sessionparameter inconnect() - Idempotent startup: New
start.sh/stop.shscripts for daemon management
Working Implementation
I have a working implementation at https://github.com/parkerhancock/dev-browser (commit 8b01dba) that I'd be happy to submit as a PR once we align on the approach.
Changes Summary
| File | Change |
|---|---|
start.sh |
New - Idempotent relay startup with PID file |
stop.sh |
New - Clean relay shutdown |
src/client.ts |
Add optional session parameter to connect() |
src/relay.ts |
Session tracking, page namespacing, event routing |
SKILL.md |
Document multi-agent support |
README.md |
Document multi-agent support |
Test Results
- TypeScript check passes
- Existing tests pass (9/9)
- Manual testing with two Claude Code instances creating same-named pages confirms isolation works
Why Not Just Use PR #24's Approach?
PR #24's multi-agent support works by giving each agent its own server (on a different port) that connects to a shared external browser via CDP. This is great for external browser mode.
But in extension mode, we have a different constraint: the Chrome extension can only maintain one WebSocket connection (to one relay). We can't spawn multiple relay servers because the extension would only connect to one of them.
This solution keeps a single relay server and adds client-side session isolation within that relay. It complements PR #24 rather than competing with it.