CLI reference
Complete Claude Code CLI reference: all commands, flags, options, and usage examples.
Main command: claude
claude [OPTIONS] [PROMPT]
General flags
| Flag | Alias | Type | Description |
|---|---|---|---|
--model <id> | -m | string | Model to use (claude-haiku-4-5, claude-sonnet-4-5, claude-opus-4-5, etc.) |
--print | -p | boolean | Non-interactive mode: print the response and exit |
--output-format <fmt> | string | Output format: text (default), json, stream-json | |
--verbose | boolean | Show tool calls and metadata (debug) | |
--no-cache | boolean | Disable prompt caching (avoid cached results) | |
--dangerously-skip-permissions | boolean | Not recommended: skip all confirmation prompts | |
--continue | -c | boolean | Resume the last conversation session |
--resume <id> | string | Resume a specific session by its identifier | |
--max-turns <n> | number | Limit the number of exchange turns (agentic mode) | |
--allowedTools <list> | string | Allowed tools (comma-separated: Bash,Read,Write) | |
--disallowedTools <list> | string | Disallowed tools (comma-separated) | |
--system-prompt <text> | -s | string | System prompt to inject (overrides CLAUDE.md) |
--append-system-prompt <text> | string | Text appended to the existing system prompt | |
--add-dir <path> | string | Add a directory to the accessible file context | |
--debug | boolean | Extended debug mode (internal logs) | |
--version | -v | boolean | Show the installed Claude Code version |
--help | -h | boolean | Show help |
--dangerously-skip-permissions
This flag bypasses all Claude Code confirmations, including before destructive actions (file deletion, script execution, API calls). Only use it in an isolated sandbox environment, never in production.
Examples: claude command
# Standard interactive sessionclaude# Interactive session with a specific modelclaude --model claude-opus-4-5# Print mode: execute a task and exitclaude --print "Explain the code in src/auth.ts"claude -p "Generate unit tests for utils/date.ts"# Print mode with JSON formatclaude --print --output-format json "List the functions in this file"# Stream-json mode (for real-time processing)claude --print --output-format stream-json "Analyze this project"# Limit the number of turns (agentic mode)claude --max-turns 5 "Refactor the auth module"# Restrict available toolsclaude --allowedTools "Read,Bash" "Analyze without modifying files"# Resume the last sessionclaude --continue# Resume a session by IDclaude --resume abc123# Verbose (debug)claude --verbose "Why is this test failing?"
Pipe mode (stdin -> stdout)
The --print mode is compatible with standard Unix pipes.
# Pass a file as inputcat src/auth.ts | claude --print "Add JSDoc comments to this code"# Chain commandsgit diff HEAD~1 | claude --print "Summarize these changes in bullet points"# Pass a prompt via standard inputecho "Explain the Observer Design Pattern" | claude --print# Integration in a shell scriptRESULT=$(claude --print --output-format json "Analyze this code" < src/main.ts)echo $RESULT | jq '.content[0].text'# Read from a fileclaude --print "What are the security risks here?" < config/database.yml
SDK / headless mode
For automated scripts, CI/CD pipelines, and applications that integrate Claude Code.
# Non-interactive execution with strict controlANTHROPIC_API_KEY="sk-ant-..." \claude \--print \--max-turns 1 \--output-format json \"Check code quality in src/"# Agentic mode with multiple turnsclaude \--print \--max-turns 10 \--dangerously-skip-permissions \"Run the test suite and fix the errors"# With environment variables in the configclaude \--print \--allowedTools "Read,Bash,Write" \--system-prompt "You are a security expert. Do not modify any files." \"Audit this project"
CI/CD integration
In CI/CD, always use --print and --max-turns to avoid infinite sessions. Set ANTHROPIC_API_KEY as a secret in your CI platform (GitHub Actions, GitLab CI, etc.). See our complete guide on hooks and headless mode.
Subcommand: claude config
Manages Claude Code configuration (~/.claude/settings.json file by default).
claude config [SUBCOMMAND] [OPTIONS]
| Subcommand | Description |
|---|---|
claude config list | List all active options and their values |
claude config get <key> | Show the value of a specific key |
claude config set <key> <value> | Set a key's value |
claude config add <key> <value> | Add a value to an array |
claude config remove <key> <value> | Remove a value from an array |
# Examplesclaude config listclaude config get model# -> claude-sonnet-4-5claude config set model claude-opus-4-5claude config add allowedTools "Bash"claude config remove allowedTools "Bash"# With scope (global by default)claude config --global set model claude-haiku-4-5
Subcommand: claude mcp
Manages MCP (Model Context Protocol) servers.
claude mcp [SUBCOMMAND] [OPTIONS]
claude mcp add
claude mcp add [OPTIONS] <name> -- <command> [args...]
| Option | Description |
|---|---|
--scope <scope> | global (default), project, or user |
--transport <type> | stdio (default) or sse |
-e <VAR=value> | Set an environment variable for the MCP |
# Add a stdio MCP (local, via npx)claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem ~/projects# Add an MCP with project scopeclaude mcp add --scope project postgres -- \npx -y @modelcontextprotocol/server-postgres postgresql://localhost/mydb# Add an MCP with an environment variableclaude mcp add github -e GITHUB_TOKEN=ghp_xxx -- \npx -y @modelcontextprotocol/server-github# Add an MCP via SSE transport (HTTP)claude mcp add --transport sse my-api https://api.example.com/mcp# Add a Python MCP (via uvx)claude mcp add my-script -- uvx my-python-package
claude mcp remove
claude mcp remove [--scope <scope>] <name>
claude mcp remove filesystemclaude mcp remove --scope project postgres
claude mcp list
claude mcp list# Shows: name, status (connected/disconnected), available tools, scope
claude mcp logs
# Show MCP logs (useful for debugging)claude mcp logs github# Follow logs in real timeclaude mcp logs -f filesystem
claude mcp get
# Show the full configuration for an MCPclaude mcp get github
Subcommand: claude doctor
Diagnoses your Claude Code installation and configuration.
claude doctor
It checks:
- Claude Code version and available updates
- Network connectivity to the Anthropic API
- API key validity (
ANTHROPIC_API_KEY) - Status of configured MCPs (connection, available tools)
- System permissions (file read/write)
- Shell and environment variable configuration
# Example outputclaude doctor# -> Claude Code v1.x.x (up to date)# -> Anthropic API reachable# -> ANTHROPIC_API_KEY valid# -> MCP filesystem: connected (5 tools)# x MCP github: connection error (GITHUB_TOKEN missing)# -> File permissions: OK
Subcommand: claude update
# Update Claude Code to the latest versionclaude update# Check version without updatingclaude --version
Advanced options: output formats
--output-format text (default)
Plain text formatted for human reading. Includes markdown rendered in the terminal.
--output-format json
Returns a complete JSON object with the response and metadata.
{"type": "result","subtype": "success","cost_usd": 0.0023,"is_error": false,"duration_ms": 1842,"num_turns": 1,"result": "Response text here...","session_id": "abc123"}
--output-format stream-json
Stream of JSON messages (newline-delimited) in real time, suited for streaming processing.
# Line-by-line processingclaude --print --output-format stream-json "prompt" | while IFS= read -r line; doecho "$line" | jq -r 'select(.type == "content_block_delta") | .delta.text // empty'done
Next steps
- Cheatsheet: Quick reference: Slash commands and shortcuts
- settings.json: Complete guide: All configuration options
- Environment variables: Variables recognized by Claude Code