How brightdata/cli works
Purpose and Entrypoint
Bright Data CLI is a Node.js (≥20) terminal client for Bright Data APIs: web scraping, SERP/search, AI discovery, dataset pipelines, scraper lifecycle management, account administration, and persistent remote-browser control. src/index.ts is the command-line composition/dispatch entrypoint; command implementations live under src/commands/.
Command Layer
Commands translate parsed CLI arguments into product-specific API requests and output contracts. Major domains include scraping/search/discovery (src/commands/scrape.ts, src/commands/search.ts, src/commands/discover.ts), dataset pipelines (src/commands/dataset.ts), and AI scraper creation/run/heal/approval (src/commands/scraper.ts). Account/setup operations are separated into src/commands/login.ts, src/commands/init.ts, src/commands/zones.ts, and src/commands/budget.ts.
Shared API, Auth, and Configuration Boundary
All remote-service access is centralized behind the reusable client and credential/config utilities: src/utils/client.ts, src/utils/auth.ts, and src/utils/config.ts. Credentials may come from command flags, environment, or persisted OS-local files; this is the boundary between user-local state and Bright Data’s authenticated HTTP APIs. src/utils/polling.ts supports asynchronous job workflows, while src/utils/output.ts enforces terminal, JSON, and file-oriented response delivery.
Asynchronous Data Product Flows
Scrape, datasets, discovery, and scraper execution may submit server-side jobs then poll for results. Commands own product request/response shaping, shared polling owns wait/timeout behavior, and domain types document payload contracts in src/types/scrape.ts, src/types/dataset.ts, src/types/discover.ts, and src/types/scraper.ts. Scraper operations implement a longer control flow: trigger AI generation or refactoring, retry/back off on capacity limits, poll progress, and optionally stop at or continue through a human approval gate.
Persistent Browser Subsystem
Browser control is architecturally distinct from ordinary request/response commands. A local daemon retains Scraping Browser connections and session state between CLI invocations: src/browser/daemon.ts, src/browser/ipc.ts, and src/browser/lifecycle.ts. The browser command front end delegates navigation and interaction through IPC (src/browser/entrypoint.ts, src/browser/interaction.ts), while specialized modules create accessibility snapshots, screenshots, and per-daemon authentication tokens (src/browser/snapshot.ts, src/browser/screenshot.ts, src/browser/token.ts). This isolates local process/socket lifecycle from the remote browser service.
Agent and Integration Installation
The CLI can modify external coding-agent configuration rather than merely call Bright Data APIs. MCP registration is handled by src/commands/add-mcp.ts and src/utils/mcp-config.ts, writing Bright Data MCP server definitions into Claude Code, Cursor, or Codex config locations. AI-agent skill discovery and installation are handled by src/commands/skill.ts plus src/utils/skill-installer/installer.ts and src/utils/skill-installer/agents.ts.
Runtime and External Dependencies
The distributable is an npm TypeScript CLI, with release automation in .github/workflows/release.yml and shell installation via install.sh. Its material external systems are Bright Data’s authenticated APIs—Web Unlocker, SERP, Web Scraper/datasets, Scraper Studio AI flows, account/zone APIs, and Scraping Browser—as well as optional GitHub CLI/browser-based login and local configuration files.
Main entry points: index.ts CLI composition & dispatch · client.ts Authenticated API client · scrape.ts Scrape, search & discovery · dataset.ts Dataset pipelines
Components 18
CLI command layer
- CLI composition & dispatch
src/index.ts - Scrape, search & discovery · Shapes requests and asynchronous result contracts.
src/commands/scrape.ts - Dataset pipelines
src/commands/dataset.ts - AI scraper lifecycle · Creates, runs, heals, and approves AI scrapers.
src/commands/scraper.ts - Setup & account commands
src/commands/login.ts
Shared runtime
- Authenticated API client
src/utils/client.ts - Credentials & configuration · Resolves flags, environment, and persisted OS-local credentials.
src/utils/auth.ts - Async job polling
src/utils/polling.ts - Output delivery · Produces terminal, JSON, or file output.
src/utils/output.ts
Persistent browser
- Browser command frontend · Delegates navigation and interaction to the retained daemon.
src/browser/entrypoint.ts - Daemon IPC
src/browser/ipc.ts - Persistent browser daemon · Retains browser connections and session state across CLI invocations.
src/browser/daemon.ts - Snapshots & screenshots
src/browser/snapshot.ts
Agent integrations
- MCP registration · Writes Bright Data MCP definitions into supported coding-agent configuration.
src/commands/add-mcp.ts - Agent skill installation
src/commands/skill.ts
External and local systems
- OS-local files & agent configs
- Bright Data APIs · Includes Unlocker, SERP, datasets, Scraper Studio, account APIs, and Scraping Browser.
- Server-side jobs · Scrape, dataset, discovery, and scraper executions may run asynchronously.
Connections 27
- CLI composition & dispatch → Scrape, search & discovery: dispatches
- CLI composition & dispatch → Dataset pipelines: dispatches
- CLI composition & dispatch → AI scraper lifecycle: dispatches
- CLI composition & dispatch → Setup & account commands: dispatches
- CLI composition & dispatch → Browser command frontend: dispatches
- CLI composition & dispatch → MCP registration: dispatches
- CLI composition & dispatch → Agent skill installation: dispatches
- Scrape, search & discovery → Authenticated API client: API requests
- Dataset pipelines → Authenticated API client: API requests
- AI scraper lifecycle → Authenticated API client: AI lifecycle requests
- Setup & account commands → Authenticated API client: account requests
- Authenticated API client → Credentials & configuration: gets credentials
- Credentials & configuration → OS-local files & agent configs: reads and persists
- Authenticated API client → Bright Data APIs: authenticated HTTP
- Scrape, search & discovery → Async job polling: waits for jobs
- Dataset pipelines → Async job polling: waits for jobs
- AI scraper lifecycle → Async job polling: progress and retry
- Async job polling → Server-side jobs: polls
- Scrape, search & discovery → Output delivery: renders results
- Dataset pipelines → Output delivery: renders results
- AI scraper lifecycle → Output delivery: renders results
- Browser command frontend → Daemon IPC: navigation & interaction
- Daemon IPC → Persistent browser daemon: local messages
- Persistent browser daemon → Bright Data APIs: browser sessions
- Persistent browser daemon → Snapshots & screenshots: captures
- MCP registration → OS-local files & agent configs: writes MCP config
- Agent skill installation → OS-local files & agent configs: installs skills