Skip to content

Make BROWSERBASE_PROJECT_ID optional in CLI - #1803

Merged
shrey150 merged 1 commit into
mainfrom
shrey/cli-optional-project-id
Mar 10, 2026
Merged

shrey150 merged 1 commit into
mainfrom
shrey/cli-optional-project-id

Conversation

@shrey150

@shrey150 shrey150 commented Mar 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Changes

  • packages/cli/src/index.ts — hasBrowserbaseCredentials() only checks for API key
  • packages/cli/tests/mode.test.ts — Updated test to match new error message
  • packages/cli/README.md — Updated docs to reflect optional project ID

Test plan

  • Existing mode test updated
  • Manual: browse env remote with only BROWSERBASE_API_KEY set

🤖 Generated with Claude Code


Summary by cubic

Make BROWSERBASE_PROJECT_ID optional in the CLI for remote mode, so only BROWSERBASE_API_KEY is required. The project ID is still forwarded when provided.

  • Bug Fixes
    • Updated remote mode check and error message to only require BROWSERBASE_API_KEY.
    • Autodetection now defaults to remote when the API key is set; otherwise local.
    • Updated tests and @browserbasehq/browse-cli README to match.

Written for commit 99eb186. Summary will update on new commits. Review in cubic

@changeset-bot

changeset-bot Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 99eb186

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-server-v3 Patch
@browserbasehq/browse-cli Minor
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server-v4 Patch

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

@greptile-apps

greptile-apps Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces the initial open-source release of the @browserbasehq/browse-cli package and makes BROWSERBASE_PROJECT_ID optional for remote mode — only BROWSERBASE_API_KEY is now required to use Browserbase. The credential check is a one-line change in hasBrowserbaseCredentials(), the error message in assertModeSupported() is updated accordingly, and the mode.test.ts assertion and README are kept in sync.

Key changes:

  • hasBrowserbaseCredentials() now returns Boolean(process.env.BROWSERBASE_API_KEY) — project ID is no longer checked, but still forwarded to Stagehand via the environment if set
  • assertModeSupported() error message updated to reference only BROWSERBASE_API_KEY
  • mode.test.ts assertion updated to match the new error message
  • README.md documents BROWSERBASE_PROJECT_ID as optional in the environment variable table
  • CI workflow gains a cli path filter and cache entry for packages/cli/dist/**
  • killChromeProcesses uses dynamic imports for child_process.exec and util.promisify even though child_process is already a top-level import — these should be consolidated into static imports

Confidence Score: 4/5

  • Safe to merge — the credential change is minimal and correct; the only issue is a style violation with dynamic imports.
  • The core change (removing BROWSERBASE_PROJECT_ID from the required credential check) is a one-liner that is straightforward, well-tested, and correctly documented. The broader CLI initial release is well-structured with comprehensive tests. The one style issue (dynamic imports of non-optional built-ins in killChromeProcesses) does not affect correctness or security.
  • packages/cli/src/index.ts — dynamic imports of child_process.exec and util.promisify should be converted to top-level imports.

Important Files Changed

Filename Overview
packages/cli/src/index.ts Initial release of the Browse CLI (~2200 lines). Core credential change: hasBrowserbaseCredentials() now only requires BROWSERBASE_API_KEY. One issue: exec (child_process) and promisify (util) are dynamically imported in killChromeProcesses despite being non-optional built-ins already partially top-level imported.
packages/cli/tests/mode.test.ts Test updated to check for "Remote mode requires BROWSERBASE_API_KEY" matching the new error message — correct and aligned with the credential change.
packages/cli/README.md New README correctly documents BROWSERBASE_PROJECT_ID as optional and BROWSERBASE_API_KEY as the only required variable for remote mode.
packages/cli/tests/cli.test.ts Comprehensive integration test suite covering daemon lifecycle, navigation, actions, multi-tab, network capture, and error handling. Looks well-structured.
.github/workflows/ci.yml Adds cli path filter for CI, wires packages/cli/dist/** to the cache restore list, and exposes the cli output. Looks correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[browse env remote] --> B{hasBrowserbaseCredentials?}
    B -- "BROWSERBASE_API_KEY set" --> C[assertModeSupported passes]
    B -- "BROWSERBASE_API_KEY missing" --> D["Error: Remote mode requires BROWSERBASE_API_KEY"]
    C --> E[Write mode-override file]
    E --> F{Daemon running?}
    F -- Yes, same mode --> G[No restart needed]
    F -- Yes, different mode --> H[stopDaemonAndCleanup]
    H --> I[ensureDaemon]
    F -- No --> I
    I --> J[Stagehand init with env=BROWSERBASE\nBROWSERBASE_PROJECT_ID passed via env if set]
Loading

Last reviewed commit: fae93c1

Comment thread packages/cli/src/index.ts
Comment on lines +236 to +237
const { exec } = await import("child_process");
const { promisify } = await import("util");

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.

Dynamic imports of non-optional built-in modules

child_process is already statically imported at line 17 (import { spawn } from "child_process"), and util is a Node.js built-in that is always available. Both exec and promisify should be added to the existing top-level imports rather than being imported dynamically here.

Suggested change
const { exec } = await import("child_process");
const { promisify } = await import("util");
const execAsync = promisify(exec);

And at the top of the file, update the existing import and add util:

import { spawn, exec } from "child_process";
import { promisify } from "util";

Rule Used: Use top-level imports instead of dynamic imports w... (source)

Learnt From
browserbase/stagehand#1072

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Only BROWSERBASE_API_KEY is required for remote mode, matching the
core SDK changes in #1800.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@shrey150
shrey150 force-pushed the shrey/cli-optional-project-id branch from fae93c1 to 99eb186 Compare March 10, 2026 02:31
@shrey150
shrey150 changed the base branch from chris/optional-project-id to main March 10, 2026 02:31
@shrey150
shrey150 merged commit c85222c into main Mar 10, 2026
26 checks passed
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
## Summary
- Stacked on browserbase#1800
- Only `BROWSERBASE_API_KEY` is required for remote mode in the CLI
- `BROWSERBASE_PROJECT_ID` is still passed through if set, but no longer
checked

## Changes
- `packages/cli/src/index.ts` — `hasBrowserbaseCredentials()` only
checks for API key
- `packages/cli/tests/mode.test.ts` — Updated test to match new error
message
- `packages/cli/README.md` — Updated docs to reflect optional project ID

## Test plan
- [x] Existing mode test updated
- [x] Manual: `browse env remote` with only `BROWSERBASE_API_KEY` set

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Make `BROWSERBASE_PROJECT_ID` optional in the CLI for remote mode, so
only `BROWSERBASE_API_KEY` is required. The project ID is still
forwarded when provided.

- **Bug Fixes**
- Updated remote mode check and error message to only require
`BROWSERBASE_API_KEY`.
- Autodetection now defaults to `remote` when the API key is set;
otherwise `local`.
  - Updated tests and `@browserbasehq/browse-cli` README to match.

<sup>Written for commit 99eb186.
Summary will update on new commits. <a
href="https://cubic.dev/pr/browserbase/stagehand/pull/1803">Review in
cubic</a></sup>

<!-- End of auto-generated description by cubic. -->
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