Files
cline/apps/cli
Saoud Rizwan d3d3bd8749 fix(cli): defer auto-update install until no CLI is attached to the hub (#13233)
* fix(core): bridge protections for updates landing under pre-3.0.55 clients

Three pieces, each proven against real released artifacts:

- postinstall shield: CLI versions <= 3.0.54 restart the hub daemon after a
  background auto-update even while it serves live sessions, and their
  fingerprint check then rejects every replacement hub, bricking the running
  TUI. That code is on users' machines and cannot be patched — but it runs
  only after the install completes, and it bails out harmlessly when no hub
  discovery record exists. The newly installed package's postinstall sets
  the record aside so the old updater never fires.
- superseded-record fallback: the set-aside record is also the only source
  of the auth token and pid the next new-build launch needs to retire the
  displaced hub (a port probe carries neither); ensure reads it back.
- bind retry: a hub retired on the fixed port can hold it ~2s after acking
  shutdown (watchdog force-exit); the replacement daemon retries EADDRINUSE
  for up to 5s instead of dying and leaving no hub at all.

* fix(cli): defer auto-update install until no CLI is attached to the hub

Installing while cline processes run swaps the npm package under them:
their respawn paths break on the new build fingerprint, and the updater
then restarted the hub daemon out from under live sessions (the 'Hub
connection closed (code=1006)' incident). Guarding the restart treats the
symptom; the fix is to never install under a running process.

The startup check now only records that an update is available. The
install runs at process exit, and only when the hub confirms no other
cli* client is attached — desktop sidecars and connectors ship their own
binaries, so only cli* clients make the swap unsafe. With nothing old
running at install time, no hub restart is needed at all: the next launch
retires the stale hub through the existing ensure path. Deletes
restartHubServerIfRunning, ensureCliHubServerAfterUpdate, and their
support code; manual 'cline update' still installs immediately and now
just notes that the update applies on next start.

* fix(cli): apply deferred update from the entrypoint exit sequence

The CLI entrypoint always terminates with an explicit process.exit(),
which never emits beforeExit — the hook the deferred installer waited on,
so it would never have run (caught by review). Invoke applyDeferredUpdate
directly from the entrypoint's exit sequence after disposeAll(), where
every normal termination passes; crash paths deliberately skip it. Also
clear the pending update once an install spawns so the apply is
idempotent.

* test(cli): isolate unit tests from the real ~/.cline

A full vitest run could leave a real hub daemon running against the
developer's actual ~/.cline discovery record (observed while validating
this PR: a daemon spawned from the globally installed cline binary,
attached to the real data dir). Point CLINE_DIR, CLINE_DATA_DIR, and
CLINE_HUB_DISCOVERY_PATH at a per-worker temp dir and disable auto-update
before any test file loads; subprocesses inherit the isolation via env.

* fix(core): discard the superseded discovery record once consumed

The set-aside record is one-shot recovery metadata, but nothing deleted
it, and it feeds a pid into retireDiscoveredHub's SIGTERM. Weeks later a
launch that finds no live record (routine after any retirement) could
read the stale file and signal whatever process the OS recycled that pid
onto (review finding by @abeatrix). Unlink it at every ensure resolution
that ends with a live, verified hub; failure paths keep it for the next
attempt.

* fix(cli): harden the exit-time update gate

Three review findings on the deferred-apply path:

- A wedged hub could stall an otherwise-finished CLI for tens of seconds
  via the hub client's default timeouts; the whole exit-time query is now
  bounded to 3s, with timeout counting as attached (never install unless
  the hub positively confirms).
- Sub-second commands exited before the startup version check resolved
  and silently dropped the update every time for one-shot-only usage;
  exit now grants the in-flight check a 250ms grace.
- client.list can lose a TUI's registration during transport churn while
  its session connection survives, so an empty client list is not proof
  of safety; cross-check sessions with participants. Participants rather
  than session status: finished sessions linger idle forever and must
  not pin updates, and participant-less scheduled runs live in the hub
  process, which the binary swap does not touch. Verified live: a
  session-holding client invisible to client.list defers the install,
  and the gate opens once it disconnects.

* docs(cli): fix stale beforeExit reference in the exit-gate comment

* style(cli): apply biome formatting to update deferral code

* fix(cli): let doctor see a hub whose record the update shield set aside

During the shielded update window the discovery record is renamed to
.superseded so pre-3.0.55 updaters cannot restart a busy hub. Doctor
read only the primary record, so in that window it reported the live
daemon - the one serving the user's still-open old session - as a stale
hub daemon and advised 'cline doctor fix', which kills it and reproduces
the exact 1006 incident the shield exists to prevent (found by QA).
Doctor now falls back to the set-aside record the same way the ensure
path does, and doctor fix clears the set-aside file along with the
primary record so a deliberate reset does not leave stale retirement
metadata pointing at a recyclable pid.

* fix(core): keep shielded sessions on one Hub authority (#13244)

* fix(core): recover shielded busy hub discovery

* chore(core): instrument shielded hub recovery

* fix(core): recover shielded hubs with attached clients

* fix(cli): recognize shielded hubs in doctor

* refactor(core): keep shield recovery minimal

* fix(core): retain shared Hub idle helper semantics

* chore(core): align busyness helper with the #13231 wording

The participants-only hasActiveHubSessions here duplicates the change on
bee/hub-lifecycle (this branch needs its semantics for the participant
gate). Matching that version byte for byte lets the two merges resolve
cleanly instead of conflicting. Also restores the module-registry reset
comment this branch dropped - it documents a real local-vs-CI gotcha.
2026-08-13 19:39:44 -07:00
..
2026-06-03 01:49:57 +02:00
2026-06-25 18:17:16 +02:00
2026-08-12 23:13:29 -07:00
2026-08-12 23:13:29 -07:00
2026-06-03 01:49:57 +02:00

Cline CLI

Run Cline in your terminal. Interactive chat for paired sessions, or fully headless for CI/CD and scripting. The CLI shares its agent core with the Cline VS Code extension, JetBrains plugin, and SDK, so plan/act modes, MCP servers, checkpoints, rules, skills, and provider configuration all behave the same across surfaces.

Install

npm install -g cline

For nightly builds:

npm install -g cline@nightly

Platform binaries are published for macOS, Linux, and Windows on arm64 and x64. The cline package resolves the correct binary for your platform via optional dependencies, so no Node, Bun, or Zig runtime is required at install time.

Quick start

Run interactively:

cline

Run a single prompt:

cline "Audit this package and propose fixes"

Pipe input:

cat file.txt | cline "Summarize this"

See cline --help for the full flag reference.

Use any provider

Cline supports the same providers as the VS Code extension. You can sign in to Cline directly, use your ChatGPT Subscription through openai-codex, or bring an API key from Anthropic, OpenAI, Google Gemini, OpenRouter, AWS Bedrock, GCP Vertex, Cerebras, Groq, and any OpenAI-compatible endpoint.

cline auth                              # interactive sign-in
cline auth cline                        # OAuth sign-in
cline auth --provider anthropic --apikey sk-... --modelid claude-sonnet-4-6

cline auth without a provider opens the interactive auth setup TUI with the same options as the old CLI flow (Sign in with Cline, Sign in with ChatGPT Subscription, Sign in with OCA, or use your own API key).

OAuth-supported providers (cline, openai-codex, oca) do not auto-launch a browser on normal startup. Authenticate explicitly first with cline auth <provider>. For non-interactive runs, if an OAuth provider is selected and no saved credentials are available, cline fails fast with an authentication message instead of launching a hidden browser flow.

Modes

Cline CLI runs in a few different shapes depending on what you need:

  • Interactive TUI: cline or cline -i opens a full terminal UI with plan/act toggle, slash commands, file mentions, and live tool approvals
  • One-shot: cline "your prompt" runs a single turn and exits
  • JSON: cline --json "..." streams NDJSON events for piping into other tools
  • Yolo: cline --yolo "..." skips approval prompts and exits when the turn finishes
  • Zen: cline --zen "..." fires the task to the background hub daemon and exits immediately (see below)

Headless mode for CI/CD

Run Cline with zero interaction for scripting and automation. Pipe input, get JSON output, chain commands, integrate into CI/CD pipelines.

# One-shot prompt, auto-approve all tools
cline --yolo "Run tests and fix any failures"

# Pipe a diff in for review
git diff origin/main | cline "Review these changes for issues"

# NDJSON output for downstream tooling
cline --json "List all TODO comments" | jq -r 'select(.type == "agent_event" and .event.text) | .event.text'

Features

  • Streaming TUI built on OpenTUI with markdown rendering, syntax-highlighted diffs, scrollable chat, and mouse support
  • Plan/Act mode toggle for switching between planning and execution
  • Native MCP support for connecting custom tools
  • Checkpoints with /undo to rewind workspace state
  • Sub-agent spawning and agent teams for parallel work
  • OAuth login for Cline, ChatGPT Subscription (openai-codex), and OCA
  • Configurable thinking budgets per run
  • Cron and event-driven schedules for recurring agent work
  • Chat connectors for Telegram, Google Chat, and WhatsApp

Usage

# Start Cline CLI without a prompt to enter interactive mode
cline

# Single prompt (one-shot) - includes tools, spawn, and teams
cline "Audit this package and propose fixes"

# Interactive mode with a starting prompt
cline -i "Let's work on this together. First, analyze the current state."

# With a custom system prompt
cline -i -s "You are a pirate" "Tell me about the sea"

# Require approval before each tool call
cline --auto-approve false "Inspect and modify this repository"

# Explicit yolo: enables submit_and_exit and disables spawn/team tools by default
cline --yolo --retries 5 "Refactor this package"

# Override consecutive internal mistake (retry) limit (default: 3)
cline --retries 5 "Fix failing tests"

# Team workflow with persistent name
cline --team-name my-team "Plan, implement, and verify release checklist"
cline --team-name my-team "Continue yesterday's team workflow"

# Show verbose run stats (elapsed time, tokens, estimated cost when available)
cline -v "Explain quantum computing"

# Use a specific provider, model, and access token for a single prompt
cline -P openrouter -m google/gemini-3-pro -k sk-... "Set up a storybook"

# Use a different model with the last used provider
cline -m anthropic/claude-opus-4-6 "Explain string theory"

# Stream structured NDJSON output
cline --json "Summarize this repository"

# Quick provider setup
cline auth --provider anthropic --apikey sk-... --modelid claude-sonnet-4-6
cline auth --provider openai-native --apikey sk-... --modelid gpt-5 --baseurl https://api.example.com/v1

MCP servers

Manage MCP servers with the interactive wizard:

cline mcp
cline config mcp

Open the add-server wizard with the name, transport, and command or URL already filled in with cline mcp install (cline mcp add also works). Stdio servers use everything after -- as the command and arguments:

cline mcp install fs -- npx -y @modelcontextprotocol/server-filesystem /tmp

Remote HTTP and SSE servers take a name, transport, and URL. The wizard still asks for auth details before saving:

cline mcp install ctx7 --transport http https://mcp.context7.com/mcp
cline mcp install events --transport sse https://example.com/sse

Because this command opens the wizard, it requires a TTY.

Connectors

Bridge a chat surface into RPC-backed Cline sessions. Each conversation thread maps to a session with full context. Supported platforms: Telegram, Slack, Google Chat, WhatsApp, and Linear.

# Telegram (polling mode)
cline connect telegram -k 123456:ABCDEF...

# Slack (webhook mode)
cline connect slack --bot-token $SLACK_BOT_TOKEN --signing-secret $SLACK_SIGNING_SECRET --base-url https://your-domain.com

# Slack (socket mode)
cline connect slack --bot-token $SLACK_BOT_TOKEN --app-token $SLACK_APP_TOKEN

# Google Chat (webhook mode)
cline connect gchat --base-url https://your-domain.com

# WhatsApp (webhook mode)
cline connect whatsapp --base-url https://your-domain.com

# Linear (webhook mode)
cline connect linear --api-key $LINEAR_API_KEY --base-url https://your-domain.com

# Stop connector bridges and delete their sessions
cline connect --stop
cline connect --stop telegram

In chat surfaces, connector slash commands include /help, /start, /new, /clear, /whereami, /tools, /yolo, /cwd <path>, /schedule, /abort, and /exit. Run cline connect <adapter> --help to see the full flag list for any adapter.

Schedules

Schedule agents on cron-like intervals or external events.

If --provider and --model are omitted, schedules use the last configured provider and model. If only --provider is given, the schedule uses that provider's saved model.

cline schedule create "Daily code review" \
  --cron "0 9 * * MON-FRI" \
  --prompt "Review PRs opened yesterday and summarize issues." \
  --workspace /path/to/repo \
  --timeout 3600 \
  --tags automation,review

cline schedule list
cline schedule get <schedule-id>
cline schedule trigger <schedule-id>
cline schedule history <schedule-id> --limit 20
cline schedule export <schedule-id> > daily-review.yaml
cline schedule import ./daily-review.yaml

Schedules can route results back to chat surfaces with --delivery-adapter, --delivery-bot, and --delivery-thread.

Options

Flag Description
-s, --system <prompt> Override the system prompt
-P, --provider <id> Provider id (default: cline)
-m, --model <id> Model id (default: anthropic/claude-sonnet-4.6)
-k, --key <api-key> API key override for this run
-p, --plan Run in plan mode (default is act mode)
-i, --tui Interactive TUI multi-turn mode
-t, --timeout <seconds> Optional run timeout in seconds
-c, --cwd <path> Working directory for tools
--config <path> Configuration directory (used for CLI home resolution)
--hooks-dir <path> Additional hooks directory hint for runtime hook injection
--acp ACP (Agent Client Protocol) mode
--thinking [none|low|medium|high|xhigh] Model thinking level when supported. Defaults to medium when the flag is provided without a level; thinking is off when the flag is omitted.
--compaction <agentic|basic|off> Context compaction mode. Defaults to agentic; use basic for local truncation or off to disable.
--retries <count> Maximum consecutive mistakes (retries) before halting (default: 3)
--json Output NDJSON instead of styled text
--data-dir <path> Use isolated local state at <path> instead of ~/.cline/data (enables sandbox mode automatically)
--auto-approve [true|false] Set tool auto-approval for all tools
--kanban Run the external kanban app
-y, --yolo Skip tool approval prompts, enable submit_and_exit, and disable spawn/team tools by default
-z, --zen Dispatch the task to the background hub and exit the CLI immediately
--team-name <name> Override the runtime team state name
-h, --help Show help and exit
-v, --verbose Show verbose runtime diagnostics
-V, --version Show version and exit

--json is non-interactive and requires either a prompt argument or piped stdin. --key takes precedence over environment variables.

Top-level commands

  • cline config - Open the interactive config view
  • cline history|h [options] - List session history or manage saved sessions
  • cline version - Show CLI version
  • cline update [options] - Check for CLI and kanban updates
  • cline auth <provider> - Authenticate or seed provider credentials
  • cline connect <adapter> - Run a chat connector bridge (telegram, gchat, whatsapp)
  • cline connect --stop [adapter] - Stop connector bridge processes and their sessions
  • cline schedule <command> - Create and manage scheduled runs
  • cline doctor - Inspect local CLI health and stale processes
  • cline doctor fix - Kill stale local RPC listeners and old CLI processes
  • cline doctor log - Open the CLI runtime log file
  • cline hook - Handle a hook payload from stdin
  • cline hub - Manage the local hub daemon
  • cline kanban - Run the external kanban app, installing it first when needed

Zen mode

--zen (alias -z) runs a task in the background hub daemon and exits the CLI immediately. It is intended for long-running tasks you want to fire off and walk away from.

cline --zen "Refactor the authentication module and add unit tests"

Behavior:

  • The CLI starts (or reuses) the local hub daemon, submits the task, then exits. It does not stream output or stay attached to the session.
  • Because there is no human in the loop once the CLI exits, zen sessions run with full tool auto-approval (same semantics as --yolo). spawn/team tools are disabled by default for safety, consistent with yolo-mode defaults.
  • If the Cline menubar app is running, it subscribes to hub ui.notify events and will surface a system notification when the task completes.
  • If the menubar app is not running, there is no live UI for the task. Use cline history later to find the session and inspect the result.
  • --zen is incompatible with --data-dir (the implicit sandbox requires a local backend that exits with the CLI) and with --tui (there is no terminal UI to render into).

Tool approval

Tool calls are auto-approved by default. Use --auto-approve false to require review before tool execution.

cline --auto-approve false "Inspect and modify this repository"

When approval is required, the CLI prompts in TTY mode:

Approve tool "<tool_name>" with input <preview>? [y/N]
  • Enter y or yes to approve.
  • Enter anything else (or press Enter) to reject.
  • If stdin/stdout is not a TTY, required-approval calls are denied in terminal mode.

Desktop-integrated approval mode is also supported via env wiring (CLINE_TOOL_APPROVAL_MODE=desktop and CLINE_TOOL_APPROVAL_DIR=<path>). In desktop mode, CLI writes a request JSON file and waits for a matching decision JSON file.

Environment variables

  • ANTHROPIC_API_KEY - API key for Anthropic
  • CLINE_API_KEY - API key for Cline (when using -P cline)
  • OPENAI_API_KEY - API key for OpenAI (when using -P openai)
  • OPENROUTER_API_KEY - API key for OpenRouter (when using -P openrouter)
  • AI_GATEWAY_API_KEY - API key for Vercel AI Gateway (when using -P vercel-ai-gateway)
  • V0_API_KEY - API key for v0 (when using -P v0)
  • CLINE_DATA_DIR - Base data directory for sessions/settings/teams/hooks
  • CLINE_SANDBOX - Set to 1 to force sandbox mode
  • CLINE_SANDBOX_DATA_DIR - Override sandbox state directory
  • CLINE_TEAM_DATA_DIR - Override team persistence directory
  • CLINE_BUILD_ENV - Runtime build mode for SDK-owned subprocess launches
  • CLINE_DEBUG_HOST - Host for development inspector listeners (default 127.0.0.1)
  • CLINE_DEBUG_PORT_BASE - Base inspector port for development child processes
  • CLINE_TOOL_APPROVAL_MODE - Approval mode (desktop uses file IPC; unset uses terminal prompt)
  • CLINE_TOOL_APPROVAL_DIR - Directory for desktop approval request/decision files
  • CLINE_LOG_ENABLED - Set to 0/false to disable runtime file logging
  • CLINE_LOG_LEVEL - Runtime log level (trace|debug|info|warn|error|fatal|silent, default info)
  • CLINE_LOG_PATH - Runtime log file path (default <CLINE_DATA_DIR>/logs/cline.log)
  • CLINE_LOG_NAME - Logger name embedded in runtime log records
  • CLINE_DEBUG - Set to 1/true to print wrapper diagnostics (e.g. the CA bundle summary)

--key takes precedence over environment variables.

Certificate trust

The CLI automatically trusts your operating system's certificate store, so it works behind corporate TLS-inspecting proxies and with self-signed/internal endpoints without any setup. On launch the cline wrapper harvests the OS trust anchors and writes them to ~/.cline/cli-node-extra-ca-certs.pem, then points the runtime's NODE_EXTRA_CA_CERTS at that bundle. The file is regenerated when it changes and is safe to delete (it is rebuilt on the next run).

If you set NODE_EXTRA_CA_CERTS yourself, your certificates are merged into that bundle alongside the system store rather than replacing it. Run with CLINE_DEBUG=1 to see how many OS and user CAs were loaded and where the bundle was written.

Contributing

See DEVELOPMENT.md for local development setup, monorepo structure, and TUI architecture. See DISTRIBUTION.md for how the CLI is packaged and distributed.

License

Apache 2.0 © Cline Bot Inc.