Claude Code CLI Commands & Flags
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.
-c = continue-r = resume-p = print/pipeCommands
claude <command> — start sessions, authenticate, manage background agents, and configure MCP/plugins.
Start & query
claudeclaude "explain this project"claude -p "explain this function"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 -cclaude -c -p "Check for type errors"claude -r "auth-refactor" "Finish this PR"Auth (like git remote auth)
--email pre-fills, --sso forces SSO, --console uses Console/API billing.claude auth login --consoleclaude auth logout--text for readable). Exits 0 if logged in, 1 if not.claude auth statusclaude setup-tokenInstall & update
claude updatestable, or latest.claude install stableBackground sessions (agent view) — think mini job control
Manage parallel background agents the way you'd manage OS jobs: list, attach, log, stop, remove, restart.
--json for scripting; --cwd, --model, --permission-mode, --effort, --agent set defaults.claude agents --jsonclaude attach 7c5dcf5dclaude logs 7c5dcf5d--all for every one.claude respawn 7c5dcf5dclaude kill.claude stop 7c5dcf5dclaude rm 7c5dcf5dclaude daemon status--keep-workers leaves sessions running.claude daemon stop --any --keep-workersMCP & plugins
--no-browser over SSH. (v2.1.186+)claude mcp login sentryclaude mcp logout sentryclaude plugins).claude plugin install code-review@claude-plugins-officialAdmin & housekeeping
claude remote-control --name "My Project"--dry-run previews, -y skips confirm, --all for every project.claude project purge ~/work/repo --dry-runclaude auto-mode defaults > rules.json--json for raw payload, --timeout <min>. Exits 0/1.claude ultrareview 1234 --jsonFlags
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.
claude -p "..."claude --continueclaude -r "auth-refactor"model setting).claude --model claude-sonnet-5low/medium/high/xhigh/max (session only, doesn't persist).claude --effort highagent setting).claude --agent my-custom-agentplan, acceptEdits, auto, bypassPermissions.claude --permission-mode planPermissions & file access
.claude/ config.claude --add-dir ../apps ../lib"Bash(git log *)" "Read""Bash(rm *)" "Edit"--permission-mode bypassPermissions.Shift+Tab cycle without starting in it.Prompt & subagents
--append-system-prompt "Always use TypeScript"--append-system-prompt-file ./extra-rules.txtprompt).--agents '{"reviewer":{...}}'Speed & scripting
claude --bare -p "query"-p.claude --bg "investigate the flaky test"agents, auth status, ultrareview): machine-readable output for scripting.claude agents --jsonDebug & diagnostics
"api,mcp" or "!statsig".claude --debug "api,mcp"claude --debug-file /tmp/claude-debug.logclaude --disable-slash-commandsTooling & integrations
opus, sonnet, or fable. (v2.1.98+)claude --advisor opusclaude --betas interleaved-thinkingclaude --chromeclaude --cloud "Fix the login bug"claude --ax-screen-readerDeep 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.
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.
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 goal | Stop permission-prompt fatigue | Fast, clean, isolated script runs |
| Interactive UI | Yes — standard TTY terminal | No — one-shot execution |
| Prompts / approvals | Bypassed — 100% autonomous | Active — still needs approvals |
| Auth source | System Keychain / web OAuth | ANTHROPIC_API_KEY env var |
| Reads project context | Yes — CLAUDE.md & history | No — clean slate |
| Speeds up startup | No | Yes — 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, plussetup-tokenfor CI. - **Anything risky starts with
--dangerously-…** (e.g.--dangerously-skip-permissions). Easy to spot in scripts and reviews. - Headless recipe:
claude -p "…" --output-format jsonfor scripts; add--bareto 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.
Independent study notes. Consult the official documentation for current product behavior and exam requirements.
About this guide & our sources ↗