Skip to main content
The Claude Code integration connects a Claude Agent SDK query loop to the Stagehand facade MCP server over MCP/stdio. One server process owns the browser, so page state survives across run, snapshot, and screenshot calls.
Stagehand ships this experimental integration from the repository rather than publishing it as a standalone adapter.

Prerequisites

  • Node.js 24 or newer
  • pnpm 11.10.0
  • An Anthropic API key for the example agent
  • A current Google Chrome installation for local browser mode

Quickstart

1

Clone and build Stagehand

2

Configure the Claude Code agent

Set CLAUDE_STAGEHAND_MODEL to select another model; the example defaults to claude-sonnet-5.
3

Choose the browser

The example defaults to Browserbase when BROWSERBASE_API_KEY is set, otherwise it uses local Chrome:
4

Run a browser task

Configuration

Keep the browser session alive

The example mounts one facade MCP server for the entire query loop and limits allowedTools to the three mcp__stagehand__ tools. A canUseTool guard denies everything else, because headless runs hang on any unanswered permission prompt. Preserve that lifetime if you adapt the integration; a new process per tool call starts a new browser. The MCP child receives only Stagehand and Browserbase configuration plus the process values required to launch Node. The host’s model credential remains in the Claude Code process.

Connect a running Claude Code CLI

The package ships a project-scoped .mcp.json that mounts the same facade server in the Claude Code CLI. Its args path is relative to the package, so start the CLI from that directory:
Claude Code inherits your shell environment, so the exports above are the only configuration. For a headless one-shot run:
run executes model-authored JavaScript in the browser. Use Browserbase for untrusted tasks and review the integration security boundary.

Claude Code integration source

Read the MCP mount, permission guard, and contract tests.