- Reference
- Cli
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-6, claude-opus-4-6, 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 | |
--worktree | -w | boolean | Launch the session in an isolated git worktree |
--bare | boolean | Minimal mode: no CLAUDE.md, no MCP servers, no plugins | |
--teleport | boolean | Pull a web session (claude.ai/code) into your local terminal | |
--agent <name> | string | Use a custom agent from .claude/agents/ as the system prompt | |
--max-budget-usd <amount> | number | Cap the session spend in USD | |
--debug | boolean | Extended debug mode (internal logs) | |
--version | -v | boolean | Show the installed Claude Code version |
--help | -h | boolean | Show help |
Examples: claude command
# Standard interactive sessionclaude# Interactive session with a specific modelclaude --model claude-opus-4-6# 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?"
Advanced flags
--worktree / -w: parallel sessions without conflicts
When you're juggling multiple features at once, branches can get in each other's way. --worktree spins up an isolated git worktree for the session: each Claude instance gets its own copy of the repo and can make changes without touching the others.
# Start a session in an isolated worktreeclaude --worktree "Implement the payment feature"# With a specific modelclaude -w --model claude-opus-4-5 "Refactor the auth module"
--bare: fast startup with no context
By default, Claude Code loads your CLAUDE.md, connects MCP servers, and initializes plugins. That all takes time. With --bare, none of that happens: the session starts almost instantly.
This is the go-to mode for scripts where you don't need project context, and for CI/CD pipelines where startup time adds up.
# Minimal startup, no project context at allclaude --bare --print "Generate a UUID v4 in TypeScript"# In a shell script (starts ~10x faster)claude --bare --print --output-format json "Parse this JSON" < data.json# In CI/CD for a one-off taskclaude --bare --print --max-turns 1 "Check the syntax of this YAML file" < config.yml
--teleport: bring a web session into your terminal
You started a conversation on claude.ai/code in your browser and now you want to continue it in the terminal, with full access to file and bash tools. --teleport does exactly that: it picks up the active session and drops you right back where you left off, with the full power of the CLI.
# Pull the last active web session into the terminalclaude --teleport# If multiple sessions are available, a list is shown for you to pick from
--agent <name>: specialized agents
Claude Code lets you define custom agents in .claude/agents/. Each agent is a YAML or Markdown file that specifies a specialized system prompt. The --agent flag loads that agent at session startup.
# Use the "code-reviewer" agent defined in .claude/agents/code-reviewer.mdclaude --agent code-reviewer "Review the changes in src/api/"# Security agent for an auditclaude --agent security-auditor --print "Analyze this file" < src/auth.ts# Technical writing agentclaude --agent tech-writer "Generate documentation for this module"
--max-budget-usd <amount>: cost control
For long-running tasks or automated pipelines, it's useful to cap spending per session. When the budget runs out, Claude stops cleanly rather than continuing to rack up costs.
# Session capped at $0.50claude --max-budget-usd 0.50 "Analyze and refactor the src/ directory"# In CI/CD to prevent runaway costsclaude \--print \--max-budget-usd 1.00 \--max-turns 20 \"Run the tests and fix any errors"
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"
Subcommand: claude agents
Lists all configured and running Background Agents with their status, Git branch, and duration.
claude agents
# Example output# ID STATUS BRANCH SINCE# agent-a3f2 running feat/refactor-auth 5m ago# agent-b8c1 running feat/add-tests 2m ago# agent-d9e4 completed fix/memory-leak 12m ago
See the Background Agents page for usage with Git Worktree.
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-6claude config set model claude-opus-4-6claude 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
Interactive session slash commands
These commands are typed directly in an interactive Claude Code session (not from the command line):
| Command | Description |
|---|---|
/voice | Enable/disable Voice Mode (push-to-talk with Space) |
/loop <interval> <task> | Launch a recurring task (e.g., /loop 5m /review-pr) |
/help | Show help and list of available commands |
/compact | Compress the conversation context |
/memory | Show persistent memory (CLAUDE.md) |
/init | Initialize a CLAUDE.md file in the current project |
/review | Launch a code review of the project |
/cost | Show the current session cost |
/clear | Clear the conversation and start fresh |
Next steps
- Cheatsheet: Quick reference: Slash commands and shortcuts
- settings.json: Complete guide: All configuration options
- Environment variables: Variables recognized by Claude Code
- Voice Mode: Dictate tasks out loud
- Background Agents: Parallel execution with Git Worktree