💬 hippo: Part of the Claude Code Official Docs Breakdown series.


1. What Is the CLI?

The CLI (Command Line Interface) is the primary entry point to Claude Code. Starting an interactive session, running a one-shot query, wiring Claude into CI/CD pipelines, and managing account authentication all run through it.

Think of the CLI Reference as Claude Code’s command dictionary: claude drops you into an interactive chat, claude -p "query" drives it from a shell script, and claude auth login handles authentication. This breakdown organizes all 16 official commands and 40+ flags so you can grab the right invocation fast.


2. Official Docs Breakdown

2.1 Core Commands at a Glance

Claude Code ships 16 core commands spanning session management, authentication, plugins, and remote control:

Command Description Example
claude Start an interactive session claude
claude "query" Start an interactive session with an initial prompt claude "explain this project"
claude -p "query" Run a non-interactive query and exit claude -p "explain this function"
cat file | claude -p "query" Pipe file contents into a query cat logs.txt | claude -p "explain"
claude -c Continue the most recent conversation in the current directory claude -c
claude -c -p "query" Continue the most recent conversation via the SDK claude -c -p "Check for type errors"
claude -r "<session>" "query" Resume a specific session by ID or name claude -r "auth-refactor" "Finish this PR"
claude update Update to the latest version claude update
claude auth login Sign in to your account (--email prefills email, --sso enforces SSO, --console bills via Anthropic Console API usage) claude auth login --console
claude auth logout Sign out of your account claude auth logout
claude auth status Print authentication status as JSON (exit code 0 if signed in, 1 if not) claude auth status
claude agents List configured subagents claude agents
claude auto-mode defaults Print built-in auto-mode classifier rules as JSON (use claude auto-mode config to view effective rules after applying settings) claude auto-mode defaults > rules.json
claude mcp Configure MCP servers See MCP docs
claude plugin Manage plugins (alias: plugins) claude plugin install xxx@marketplace
claude remote-control Start a remote-control server accessible from claude.ai claude remote-control --name "My Project"

The five most common launch patterns:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 1. Start an interactive session
claude

# 2. Launch straight into a question
claude "Analyze the project architecture"

# 3. Non-interactive mode for scripts
claude -p "List all TypeScript files"

# 4. Continue the last conversation
claude -c

# 5. Resume a named session
claude -r "auth-refactor" "Finish implementing the auth module"

2.2 Print Mode

-p / --print executes a query through the SDK and exits immediately. It is the core flag for headless scripting and CI/CD:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Plain text output
claude -p "Explain this function"

# JSON output for jq parsing
claude -p "Analyze the code structure" --output-format json

# Streaming JSON for real-time processing
claude -p "Generate the code" --output-format stream-json

# Cap agent turns to prevent runaway loops
claude -p --max-turns 5 "Refactor this module"

# Cap spend in USD
claude -p --max-budget-usd 2.00 "review this code"

Output format comparison:

Format Use Case Characteristics
text Direct terminal display Human-readable
json Programmatic parsing Structured; easy to extract fields with jq
stream-json Real-time streaming Processes tokens as they arrive; suited for long outputs
--json-schema Schema-enforced output Guarantees output conforms strictly to a JSON Schema (print mode only)

2.3 System Prompt Flags

Four flags control Claude’s system prompt, split into replace and append variants:

Flag Behavior
--system-prompt Replace the entire default system prompt
--system-prompt-file Load a replacement system prompt from a file
--append-system-prompt Append text to the end of the default system prompt
--append-system-prompt-file Append text loaded from a file to the default system prompt

Key rules: All four flags work in both interactive and non-interactive modes. --system-prompt and --system-prompt-file are mutually exclusive, while append flags can be combined with replace flags. Default to the append flags for almost every use case—they preserve Claude Code’s built-in capabilities. Reach for replace only when you need total control over the prompt.

1
2
3
4
5
6
7
8
# Append custom instructions (recommended)
claude --append-system-prompt "Always use TypeScript strict mode"

# Append rules loaded from a file
claude --append-system-prompt-file ./coding-style.txt

# Replace completely (use with caution; drops built-in behavior)
claude --system-prompt "You are a Python expert"

2.4 Tool Permission Controls

--allowedTools and --disallowedTools give you fine-grained control over which tools Claude can invoke:

1
2
3
4
5
# Pre-approve read-only git commands without prompts
claude --allowedTools "Bash(git log *)" "Bash(git diff *)" "Read"

# Block file edits for read-only reviews
claude --disallowedTools "Edit" "Write"

Tool names support pattern matching: "Bash(git log *)" matches every command beginning with git log.

