← Study Guide
CLI REFERENCE

Claude Code CLI

The command-line interface — commands to start, pipe, resume, and manage sessions, plus the flags worth memorizing. Grouped so they stick; see the memory aids at the bottom.

Start here — the essentials

If you remember nothing else, remember these six.

claude
Start an interactive session.
the default
claude -c
Continue the most recent conversation here.
-c = continue
claude -r "name"
Resume a specific session by name or ID.
-r = resume
claude -p "query"
Print (headless): answer once and exit — for pipes & scripts.
-p = print/pipe
claude update
Update to the latest version.
stay current
claude mcp
Configure MCP servers.
tools & integrations

Commands

claude <command> — start sessions, authenticate, manage background agents, and configure MCP/plugins.

Start & query

claude
Start an interactive session.
claude
claude "query"
Start interactive with an initial prompt.
claude "explain this project"
claude -p "query"
Headless / print mode: query, print the result, then exit.
claude -p "explain this function"
cat file | claude -p "query"
Pipe content in and process it headlessly.
cat logs.txt | claude -p "explain"

Continue & resume

Three ways back into work: continue the last one, or resume a named/ID'd one.

claude -c
Continue the most recent conversation in this directory.
claude -c
claude -c -p "query"
Continue the last conversation, headlessly.
claude -c -p "Check for type errors"
claude -r "<session>" "query"
Resume a session by ID or name and send a prompt.
claude -r "auth-refactor" "Finish this PR"

Auth (like git remote auth)

