Skip to content

CLI: Do not auto-open the browser in storybook dev under AI agents - #35412

Merged
kasperpeulen merged 4 commits into
nextfrom
kasper/amazing-engelbart-750925
Jul 8, 2026
Merged

kasperpeulen merged 4 commits into
nextfrom
kasper/amazing-engelbart-750925

Conversation

@kasperpeulen

@kasperpeulen kasperpeulen commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Part 1 of #35411 (the SB11 default flip and the storybookjs/mcp changes are tracked separately in that issue).

What I did

When storybook dev is launched from an AI agent environment (Claude Code, Codex, Cursor, Gemini CLI, opencode, Devin, Kiro, or an explicit AI_AGENT env var), the system browser is no longer auto-opened. Agents usually start Storybook to verify changes — often next to their own in-app preview browser — so the extra Chrome tab is pure noise.

  • resolveDevCommandOptions now resolves open: false whenever the existing detectAgent() (backed by std-env v4, already used for telemetry and onboarding-skip) reports an agent. The suppression is silent: no log line and no new CLI flag.
  • The existing isClaudePreviewLaunch handling (including its PORT precedence behavior) is fully unchanged; agent detection is a superset for the open gate only.
  • Humans in non-agent shells are unaffected.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

New cases in code/core/src/bin/dev-options.test.ts cover suppression via CLAUDECODE, CODEX_SANDBOX, CODEX_THREAD_ID, CURSOR_AGENT, and explicit AI_AGENT (using vi.stubEnv), plus no-regression coverage for the Claude-preview port precedence logic.

Manual testing

  1. Run a sandbox, e.g. yarn task sandbox --start-from auto --template react-vite/default-ts
  2. In the sandbox, run CLAUDECODE=1 yarn storybook — Storybook starts but no browser opens.
  3. Run yarn storybook from a regular shell (no agent env vars) — the browser still opens automatically.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

Summary by CodeRabbit

  • Bug Fixes
    • The dev command now respects agent-aware sessions when deciding whether to auto-open the browser.
    • Port selection behavior was refined to keep command-line port settings higher priority than environment-based defaults in these sessions.
    • Updated test coverage for browser-opening behavior and environment cleanup to improve reliability.

When detectAgent() (std-env) reports an AI agent environment (Claude Code,
Codex, Cursor, explicit AI_AGENT, ...), resolve open: false for storybook dev
so the system browser is not opened next to the agent's own preview.
Claude-preview launch behavior, including PORT precedence, is unchanged.

Part 1 of #35411
@kasperpeulen kasperpeulen added feature request cli ci:normal Run our default set of CI jobs (choose this for most PRs). qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Jul 8, 2026
@kasperpeulen kasperpeulen changed the title CLI: Don't auto-open the browser in under AI agents CLI: Do not auto-open the browser in storybook dev under AI agents Jul 8, 2026
Both independent reviews flagged that detectAgent() silently bypassed the
injected env seam of resolveDevCommandOptions. Expose it as an overridable
'agent' option (defaulting to ambient detection) so tests opt out with
agent: null instead of scrubbing a hand-maintained agent env-var list.
@kasperpeulen
kasperpeulen marked this pull request as ready for review July 8, 2026 10:20
@kasperpeulen
kasperpeulen requested a review from huang-julien July 8, 2026 10:20
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b12ed03-cf8e-48f5-9bff-529b72618017

📥 Commits

Reviewing files that changed from the base of the PR and between 233e024 and 5cb67b7.

📒 Files selected for processing (2)
  • code/core/src/bin/dev-options.test.ts
  • code/core/src/bin/dev-options.ts
📝 Walkthrough

Walkthrough

resolveDevCommandOptions now accepts an optional agent parameter defaulting to detectAgent(), and computes an isAgentSession flag (true for Claude preview or when an agent is detected) to suppress the open option. Tests add environment stub cleanup and new coverage for agent-detection opt-out and port precedence.

Changes

Agent-aware Open Suppression

Layer / File(s) Summary
Agent detection and open suppression logic
code/core/src/bin/dev-options.ts
Adds detectAgent import, accepts optional agent parameter (default detectAgent()), computes isAgentSession from Claude preview status or agent presence, and suppresses open for any agent session instead of only Claude preview.
Test cleanup and new coverage
code/core/src/bin/dev-options.test.ts
Adds afterEach cleanup via vi.unstubAllEnvs(), and adds/updates test cases covering Claude-preview open suppression, agent: null opt-out, and port precedence (--port vs PORT vs SBCONFIG_PORT) under agent sessions.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related issues

Possibly related PRs

  • storybookjs/storybook#35259: Both update dev option-resolution logic for Claude-preview/agent detection, affecting open suppression and port precedence behavior.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
code/core/src/bin/dev-options.test.ts (1)

118-130: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Broaden the integration matrix if you want end-to-end agent coverage detectAgent already has direct cases for Gemini CLI, opencode, Devin, and Kiro, but this test only exercises CLAUDECODE, CODEX_SANDBOX, CODEX_THREAD_ID, CURSOR_AGENT, and AI_AGENT. Add the remaining signals here if you want resolveDevCommandOptions() to cover every agent path directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/core/src/bin/dev-options.test.ts` around lines 118 - 130, The
dev-options test matrix for resolveDevCommandOptions() does not cover all
agent-detection signals already handled by detectAgent. Extend the it.each table
in dev-options.test.ts to include the remaining environment markers for Gemini
CLI, opencode, Devin, and Kiro, so the browser-suppression behavior is exercised
for every agent path directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@code/core/src/bin/dev-options.test.ts`:
- Around line 118-130: The dev-options test matrix for
resolveDevCommandOptions() does not cover all agent-detection signals already
handled by detectAgent. Extend the it.each table in dev-options.test.ts to
include the remaining environment markers for Gemini CLI, opencode, Devin, and
Kiro, so the browser-suppression behavior is exercised for every agent path
directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0e205cf5-a19c-4dc2-87f2-650c29f57d42

📥 Commits

Reviewing files that changed from the base of the PR and between c0e9190 and 233e024.

📒 Files selected for processing (2)
  • code/core/src/bin/dev-options.test.ts
  • code/core/src/bin/dev-options.ts

@shilman shilman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added some questions

Comment thread code/core/src/bin/dev-options.test.ts Outdated
Comment thread code/core/src/bin/dev-options.ts
Comment thread code/core/src/bin/dev-options.ts
@huang-julien

Copy link
Copy Markdown
Contributor

let's also remove all the comments, it's not needed as obvious for us

@kasperpeulen
kasperpeulen enabled auto-merge July 8, 2026 10:53
This was referenced Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). cli feature request qa:skip Pull Requests that do not need any QA. (e.g. documentation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants