STG-1672: Add --connect flag to browse CLI for existing Browserbase sessions#1889
Merged
STG-1672: Add --connect flag to browse CLI for existing Browserbase sessions#1889
Conversation
Allows connecting to an already-running Browserbase session by ID instead of always creating a new one. Uses Stagehand core's existing browserbaseSessionID support with keepAlive: true so the session stays alive after the CLI disconnects. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 7a14528 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User
participant CLI as CLI (Client Process)
participant FS as Local Filesystem (/tmp)
participant Daemon as CLI Daemon Process
participant SH as Stagehand Core
participant BB as Browserbase API
Note over User,BB: Request Flow with --connect flag
User->>CLI: browse --connect <id> open <url>
alt Mode Validation
CLI->>CLI: Check browse mode (env)
opt Mode is LOCAL
CLI-->>User: Error: --connect only supported in remote mode
end
opt --context-id also provided
CLI-->>User: Error: Mutually exclusive with --connect
end
end
alt NEW: Handle Session Connection State
CLI->>FS: NEW: Write <session-id> to browse-{session}.connect
else Command without --connect
CLI->>FS: CHANGED: Unlink browse-{session}.connect (clear stale)
end
CLI->>Daemon: ensureDaemon()
Note over Daemon: Initialization (if not running)
Daemon->>FS: NEW: Read browse-{session}.connect
FS-->>Daemon: session-id (if exists)
Daemon->>SH: NEW: Initialize Stagehand
Note over SH: Pass browserbaseSessionID & keepAlive: true
SH->>BB: Connect to existing Session ID
BB-->>SH: Session socket attached
CLI->>Daemon: sendCommand("open", url)
Daemon->>SH: page.goto(url)
SH-->>Daemon: Navigation complete
Daemon-->>CLI: Success
CLI-->>User: Command finished
Note over User,BB: browse status (Information Flow)
User->>CLI: browse status
CLI->>Daemon: getStatus()
Daemon->>FS: NEW: Read browse-{session}.connect
FS-->>Daemon: session-id
Daemon-->>CLI: Return status + browserbaseSessionId
CLI-->>User: JSON output with browserbaseSessionId
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
shrey150
added a commit
to browserbase/skills
that referenced
this pull request
Mar 25, 2026
Documents the new `browse --connect <session-id>` flag that attaches to an existing Browserbase session instead of creating a new one. Updates SKILL.md, REFERENCE.md, and EXAMPLES.md for both browser/ and browse/ skills. Sister PR: browserbase/stagehand#1889 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
Contributor
Author
|
Sister PR for skills docs: browserbase/skills#53 |
shrey150
added a commit
to browserbase/skills
that referenced
this pull request
Mar 25, 2026
Documents the new `browse --connect <session-id>` flag that attaches to an existing Browserbase session instead of creating a new one. Updates SKILL.md, REFERENCE.md, and EXAMPLES.md for the browser skill. Sister PR: browserbase/stagehand#1889 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pirate
approved these changes
Mar 25, 2026
Combine connect session logic with new userMetadata field. When connecting to existing session, use browserbaseSessionID + keepAlive. When creating new session, include userMetadata and optional context config. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pirate
approved these changes
Mar 26, 2026
This was referenced Mar 26, 2026
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.
Summary
--connect <session-id>flag to thebrowseCLI that connects to an existing Browserbase session instead of creating a new onebrowserbaseSessionIDsupport withkeepAlive: trueso the session stays alive after the CLI disconnects--context-id(writes session ID to/tmp/browse-{session}.connect, daemon reads it during initialization)Test procedure
Tests completed
browse --connect <id> open ...in local mode → errors with "only supported in remote mode"browse --connect <id> open --context-id <ctx> ...→ errors with mutual exclusion message--connectwrites session ID to connect file before daemon start--connectclear stale connect filebrowse statusoutput includesbrowserbaseSessionIdfieldbrowse --connect <valid-bb-session> open https://example.comconnects and navigatesbrowse stopdisconnects without killing the BB session🤖 Generated with Claude Code
Fixes STG-1672
Summary by cubic
Adds a
--connect <session-id>flag to thebrowseCLI to attach to an existing Browserbase session instead of creating a new one, leaving the session running after the CLI exits. Implements STG-1672.--connect <session-id>forbrowseto attach to an existing Browserbase session--context-id/tmp/browse-{session}.connect; clears when unused and restarts the daemon if the ID changesbrowserbaseSessionIDwithkeepAlive: trueso the session persists after disconnectbrowse statusnow includes abrowserbaseSessionIdfield@browserbasehq/browse-cliWritten for commit aff1bad. Summary will update on new commits. Review in cubic