getting-started.mdx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. ---
  2. title: "Getting Started"
  3. description: "Run Cline AI coding agents directly in your terminal with an interactive CLI or automated workflows"
  4. ---
  5. ## What is Cline CLI?
  6. Cline CLI brings the full power of Cline to your terminal. Whether you prefer an interactive experience or automated workflows for CI/CD pipelines, the CLI adapts to your needs.
  7. The CLI supports macOS, Linux, and Windows, and works with all the same AI providers as the VS Code extension.
  8. ## Two Ways to Use Cline CLI
  9. The CLI operates in two distinct modes, automatically selecting the appropriate one based on how you invoke it:
  10. ### Interactive Mode
  11. Interactive mode is designed for **hands-on development sessions** where you want to collaborate with Cline in real-time. It provides a rich terminal interface that feels like chatting with an AI assistant.
  12. **When it activates:** Running `cline` without arguments, or when stdin is a TTY (terminal).
  13. ```bash
  14. cline
  15. ```
  16. Key features:
  17. - **Real-time conversation** - Type messages, see Cline's responses, and iterate on tasks
  18. - **Visual feedback** - Animated welcome screen, syntax-highlighted code, and progress indicators
  19. - **File mentions** with `@` - Reference workspace files with fuzzy search autocomplete
  20. - **Slash commands** with `/` - Quick access to `/settings`, `/history`, `/models`, and workflows
  21. - **Keyboard shortcuts** - `Tab` to toggle Plan/Act, `Shift+Tab` for auto-approve all
  22. - **Session summaries** - See tasks completed, files modified, and token usage on exit
  23. - **Settings panel** - Configure providers, models, and features without leaving the CLI
  24. Interactive mode keeps you in control. You review Cline's plan, approve or modify actions, and guide the conversation.
  25. [Learn more about interactive mode →](/cline-cli/interactive-mode)
  26. ### Headless Mode (Non-Interactive)
  27. Headless mode is designed for **automation, scripting, and CI/CD pipelines** where human interaction isn't possible or desired.
  28. **When it activates:** Using the `-y`/`--yolo` flag, `--json` flag, piping input/output, or when stdin is not a TTY.
  29. ```bash
  30. # Headless with auto-approval (YOLO mode)
  31. cline -y "Run tests and fix any failures"
  32. # Headless with JSON output for parsing
  33. cline --json "List all TODO comments" | jq '.text'
  34. # Headless via piped input
  35. cat README.md | cline "Summarize this document"
  36. # Chain multiple headless commands
  37. git diff | cline -y "explain these changes" | cline -y "write a commit message"
  38. ```
  39. Key features:
  40. - **No visual interface** - Clean text or JSON output suitable for scripting
  41. - **Automatic execution** - With `-y`, Cline approves all actions and runs autonomously
  42. - **Process control** - Exits automatically when the task completes
  43. - **Piped workflows** - Read from stdin, write to stdout, chain with other commands
  44. - **Machine-readable output** - Use `--json` to get structured output for parsing
  45. <Warning>
  46. Headless mode with `-y` gives Cline full autonomy. Run on a clean git branch so you can easily revert changes if needed.
  47. </Warning>
  48. ### Mode Detection Summary
  49. Cline automatically detects which mode to use based on your invocation. This table shows how different command patterns trigger each mode, helping you predict behavior in scripts and interactive sessions.
  50. | Invocation | Mode | Reason |
  51. |------------|------|--------|
  52. | `cline` | Interactive | No arguments, TTY connected |
  53. | `cline "task"` | Interactive | TTY connected |
  54. | `cline -y "task"` | Headless | YOLO flag forces headless |
  55. | `cline --json "task"` | Headless | JSON flag forces headless |
  56. | `cat file \| cline "task"` | Headless | stdin is piped |
  57. | `cline "task" > output.txt` | Headless | stdout is redirected |
  58. [Learn more about headless mode →](/cline-cli/three-core-flows)
  59. ## Supported Model Providers
  60. Cline CLI supports all providers available in the VS Code extension:
  61. - **Anthropic** (Claude)
  62. - **OpenAI** (GPT-4o, GPT-4)
  63. - **OpenAI Codex** (ChatGPT subscription)
  64. - **OpenRouter**
  65. - **AWS Bedrock**
  66. - **Google Gemini**
  67. - **X AI (Grok)**
  68. - **Cerebras**
  69. - **DeepSeek**
  70. - **Ollama** (local models)
  71. - **LM Studio** (local models)
  72. - **OpenAI Compatible** (any compatible API)
  73. During setup, authenticate with `cline auth` to configure your preferred provider. [See authentication →](#authenticate)
  74. ## What You Can Build
  75. ### Automated Code Maintenance
  76. Keep your codebase healthy with automated fixes. Cline scans for issues and applies corrections across multiple files.
  77. ```bash
  78. cline -y "Fix all ESLint errors in src/"
  79. ```
  80. Finds and fixes linting violations throughout your source directory.
  81. ```bash
  82. cline -y "Update all deprecated React lifecycle methods"
  83. ```
  84. Migrates legacy code patterns to modern equivalents (e.g., `componentWillMount` → `useEffect`).
  85. ```bash
  86. cline -y "Update dependencies with known vulnerabilities"
  87. ```
  88. Identifies outdated packages with security issues and updates them to safe versions.
  89. ### CI/CD Integration
  90. Integrate Cline into your continuous integration pipelines for automated code review and documentation.
  91. ```bash
  92. git diff origin/main | cline -y "Review these changes for issues"
  93. ```
  94. Pipes your PR diff to Cline for automated code review, catching bugs and style issues before merge.
  95. ```bash
  96. git log --oneline v1.0..v1.1 | cline -y "Write release notes"
  97. ```
  98. Generates human-readable release notes from your commit history between two tags.
  99. ```bash
  100. cline -y "Run tests and fix failures" --timeout 600
  101. ```
  102. Executes your test suite, analyzes failures, and attempts fixes with a 10-minute timeout.
  103. ### Development Workflows
  104. From quick edits to complex refactors, Cline adapts to your workflow.
  105. ```bash
  106. cline
  107. ```
  108. Launches interactive mode for exploratory development and back-and-forth collaboration.
  109. ```bash
  110. cline "Refactor this function to use async/await"
  111. ```
  112. Executes a focused task directly from the command line with approval prompts at key steps.
  113. ```bash
  114. cline "Based on @src/api.ts, add error handling to all endpoints"
  115. ```
  116. Uses file mentions (`@`) to give Cline context about specific files in your workspace.
  117. ### Custom Shell Pipelines
  118. Chain Cline with other CLI tools to build powerful automation workflows.
  119. ```bash
  120. gh pr diff 123 | cline -y "Review this PR"
  121. ```
  122. Fetches a GitHub PR diff and pipes it directly to Cline for review.
  123. ```bash
  124. cline --json "List all TODO comments" | jq '.text'
  125. ```
  126. Outputs structured JSON that you can process with tools like `jq` for scripting.
  127. ```bash
  128. git diff | cline -y "explain" | cline -y "write a haiku about these changes"
  129. ```
  130. Chains multiple Cline invocations together for creative multi-step workflows.
  131. ## Features at a Glance
  132. | Feature | Interactive Mode | Non-Interactive Mode |
  133. |---------|------------------|----------------------|
  134. | Interactive chat | ✓ | - |
  135. | File mentions (@) | ✓ | ✓ (inline) |
  136. | Slash commands (/) | ✓ | - |
  137. | Settings panel | ✓ | `cline config` |
  138. | Plan/Act toggle | ✓ (Tab) | `-p` / `-a` flags |
  139. | Auto-approve | ✓ (Shift+Tab) | `-y` flag |
  140. | Session summary | ✓ | - |
  141. | JSON output | - | `--json` |
  142. | Piped input | - | ✓ |
  143. ---
  144. ## Installation & Setup
  145. In just a few minutes, you can install the CLI, authenticate with your preferred AI provider, and start running tasks from any directory on your machine.
  146. ### Prerequisites
  147. Cline CLI requires **Node.js version 20 or higher**. We recommend Node.js 22 for the best experience.
  148. Check your Node.js version:
  149. ```bash
  150. node --version
  151. ```
  152. If you need to install or update Node.js, visit [nodejs.org](https://nodejs.org) or use a version manager like [nvm](https://github.com/nvm-sh/nvm).
  153. ### Install Cline CLI
  154. Install globally via npm:
  155. ```bash
  156. npm install -g cline
  157. ```
  158. Verify the installation:
  159. ```bash
  160. cline version
  161. ```
  162. <Tip>
  163. To install a specific version, use `npm install -g [email protected]`. Check [npm](https://www.npmjs.com/package/cline) for available versions.
  164. </Tip>
  165. ### Authenticate
  166. After installation, run the authentication wizard:
  167. ```bash
  168. cline auth
  169. ```
  170. This launches an interactive wizard with multiple options. Choose the method that works best for your workflow.
  171. #### Option 1: Sign in with Cline (Recommended)
  172. Select **"Sign in with Cline"** to authenticate with your Cline account via OAuth. Your browser opens automatically to complete sign-in.
  173. #### Option 2: Sign in with ChatGPT Subscription
  174. If you have a ChatGPT Plus or Pro subscription, select **"Sign in with ChatGPT Subscription"**. This uses OpenAI's Codex OAuth to authenticate with your existing subscription.
  175. #### Option 3: Import from Existing Tools
  176. Already using another AI coding CLI? Cline can import your existing configuration:
  177. - **Import from Codex CLI** - Imports credentials from `~/.codex/auth.json`
  178. - **Import from OpenCode** - Imports configuration from `~/.local/share/opencode/auth.json`
  179. #### Option 4: Bring Your Own API Key
  180. Select **"Bring your own API key"** to manually configure any supported provider. Or skip the wizard entirely with flags:
  181. ```bash
  182. # Anthropic (Claude)
  183. cline auth -p anthropic -k sk-ant-api-xxxxx -m claude-sonnet-4-5-20250929
  184. # OpenAI
  185. cline auth -p openai-native -k sk-xxxxx -m gpt-4o
  186. # OpenRouter
  187. cline auth -p openrouter -k sk-or-xxxxx -m anthropic/claude-sonnet-4-5-20250929
  188. # OpenAI-compatible provider with custom base URL
  189. cline auth -p openai -k your-api-key -b https://api.example.com/v1
  190. ```
  191. **Quick Setup Flags:**
  192. | Flag | Description |
  193. |------|-------------|
  194. | `-p, --provider <id>` | Provider ID (e.g., `anthropic`, `openai-native`, `openrouter`) |
  195. | `-k, --apikey <key>` | Your API key |
  196. | `-m, --modelid <id>` | Model ID (e.g., `claude-sonnet-4-5-20250929`, `gpt-4o`) |
  197. | `-b, --baseurl <url>` | Base URL for OpenAI-compatible providers |
  198. <Tip>
  199. Flags are especially useful for scripting, CI/CD environments, or setting up multiple machines.
  200. </Tip>
  201. #### Supported Providers
  202. | Provider | Provider ID | Notes |
  203. |----------|-------------|-------|
  204. | Anthropic | `anthropic` | Direct Claude API access |
  205. | OpenAI | `openai-native` | GPT-4o, GPT-4, etc. |
  206. | OpenAI Codex | `openai-codex` | ChatGPT subscription OAuth |
  207. | OpenRouter | `openrouter` | Access multiple providers |
  208. | AWS Bedrock | `bedrock` | Claude via AWS |
  209. | Google Gemini | `gemini` | Gemini Pro, etc. |
  210. | X AI (Grok) | `xai` | Grok models |
  211. | Cerebras | `cerebras` | Fast inference |
  212. | DeepSeek | `deepseek` | DeepSeek models |
  213. | Ollama | `ollama` | Local models |
  214. | LM Studio | `lmstudio` | Local models |
  215. | OpenAI Compatible | `openai` | Any OpenAI-compatible API |
  216. ### Verify Your Setup
  217. Confirm everything is working with a simple test:
  218. ```bash
  219. cline "What is 2 + 2?"
  220. ```
  221. If Cline responds with an answer, your installation and authentication are complete.
  222. Check your current configuration:
  223. ```bash
  224. cline config
  225. ```
  226. ### Quick Start
  227. Now you're ready to use Cline. Choose how you want to work:
  228. #### Interactive Mode
  229. Launch the interactive CLI for development:
  230. ```bash
  231. cline
  232. ```
  233. You'll see the Cline welcome screen. Type your task and press Enter. Use:
  234. - `Tab` to toggle between Plan and Act modes
  235. - `Shift+Tab` to enable auto-approve
  236. - `/help` for available commands
  237. [Learn more about interactive mode →](/cline-cli/interactive-mode)
  238. #### Direct Task Execution
  239. Run a task directly from your shell:
  240. ```bash
  241. cline "Add error handling to utils.js"
  242. ```
  243. For non-interactive execution (perfect for scripts and CI/CD):
  244. ```bash
  245. cline -y "Run tests and fix any failures"
  246. ```
  247. [Learn more about headless mode →](/cline-cli/three-core-flows)
  248. ### Switching Providers
  249. To change your configured provider at any time:
  250. ```bash
  251. cline auth
  252. ```
  253. You can also use the settings panel in interactive mode:
  254. ```bash
  255. cline
  256. # Then type: /settings
  257. # Navigate to the API tab
  258. ```
  259. ### Updating
  260. Check for updates and install the latest version:
  261. ```bash
  262. cline update
  263. ```
  264. Or update manually via npm:
  265. ```bash
  266. npm update -g cline
  267. ```
  268. ### Troubleshooting
  269. #### Command Not Found
  270. If `cline` is not found after installation:
  271. 1. Ensure npm global bin is in your PATH:
  272. ```bash
  273. npm bin -g
  274. ```
  275. 2. Add the path to your shell configuration (`.bashrc`, `.zshrc`, etc.):
  276. ```bash
  277. export PATH="$PATH:$(npm bin -g)"
  278. ```
  279. 3. Restart your terminal or source your shell config.
  280. #### Permission Errors
  281. If you get permission errors during installation:
  282. ```bash
  283. # Option 1: Use a Node version manager (recommended)
  284. # nvm, fnm, or volta handle permissions automatically
  285. # Option 2: Fix npm permissions
  286. # See: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
  287. ```
  288. #### OAuth Flow Issues
  289. If the browser doesn't open automatically during OAuth:
  290. 1. Copy the URL from the terminal
  291. 2. Paste it in your browser manually
  292. 3. Complete the sign-in flow
  293. 4. Return to the terminal
  294. #### API Key Validation
  295. If your API key is rejected:
  296. 1. Verify the key is correct and hasn't expired
  297. 2. Check that you've selected the correct provider
  298. 3. Ensure your API account has the necessary permissions
  299. **Provider-specific tips:**
  300. - **Anthropic**: Keys start with `sk-ant-`
  301. - **OpenAI**: Keys start with `sk-`
  302. - **AWS Bedrock**: Requires AWS credentials configured separately. See [AWS Bedrock documentation](/provider-config/aws-bedrock/api-key).
  303. ### Uninstallation
  304. To remove Cline CLI:
  305. ```bash
  306. npm uninstall -g cline
  307. ```
  308. To also remove configuration data:
  309. ```bash
  310. rm -rf ~/.cline
  311. ```
  312. ## Next Steps
  313. - **[Interactive Mode](/cline-cli/interactive-mode)** - Master the interactive CLI with shortcuts and slash commands
  314. - **[Headless Mode](/cline-cli/three-core-flows)** - Run Cline autonomously in scripts, CI/CD pipelines, and automated workflows
  315. - **[Configuration](/cline-cli/configuration)** - Configure settings, rules, workflows, and environment variables
  316. - **[CLI Reference](/cline-cli/cli-reference)** - Complete command documentation with all flags and options