The CLI is a standalone terminal interface for the Cline AI coding assistant, written in Go. It provides the same autonomous coding capabilities as the VS Code extension but runs entirely in the terminal.
┌─────────────────────────────────────────────────────────────────────────┐
│ User Terminal │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ cline (Go binary) │
│ cmd/cline/main.go │
│ • Cobra CLI commands (task, auth, config, instance, etc.) │
│ • Interactive input via Bubble Tea │
│ • Streaming output with markdown rendering │
└─────────────────────────────────────────────────────────────────────────┘
│ gRPC (50052) │ starts subprocess
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ cline-core │◄────────────────►│ cline-host │
│ (Node.js) │ gRPC (51052) │ (Go binary) │
│ │ │ cmd/cline-host/main.go│
│ • AI/LLM orchestration │ │ │
│ • Tool execution │ │ • Workspace paths │
│ • Task state mgmt │ │ • File diff editing │
│ • Message handling │ │ • Clipboard access │
└─────────────────────────┘ │ • Environment info │
│ └─────────────────────────┘
│ SQLite (self-registration)
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ ~/.cline/data/locks/locks.db │
│ (Instance registry - core self-registers on startup) │
└─────────────────────────────────────────────────────────────────────────┘
cmd/)cmd/cline/main.go - Main CLICobra-based CLI with commands:
cline [prompt] - Start a task directlycmd/cline-host/main.go - Host Bridge ServiceSeparate gRPC server providing host environment operations to cline-core:
pkg/cli/ Subsystemsauth/ - Authentication SystemHandles authentication with Cline service and BYO (Bring Your Own) API providers.
| File | Purpose |
|---|---|
auth_cline_provider.go |
OAuth login flow - opens browser, subscribes to auth callback stream |
auth_menu.go |
Interactive menu showing auth options based on current state |
auth_subscription.go |
gRPC stream subscription for auth status updates |
wizard_byo.go |
Interactive wizard for configuring BYO providers |
wizard_byo_bedrock.go |
AWS Bedrock-specific credential setup |
wizard_byo_oca.go |
Oracle Code Assist setup |
providers_list.go |
Retrieves configured providers from core state |
providers_byo.go |
Provider selection UI and field configuration |
models_*.go |
Model listing (static lists + dynamic fetch from OpenRouter/OpenAI/Ollama) |
Flow: User runs cline auth → Menu shows options → For BYO: wizard guides through provider/key/model selection → Config saved via gRPC to core.
clerror/ - Error HandlingParses and classifies API errors from the Cline service.
Error Types:
ErrorTypeAuth - 401, bad API keyErrorTypeBalance - Insufficient creditsErrorTypeRateLimit - 429, quota exceededErrorTypeNetwork - Connection issuesErrorTypeUnknown - Catch-allExtracts billing details (balance, spent, buy credits URL) from error responses.
config/ - Configuration Management| File | Purpose |
|---|---|
manager.go |
gRPC interface for reading/writing settings via UpdateSettingsCli RPC |
settings_renderer.go |
Pretty-prints config values, censors sensitive fields (keys, secrets) |
Supports dot-notation paths: cline config get auto-approval-settings.actions.read-files
display/ - Terminal Display SystemThe most complex subsystem - handles all visual output.
| File | Purpose |
|---|---|
renderer.go |
Central coordinator with lipgloss styles, color methods, markdown delegation |
streaming.go |
Real-time streaming display with deduplication |
segment_streamer.go |
Streaming segments (header + body) with context-aware headers |
typewriter.go |
Character-by-character animation with variable delays |
markdown_renderer.go |
Glamour wrapper for terminal markdown rendering |
tool_renderer.go |
Tool operation formatting ("Cline is editing file.ts") |
tool_result_parser.go |
Parses structured tool results (file lists, search results) |
banner.go |
Session startup banner with version/model/workspace |
deduplicator.go |
MD5-based deduplication with 2-second window |
system_renderer.go |
Rich error/warning boxes for balance errors, auth failures |
ansi.go |
TTY detection, line clearing with escape codes |
global/ - Global State Management| File | Purpose |
|---|---|
global.go |
Global config (paths, verbosity, output format), initialization |
registry.go |
Instance discovery via SQLite, health checking, default instance management |
cline-clients.go |
Starts cline-core + cline-host processes, port allocation, cleanup |
Instance lifecycle:
cline-host on port+1000cline-core on porthandlers/ - Message HandlersRoutes incoming messages from cline-core to appropriate renderers.
| File | Purpose |
|---|---|
handler.go |
Handler registry with priority-based routing |
ask_handlers.go |
Approval requests: tool, command, followup, api_req_failed, etc. |
say_handlers.go |
Status messages: text, reasoning, command_output, tool, checkpoint, etc. |
Uses DisplayContext providing renderer access, state, and context flags (isLast, isPartial, isStreamingMode).
output/ - Output Coordination| File | Purpose |
|---|---|
coordinator.go |
Coordinates streaming output with interactive input (saves/restores input state) |
input_model.go |
Bubble Tea model for rich input (message, approval, feedback types) |
slash_completion.go |
Autocomplete dropdown for slash commands |
Key pattern: When output needs to print while input is visible, the coordinator saves input state, clears the form, prints, then restores input.
slash/ - Slash Command RegistryCentral registry for commands like /plan, /act, /cancel:
CliCompatible flagsqlite/ - Instance LockingManages the distributed locking system:
task/ - Task Management| File | Purpose |
|---|---|
manager.go |
Core orchestrator: create, cancel, resume, restore tasks; stream handling |
stream_coordinator.go |
Deduplication and turn management for dual streams |
input_handler.go |
Interactive input during follow mode (polling, approval detection) |
history_handler.go |
Direct disk access to taskHistory.json |
settings_parser.go |
Parse settings from CLI flags |
follow_options.go |
Configuration for follow behavior |
Streaming: Task manager subscribes to two gRPC streams:
SubscribeToState - Full state updatesSubscribeToPartialMessage - Streaming AI responsesterminal/ - Terminal HandlingEnhanced keyboard protocol support and terminal configuration:
types/ - Type Definitions| File | Purpose |
|---|---|
messages.go |
ClineMessage, AskType, SayType, ToolType enums, proto conversion |
state.go |
ConversationState with thread-safe message access |
history.go |
HistoryItem matching taskHistory.json format |
updater/ - Auto-UpdateBackground auto-update checking:
latest and nightly channelsnpm install -g cline to updatepkg/common/ - Shared Types| File | Purpose |
|---|---|
constants.go |
SETTINGS_SUBFOLDER, DEFAULT_CLINE_CORE_PORT |
schema.go |
SQL queries for instance/file locks |
types.go |
CoreInstanceInfo, LockRow, DefaultCoreInstance |
utils.go |
Port checking, health checks, address normalization, retry logic |
pkg/generated/ - Auto-Generated| File | Purpose |
|---|---|
providers.go |
Provider definitions (Anthropic, OpenAI, Bedrock, etc.) with field metadata and model specs - generated from TypeScript sources |
field_overrides.go |
Manual overrides for field filtering |
pkg/hostbridge/ - CLI-to-Core BridgeThis is the reverse bridge allowing cline-core to request host environment operations:
| File | Purpose |
|---|---|
grpc_server.go |
Main server registering all services |
simple_workspace.go |
Workspace service: returns CWD as workspace path |
diff.go |
In-memory file diff editing with line-based operations |
env.go |
Clipboard access, version info, shutdown coordination |
window.go |
UI stubs (no-ops or console output) |
Why this exists: The same cline-core logic runs in VS Code and CLI. In VS Code, the "host" is the extension with editor APIs. In CLI, hostbridge emulates these capabilities with terminal-appropriate implementations.
Two-process model: cline CLI manages instances; cline-core is the actual AI engine (Node.js). This allows reusing the same core as the VS Code extension.
Self-registration via SQLite: cline-core registers itself in a SQLite database on startup. The CLI discovers instances by reading this database, enabling multi-instance support.
Host bridge abstraction: The cline-host process provides platform-specific operations (clipboard, workspace paths) via gRPC, allowing cline-core to remain host-agnostic.
Streaming-first UI: The CLI uses gRPC streaming to display AI responses in real-time with typewriter-style rendering.
Dual stream handling: Task manager subscribes to both state updates and partial messages, using deduplication to prevent duplicate rendering.