claude auth login
Sign in. --email pre-fills, --sso forces SSO, --console uses Console/API billing.
claude auth login --console
claude auth logout
Log out of your Anthropic account.
claude auth logout
claude auth status
Auth status as JSON (--text for readable). Exits 0 if logged in, 1 if not.
claude auth status
claude setup-token
Generate a long-lived OAuth token for CI/scripts (prints, doesn't save). Needs a subscription.
claude setup-token

Install & update

claude update
Update to the latest version.
claude update
claude install [version]
Install/reinstall the native binary — a version, stable, or latest.
claude install stable

Background sessions (agent view) — think mini job control

Manage parallel background agents the way you'd manage OS jobs: list, attach, log, stop, remove, restart.

claude agents
Open agent view to monitor/dispatch parallel sessions. --json for scripting; --cwd, --model, --permission-mode, --effort, --agent set defaults.
claude agents --json
claude attach <id>
Attach to a background session in this terminal.
claude attach 7c5dcf5d
claude logs <id>
Print recent output from a background session.
claude logs 7c5dcf5d
claude respawn <id>
Restart a session (running or stopped) with its conversation intact. --all for every one.
claude respawn 7c5dcf5d
claude stop <id>
Stop a background session. Also claude kill.
claude stop 7c5dcf5d
claude rm <id>
Remove a session from the list. Transcript stays and is resumable.
claude rm 7c5dcf5d
claude daemon status
Supervisor state, version, socket dir, worker count. Exits 1 if not running.
claude daemon status
claude daemon stop --any
Stop the supervisor and its sessions. --keep-workers leaves sessions running.
claude daemon stop --any --keep-workers

MCP & plugins

claude mcp
Configure Model Context Protocol servers.
add / list / get / remove
claude mcp login <name>
Run an MCP server's OAuth flow from the CLI. --no-browser over SSH. (v2.1.186+)
claude mcp login sentry
claude mcp logout <name>
Clear stored OAuth credentials for an MCP server. (v2.1.186+)
claude mcp logout sentry
claude plugin
Manage plugins (alias claude plugins).
claude plugin install code-review@claude-plugins-official

Admin & housekeeping

claude gateway --config gateway.yaml
Start the self-hosted Claude apps gateway (admin SSO/policy for Bedrock/Vertex/Foundry). (v2.1.195+)
enterprise deploys
claude remote-control
Start a Remote Control server to drive Claude from Claude.ai or the app.
claude remote-control --name "My Project"
claude project purge [path]
Delete all local state for a project. --dry-run previews, -y skips confirm, --all for every project.
claude project purge ~/work/repo --dry-run
claude auto-mode defaults
Print the built-in auto-mode classifier rules as JSON.
claude auto-mode defaults > rules.json
claude ultrareview [target]
Run ultrareview non-interactively. --json for raw payload, --timeout <min>. Exits 0/1.
claude ultrareview 1234 --json

Flags

claude --help doesn't list every flag — absence from --help doesn't mean it's unavailable. A curated, memorable set:

Session control

The short flags spell what they do: -p print, -c continue, -r resume.

-p, --print
Headless: print the response and exit. Pairs with pipes and CI.
claude -p "..."
-c, --continue
Load the most recent conversation in this directory.
claude --continue
-r, --resume
Resume a specific session by ID or name.
claude -r "auth-refactor"
--model
Model for this session (overrides the model setting).
claude --model claude-sonnet-5
--effort
Effort level: low/medium/high/xhigh/max (session only, doesn't persist).
claude --effort high
--agent
Use a specific agent for the session (overrides the agent setting).
claude --agent my-custom-agent
--permission-mode
Start in a permission mode: plan, acceptEdits, auto, bypassPermissions.
claude --permission-mode plan

Permissions & file access

--add-dir
Add extra working directories to read/edit. Grants file access, not .claude/ config.
claude --add-dir ../apps ../lib
--allowedTools / --allowed-tools
Tools that run without a permission prompt.
"Bash(git log *)" "Read"
--disallowedTools / --disallowed-tools
Deny rules. A bare name removes the tool from context; a scoped rule denies only matching calls.
"Bash(rm *)" "Edit"
--dangerously-skip-permissions
Skip all permission prompts. Equals --permission-mode bypassPermissions.
"dangerous" ⇒ prefix
--allow-dangerously-skip-permissions
Add bypass to the Shift+Tab cycle without starting in it.
start in plan, switch later

Prompt & subagents

--append-system-prompt
Append custom text to the end of the system prompt.
--append-system-prompt "Always use TypeScript"
--append-system-prompt-file
Append system-prompt text loaded from a file.
--append-system-prompt-file ./extra-rules.txt
--agents
Define custom subagents inline via JSON (same fields as frontmatter + prompt).
--agents '{"reviewer":{...}}'

Speed & scripting

--bare
Minimal mode: skip auto-discovery of hooks/skills/plugins/MCP/CLAUDE.md so scripts start fast. Bash + read + edit only.
claude --bare -p "query"
--bg, --background
Start as a background agent and return immediately. Can't combine with -p.
claude --bg "investigate the flaky test"
--json
On subcommands (agents, auth status, ultrareview): machine-readable output for scripting.
claude agents --json

Debug & diagnostics

--debug
Debug mode with optional category filter, e.g. "api,mcp" or "!statsig".
claude --debug "api,mcp"
--debug-file <path>
Write debug logs to a file (implicitly enables debug).
claude --debug-file /tmp/claude-debug.log
--disable-slash-commands
Disable all skills and commands for the session.
claude --disable-slash-commands

Tooling & integrations

--advisor <model>
Enable the server-side advisor tool: opus, sonnet, or fable. (v2.1.98+)
claude --advisor opus
--betas
Beta headers to include on API requests (API-key users only).
claude --betas interleaved-thinking
--chrome
Enable Chrome browser integration for web automation/testing.
claude --chrome
--cloud
Create a new web session on claude.ai with the given task.
claude --cloud "Fix the login bug"
--ax-screen-reader
Screen-reader-friendly flat output (no borders/animations). (v2.1.181+)
claude --ax-screen-reader

Deep dive: --dangerously-skip-permissions vs -p --bare

Both are common in automation, but they strip away different layers. --dangerously-skip-permissions suppresses permission prompts; -p --bare minimizes the startup environment. Knowing which does what is the difference between a script that runs and one that hangs.

claude --dangerously-skip-permissions
The autonomous hammer — controls behavior, not startup.

What it does: Sets the permission tier to bypassPermissions. Claude reads/writes files and runs bash commands without ever asking for approval.

The catch: The full feature set stays on: it scans for CLAUDE.md, loads plugins/skills, reads settings and conversation history, and uses your OAuth / Keychain credentials.

claude -p "…" --bare
The scripting engine — optimizes startup for raw speed & isolation.

What it does: Skips the heavy discovery phase: no hooks, skills, plugins, MCP, auto-memory, or CLAUDE.md. -p runs one-shot (headless). Community reports it also leans on ANTHROPIC_API_KEY rather than OAuth/Keychain.

The catch: Permissions are NOT bypassed. If Claude tries to run a command, it still asks — so in a non-interactive pipe it will hang or fail unless you add a permission flag.

Capability--dangerously-skip-permissions-p --bare
Primary goalStop permission-prompt fatigueFast, clean, isolated script runs
Interactive UIYes — standard TTY terminalNo — one-shot execution
Prompts / approvalsBypassed — 100% autonomousActive — still needs approvals
Auth sourceSystem Keychain / web OAuthANTHROPIC_API_KEY env var
Reads project contextYes — CLAUDE.md & historyNo — clean slate
Speeds up startupNoYes — skips lookups

The “perfect” headless recipe

For a CI/CD job or cron task that must run fast, without human auth, and fully autonomously, neither flag is enough alone — combine all three.

claude -p "Refactor the helper functions in src/utils.ts" --bare --dangerously-skip-permissions
  • --bare — skips browser popups and boots instantly.
  • -p — pipes your direct text request in and runs one-shot.
  • --dangerously-skip-permissions — stops it freezing while it waits for a human to type “yes”.

Make it stick

  • The short flags spell themselves: -p = print (headless), -c = continue (most recent), -r = resume (by name/ID).
  • Background = mini job control: agents (list) · attach · logs · stop/kill · rm · respawn — the same verbs you'd use on OS jobs.
  • Auth mirrors git: claude auth login / logout / status, plus setup-token for CI.
  • **Anything risky starts with --dangerously-…** (e.g. --dangerously-skip-permissions). Easy to spot in scripts and reviews.
  • Headless recipe: claude -p "…" --output-format json for scripts; add --bare to skip discovery and start faster.
  • Mistype a subcommand and Claude suggests the closest match (claude udpate → “Did you mean claude update?”) and exits without starting.

Summarized from the official Claude Code CLI reference (code.claude.com/docs/en/cli-reference) for study. A curated selection — check the live docs for the full command and flag list.