# CLI Overview

> Use Cline CLI for interactive terminal sessions and automated headless workflows.

- 网址：https://funcoding.ai/agents/cline/usage/cli-overview/
- 来源：Cline 官方文档原文（英文），Apache-2.0 许可，同步于 2026-10-11
- 官方原文：https://docs.cline.bot/usage/cli-overview

---
## Prerequisites

- Cline CLI installed (install via `npm i -g cline`)
- Provider authenticated (`cline auth`) — use the Cline Provider, ClinePass, or your own provider key ([Authorization Guide](https://funcoding.ai/agents/cline/getting-started/authorizing-with-cline/#cli-setup))

## Quick Start

```bash
# Interactive session
cline

# Run one task immediately
cline "refactor this module to use async/await"

# Structured output for scripts
cline --json "list TODO comments"
```

## Headless mode

Use headless mode for scripts/automation and processable output.

Headless is triggered when using flags like `--json`, when stdin is piped, or when output is redirected.

#### When headless activates

| Invocation | Reason |
|---|---|
| `cline --json "task"` | JSON output mode |
| `cat file \| cline "task"` | stdin is piped |
| `cline "task" > output.txt` | stdout is redirected |

```bash
# CI/script style execution
git diff | cline "review these changes"

# JSON for parsing: print only the final answer
cline --json "summarize this changelog" | jq -r 'select(.type == "run_result") | .text'
```

See: [Headless Mode](#headless-mode)

### Autonomous execution

For fully unattended runs, use auto-approval:

```bash
cline --auto-approve true "run tests and fix failures"
```

Mode selection also works in headless runs:

```bash
# plan-first
cline -p "design migration plan"

# act immediately (default)
cline "apply migration"
```

<div class="callout callout-warning">

Autonomous execution can modify files and run commands without further prompts. Use a clean branch and review results.

</div>

## High-Value Commands

```bash
cline --help
cline <command> --help
```

| Command | Purpose |
|---|---|
| `cline` | Start interactive mode or run a prompt |
| `cline auth` | Authenticate and set provider/model |
| `cline config` | Show the current configuration |
| `cline mcp` | Manage MCP servers |
| `cline doctor` | Diagnose/fix configuration issues |
| `cline history` | Show and manage task history |
| `cline schedule` | Manage scheduled tasks |
| `cline hub` | Manage local hub daemon |
| `cline kanban` | Run the Kanban app |

## Most-Used Global Flags

Source of truth: [CLI Reference](https://funcoding.ai/agents/cline/cli/cli-reference/)

| Flag | Purpose |
|---|---|
| `-p, --plan` | Start in Plan mode |
| `--auto-approve <boolean>` | Global tool auto-approval (`true`/`false`, default `true`) |
| `-m, --model <model>` | Override model for this run |
| `-P, --provider <id>` | Override provider for this run |
| `-c, --cwd <path>` | Set working directory |
| `--config <dir>` | Use config directory |
| `--data-dir <dir>` | Use isolated local state |
| `--json` | Output newline-delimited JSON messages |
| `--thinking <level>` | Set reasoning effort: `none\|low\|medium\|high\|xhigh`. Bare `--thinking` uses `medium`. Without the flag, Cline uses the level you last chose with `/model`, or else the provider's default |
| `-t, --timeout <seconds>` | Set task timeout |

## Automation Patterns

### Pipe context in

```bash
cat README.md | cline "summarize key setup steps"
git diff | cline "review for potential regressions"
```

### Chain tasks

```bash
git diff | cline "explain these changes" | cline "write a commit message"
```

### Restrict command execution

The CLI has no allow or deny list for shell commands. To block commands, use a `PreToolUse` hook that cancels `run_commands` calls you don't allow, like the [.clineignore hook](https://funcoding.ai/agents/cline/customization/clineignore/#enforcing-clineignore-with-a-hook).

### Include images in tasks

Mention an image file with `@` and the CLI attaches it to the prompt:

```bash
cline "fix the UI shown in @./design-mockup.png"
```

### Set execution timeout

```bash
cline --timeout 600 "run full test suite"
```

## JSON Output Schema

When you give Cline a task with `--json`, each line is a JSON object with a `type`. Agent events arrive as `agent_event` lines, and a `run_result` line holds the final `text` when the run finishes. The [CLI Reference](https://funcoding.ai/agents/cline/cli/cli-reference/#json-output-for-agent-runs) describes the line types.

## Next Steps

- [CLI Reference](https://funcoding.ai/agents/cline/cli/cli-reference/)
- [ACP](https://funcoding.ai/agents/cline/usage/acp/) — use Cline as the coding agent in Zed, JetBrains IDEs, Neovim, and other ACP clients
