cli-reference
Original:🇺🇸 English
Translated
Claude Code CLI commands, flags, headless mode, and automation patterns
24installs
Added on
NPX Install
npx skill4agent add parcadei/continuous-claude-v3 cli-referenceTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →CLI Reference
Complete reference for Claude Code command-line interface.
When to Use
- "What CLI flags are available?"
- "How do I use headless mode?"
- "Claude in automation/CI/CD"
- "Output format options"
- "System prompt via CLI"
- "How do I spawn agents properly?"
Core Commands
| Command | Description | Example |
|---|---|---|
| Start interactive REPL | |
| REPL with initial prompt | |
| Headless mode (SDK) | |
| Process piped content | |
| Continue most recent | |
| Continue via SDK | |
| Resume session | |
| Update version | |
| Configure MCP servers | See MCP docs |
Session Control
| Flag | Description | Example |
|---|---|---|
| Load most recent conversation | |
| Resume session by ID/name | |
| Use specific UUID | |
| Create new session on resume | |
Headless Mode (Critical for Agents)
| Flag | Description | Example |
|---|---|---|
| Non-interactive, exit after | |
| | |
| Limit agentic turns | |
| Full turn-by-turn output | |
| Skip permission prompts | |
| Include streaming events | |
| Input format (text/stream-json) | |
Tool Control
| Flag | Description | Example |
|---|---|---|
| Auto-approve these tools | |
| Block these tools | |
| Only allow these tools | |
Subagent Definition (--agents flag)
Define custom subagents inline via JSON:
bash
claude --agents '{
"code-reviewer": {
"description": "Expert code reviewer. Use proactively after code changes.",
"prompt": "You are a senior code reviewer. Focus on code quality and security.",
"tools": ["Read", "Grep", "Glob", "Bash"],
"model": "sonnet"
},
"debugger": {
"description": "Debugging specialist for errors and test failures.",
"prompt": "You are an expert debugger. Analyze errors and provide fixes."
}
}'Agent Fields
| Field | Required | Description |
|---|---|---|
| Yes | When to invoke this agent |
| Yes | System prompt for behavior |
| No | Allowed tools (inherits all if omitted) |
| No | |
Key Insight
When Lead uses Task tool, it auto-spawns from these definitions. No manual spawn needed.
System Prompt Customization
| Flag | Behavior | Modes |
|---|---|---|
| Replace entire prompt | Interactive + Print |
| Replace from file | Print only |
| Append to default (recommended) | Interactive + Print |
Use for most cases - preserves Claude Code capabilities.
--append-system-promptModel Selection
| Flag | Description | Example |
|---|---|---|
| Set model for session | |
| Fallback if default overloaded | |
Aliases: , ,
sonnetopushaikuMCP Configuration
| Flag | Description | Example |
|---|---|---|
| Load MCP servers from JSON | |
| Only use these MCP servers | |
Advanced Flags
| Flag | Description | Example |
|---|---|---|
| Add working directories | |
| Specify agent for session | |
| Start in permission mode | |
| MCP tool for permissions | |
| Load plugins from directory | |
| Load settings from file/JSON | |
| Which settings to load | |
| Beta API headers | |
| Enable debug mode | |
| Auto-connect to IDE | |
| Enable Chrome integration | |
| Disable Chrome for session | |
| Verbose LSP debugging | |
| Output version | |
Output Formats
JSON (for parsing)
bash
claude -p "query" --output-format json
# {"result": "...", "session_id": "...", "usage": {...}}Streaming (for real-time monitoring)
bash
claude -p "query" --output-format stream-json
# Newline-delimited JSON eventsStructured Output (schema validation)
bash
claude -p "Extract data" \
--output-format json \
--json-schema '{"type":"object","properties":{...}}'Headless Agent Pattern (CRITICAL)
Proper headless agent spawn:
bash
claude -p "$TASK_PROMPT" \
--session-id "$UUID" \
--dangerously-skip-permissions \
--max-turns 100 \
--output-format stream-json \
--agents '{...}' \
--append-system-prompt "Context: ..."Missing any of these causes hangs:
- - Track the session
--session-id - - Headless requires this
--dangerously-skip-permissions - - Prevents infinite loops
--max-turns
Common Patterns
CI/CD Automation
bash
claude -p "Run tests and fix failures" \
--dangerously-skip-permissions \
--max-turns 50 \
--output-format json | jq '.result'Piped Input
bash
cat error.log | claude -p "Find root cause"
gh pr diff | claude -p "Review for security"Multi-turn Session
bash
id=$(claude -p "Start task" --output-format json | jq -r '.session_id')
claude -p "Continue" --resume "$id"Stream Monitoring
bash
claude -p "Long task" \
--output-format stream-json \
--include-partial-messages | while read -r line; do
echo "$line" | jq '.type'
doneKeyboard Shortcuts (Interactive)
| Shortcut | Action |
|---|---|
| Cancel current |
| Exit |
| Reverse search history |
| Rewind changes |
| Toggle permission mode |
Quick Commands
| Prefix | Action |
|---|---|
| Slash command |
| Bash mode |
| Add to memory |
| File mention |