How these compare with --tools:

Flag Effect
--allowedTools Pre-approves listed tools without confirmation prompts; other tools remain available with prompts
--disallowedTools Removes listed tools from the model’s context completely
--tools Restricts the set of available tools ("" disables all tools; "default" enables all)

2.5 Notable New & Advanced Flags

Recent releases added a wide set of operational flags worth keeping on your radar:

Flag Description Typical Use Case
--from-pr <PR> Resume the session linked to a GitHub PR Picking up context during PR review
--worktree, -w Launch inside an isolated git worktree Parallel development without dirtying the main branch
--fallback-model Automatically fall back when the default model is overloaded Preventing single-point-of-failure outages in CI
--init Run initialization hooks, then enter interactive mode First-time project setup
--init-only Run initialization hooks and exit immediately CI environment prep
--maintenance Run maintenance hooks and exit Scheduled cleanup jobs
--session-id Pin a specific session UUID Deterministic session tracking
--mcp-config Load MCP server definitions from a JSON file Injecting MCP servers in CI
--strict-mcp-config Load only MCP servers from --mcp-config, ignoring all other configs Hardened, isolated environments
--enable-auto-mode Unlock auto mode (requires a Team plan or higher) Autonomous execution of complex tasks
--teammate-mode Configure how agent teams are displayed Multi-agent collaboration
--plugin-dir Load plugins from a specific local directory Testing locally developed plugins
--permission-prompt-tool Delegate permission prompts to an MCP tool Permission handling in non-interactive mode
--no-session-persistence Disable saving session history to disk Sensitive runs that must leave no trace
--bare Minimal mode: skips hooks, skills, plugins, MCP, auto memory, and CLAUDE.md; keeps only Bash and file read/write tools; sets CLAUDE_CODE_SIMPLE Fast, predictable script invocations
--effort Set reasoning effort level (low/medium/high/max) Tuning reasoning depth
--model Specify the model by alias (sonnet/opus) or full model ID Switching models per run
--agent Run a specific agent (overrides the agent field in settings) Invoking a custom agent
--agents Define subagents dynamically via inline JSON Spinning up ad-hoc subagents
--remote Create a remote web session on claude.ai Remote collaboration
--teleport Pull a claude.ai web session back into your local terminal Handing off from web to local
--fork-session Create a new session ID when resuming (pair with --resume/--continue) Branching an existing conversation
--debug Enable debug mode with optional category filters (e.g., "api,mcp") Troubleshooting
--debug-file <path> Write debug logs to a specific file Log collection
--chrome / --no-chrome Enable or disable Chrome browser integration Web automation
--json-schema Enforce a JSON Schema on output (print mode only) Guaranteed structured output
--tmux Create a tmux session for the worktree (pair with --worktree) Parallel terminal workflows
--settings Load an extra settings JSON file or inline JSON string Temporary overrides
--setting-sources Control which settings layers load (user/project/local) Configuration isolation
--input-format Set the input format (text/stream-json, print mode only) Programmatic integration
--include-hook-events Emit hook lifecycle events in streaming output Hook debugging
--disable-slash-commands Disable all skills and slash commands Minimalist execution
--permission-mode Start in a specific permission mode (default/acceptEdits/plan/auto/dontAsk/bypassPermissions) Fine-grained permission policies
--allow-dangerously-skip-permissions Add bypassPermissions to the Shift+Tab cycle without enabling it by default Opt-in escape hatch
--betas Attach beta headers to API requests (API key users only) Opting into experimental features
--channels Listen for specific MCP channel notifications (research preview) Plugin notifications
--ide Automatically connect to the IDE on startup IDE integration

Isolated development with git worktrees:

1
2
3
4
# Start in an isolated worktree without touching the current workspace
claude -w feature-auth

# The worktree lives at <repo>/.claude/worktrees/feature-auth

3. Hippo’s Field Notes

💬 hippo: Here are the pitfalls I ran into when using the CLI in production:

3.1 Three Pitfalls in CI/CD

When wiring Claude Code into GitHub Actions, I hit three classic failure modes:

Pitfall 1: Hanging in interactive mode. Running claude "query" in a script opens an interactive session. The CI runner waits forever for stdin and eventually times out.

Pitfall 2: Unattended permission prompts. Without pre-approved tools, Claude pauses on confirmation dialogs that nobody in CI can click, freezing the job.

Pitfall 3: Brittle output parsing. Default output is human-formatted plain text—scraping it with grep breaks as soon as phrasing shifts.

3.2 My CI-Friendly Command Template

To eliminate all three issues, I standardize on this template in CI pipelines:

1
2
3
4
5
6
7
# CI/CD command template
claude -p \
--output-format json \
--max-turns 3 \
--max-budget-usd 5.00 \
--allowedTools "Bash(git log *)" "Bash(git diff *)" "Read" \
"Inspect code quality and output a JSON report"

Flag-by-flag breakdown:

  • -p: Non-interactive print mode—executes and exits without hanging
  • --output-format json: Structured JSON output ready for jq
  • --max-turns 3: Caps the loop at 3 turns so the agent cannot burn tokens indefinitely
  • --max-budget-usd 5.00: Hard $5.00 spend guardrail
  • --allowedTools: Pre-approves read-only commands to bypass confirmation prompts safely

Use --bare when you need strict isolation:

1
2
# Bare mode: skips hooks, skills, plugins, MCP, auto memory, and CLAUDE.md; keeps only Bash and file read/write
claude --bare -p --max-turns 1 "Generate a commit message"

3.3 Using auth status as a Preflight Check

claude auth status returns a clean exit code, making it ideal as a guard at the top of automation scripts:

1
2
3
4
5
6
7
8
9
#!/bin/bash
# Check authentication before running CI tasks
if ! claude auth status --text; then
echo "ERROR: Not signed in to Claude Code. Please configure an API key."
exit 1
fi

# Authenticated; proceed with the review
claude -p "review this PR" --output-format json

3.4 Practical Recommendations

  1. Restrict --dangerously-skip-permissions to Docker containers and ephemeral CI runners. Never use it during local development—one bad shell command can wipe files with no undo. If you just want fewer prompts locally, pre-approve specific tools with --allowedTools.
  2. Use --bare to speed up scripted invocations. Automation jobs rarely need hooks, plugins, or MCP servers; --bare skips loading them for noticeably faster startup.
  3. Turn on --verbose while debugging. Seeing the full reasoning trace and tool-call payloads makes diagnosing unexpected behavior straightforward.
  4. Name your sessions with -n. Make claude -n "feature-auth-work" a habit so you can jump straight back in later with claude -r "feature-auth-work".

4. FAQ

Q: What is the difference between claude -c and claude --continue?
A: None. -c is the short alias for --continue; both resume the most recent conversation in the current directory.

Q: How do I capture structured output in a shell script?
A: Combine --output-format json with jq:

1
claude -p "Analyze the code" --output-format json | jq '.result'

Q: Should I use --dangerously-skip-permissions or --allowedTools?
A: Default to --allowedTools. It pre-approves only the exact tools you allow while keeping confirmation guards on everything else. --dangerously-skip-permissions disables every check and belongs strictly inside disposable, isolated environments such as Docker containers or CI runners.

Q: How do I inject an MCP configuration in CI?
A: Pass --mcp-config with your JSON file and pair it with --strict-mcp-config to ignore ambient MCP configs:

1
claude -p --mcp-config ./ci-mcp.json --strict-mcp-config "query"

Q: What if the default model is overloaded and breaks CI?
A: Configure a fallback model with --fallback-model:

1
claude -p --fallback-model sonnet "review this code"

Q: Are there any constraints on --effort?
A: The max level is exclusive to Opus 4.6. The setting applies only to the current session and is not persisted.

Q: What are the prerequisites for --enable-auto-mode?
A: It requires a Team, Enterprise, or API plan along with Claude Sonnet 4.6 or Opus 4.6.

Q: What do --remote and --teleport do?
A: --remote creates a remote web session on claude.ai for cloud-based collaboration. --teleport does the reverse—it pulls a claude.ai web session back into your local terminal so you can keep working locally.

Q: How do I guarantee the response matches a specific JSON structure?
A: Pass a JSON Schema via --json-schema (available in print mode only):

1
claude -p --json-schema '{"type":"object","properties":{"summary":{"type":"string"}}}' "Summarize this code"

5. Summary

The CLI is the universal entry point to Claude Code. Once you know the key commands and flags, you can:

  • Manage sessions effortlessly (-c to continue, -r to resume, -n to name, --fork-session to branch)
  • Wire Claude into scripts and pipelines (-p print mode, --bare minimal mode, --output-format json, --json-schema structured output)
  • Enforce least-privilege tool access (--allowedTools, --disallowedTools, --permission-mode)
  • Run reliably in CI (--max-turns, --max-budget-usd, --fallback-model, --model)
  • Isolate parallel workspaces (-w worktree, --tmux, --strict-mcp-config)
  • Collaborate across web and terminal (--remote, --teleport, --remote-control)

Series Navigation


Based on the official CLI Reference — Claude Code Docs.

Last updated: 2026-04-09