Skip to main content
Reference

CLI reference

Complete Claude Code CLI reference: all commands, flags, options, and usage examples.

Main command: claude

claude [OPTIONS] [PROMPT]

General flags

FlagAliasTypeDescription
--model <id>-mstringModel to use (claude-haiku-4-5, claude-sonnet-4-6, claude-opus-4-6, etc.)
--print-pbooleanNon-interactive mode: print the response and exit
--output-format <fmt>stringOutput format: text (default), json, stream-json
--verbosebooleanShow tool calls and metadata (debug)
--no-cachebooleanDisable prompt caching (avoid cached results)
--dangerously-skip-permissionsbooleanNot recommended: skip all confirmation prompts
--continue-cbooleanResume the last conversation session
--resume <id>stringResume a specific session by its identifier
--max-turns <n>numberLimit the number of exchange turns (agentic mode)
--allowedTools <list>stringAllowed tools (comma-separated: Bash,Read,Write)
--disallowedTools <list>stringDisallowed tools (comma-separated)
--system-prompt <text>-sstringSystem prompt to inject (overrides CLAUDE.md)
--append-system-prompt <text>stringText appended to the existing system prompt
--add-dir <path>stringAdd a directory to the accessible file context
--worktree-wbooleanLaunch the session in an isolated git worktree
--barebooleanMinimal mode: no CLAUDE.md, no MCP servers, no plugins
--teleportbooleanPull a web session (claude.ai/code) into your local terminal
--agent <name>stringUse a custom agent from .claude/agents/ as the system prompt
--max-budget-usd <amount>numberCap the session spend in USD
--debugbooleanExtended debug mode (internal logs)
--version-vbooleanShow the installed Claude Code version
--help-hbooleanShow help

Examples: claude command

# Standard interactive session
claude
# Interactive session with a specific model
claude --model claude-opus-4-6
# Print mode: execute a task and exit
claude --print "Explain the code in src/auth.ts"
claude -p "Generate unit tests for utils/date.ts"
# Print mode with JSON format
claude --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 tools
claude --allowedTools "Read,Bash" "Analyze without modifying files"
# Resume the last session
claude --continue
# Resume a session by ID
claude --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 worktree
claude --worktree "Implement the payment feature"
# With a specific model
claude -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 all
claude --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 task
claude --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 terminal
claude --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.md
claude --agent code-reviewer "Review the changes in src/api/"
# Security agent for an audit
claude --agent security-auditor --print "Analyze this file" < src/auth.ts
# Technical writing agent
claude --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.50
claude --max-budget-usd 0.50 "Analyze and refactor the src/ directory"
# In CI/CD to prevent runaway costs
claude \
--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 input
cat src/auth.ts | claude --print "Add JSDoc comments to this code"
# Chain commands
git diff HEAD~1 | claude --print "Summarize these changes in bullet points"
# Pass a prompt via standard input
echo "Explain the Observer Design Pattern" | claude --print
# Integration in a shell script
RESULT=$(claude --print --output-format json "Analyze this code" < src/main.ts)
echo $RESULT | jq '.content[0].text'
# Read from a file
claude --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 control
ANTHROPIC_API_KEY="sk-ant-..." \
claude \
--print \
--max-turns 1 \
--output-format json \
"Check code quality in src/"
# Agentic mode with multiple turns
claude \
--print \
--max-turns 10 \
--dangerously-skip-permissions \
"Run the test suite and fix the errors"
# With environment variables in the config
claude \
--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]
SubcommandDescription
claude config listList 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
# Examples
claude config list
claude config get model
# -> claude-sonnet-4-6
claude config set model claude-opus-4-6
claude 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...]
OptionDescription
--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 scope
claude mcp add --scope project postgres -- \
npx -y @modelcontextprotocol/server-postgres postgresql://localhost/mydb
# Add an MCP with an environment variable
claude 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 filesystem
claude 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 time
claude mcp logs -f filesystem

claude mcp get

# Show the full configuration for an MCP
claude 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 output
claude 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 version
claude update
# Check version without updating
claude --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 processing
claude --print --output-format stream-json "prompt" | while IFS= read -r line; do
echo "$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):

CommandDescription
/voiceEnable/disable Voice Mode (push-to-talk with Space)
/loop <interval> <task>Launch a recurring task (e.g., /loop 5m /review-pr)
/helpShow help and list of available commands
/compactCompress the conversation context
/memoryShow persistent memory (CLAUDE.md)
/initInitialize a CLAUDE.md file in the current project
/reviewLaunch a code review of the project
/costShow the current session cost
/clearClear the conversation and start fresh

Next steps