The Claude Code CLI: every flag and command that matters

Most people use Claude Code as an interactive REPL and never discover that the same binary is a perfectly good Unix filter, a background job runner, and a worktree manager. The flags below are where the second half of the tool lives.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

Running claude starts an interactive session in the current directory. claude -p "..." runs one prompt and exits, and with --output-format json returns a result object carrying result, session_id, total_cost_usd, usage, num_turns, and duration_ms. -c continues the last session, -r resumes one by id or name, -w starts in an isolated git worktree, and --bg starts a background agent you reattach to later. This page is the working subset, current as of August 2026.

What you need to know
  • claude -p "..." runs one prompt and exits. This is the scripting entry point.
  • --output-format json returns cost, token usage, turn count, and a session id.
  • -c continues the last session; -r <id-or-name> resumes a specific one.
  • -w <name> starts the session in its own git worktree, isolated from the main checkout.
  • --bg runs the session in the background; claude agents, attach, and logs manage it.
  • --bare skips discovery of hooks, skills, plugins, MCP, and CLAUDE.md. Use it in CI.

The forms you will actually use

Nine of these cover almost everything.

CommandDoes
claudeInteractive session in the current directory
claude "fix the failing test"Interactive, with an opening prompt
claude -p "summarise this repo"One-shot: print the answer and exit
cat err.log | claude -p "explain"Read from stdin, capped at 10MB
claude -cContinue the most recent conversation in this directory
claude -r "auth-refactor" "finish it"Resume a session by id or name
claude -w feature-authStart in an isolated git worktree
claude updateUpdate to the newest version now
claude doctorRead-only install and settings diagnostics
claude mcpManage MCP servers
claude setup-tokenGenerate a long-lived OAuth token for CI and scripts

The background-session verbs

This is the half of the CLI that most people never find. --bg starts a session as a background agent and returns immediately; a supervisor process hosts it, and a separate set of commands manages the fleet.

CommandDoes
claude --bg "investigate the flaky test"Start a background agent and return straight away
claude --bg --exec 'pytest -x'Run a shell command as a PTY-backed background job, no agent
claude agentsOpen the agent view to monitor and dispatch background sessions
claude agents --jsonThe same, machine-readable
claude attach 7c5dcf5dAttach to a background session in this terminal
claude logs 7c5dcf5dPrint recent output from a background session
claude respawn 7c5dcf5dRestart a background session with its conversation intact
claude stop 7c5dcf5dStop it (alias claude kill)
claude rm 7c5dcf5dRemove it from the list
claude daemon statusPrint the background-session supervisor state

The flags, grouped by what they control

Sessions and continuity

FlagEffect
-c, --continueLoad the most recent conversation in this directory
-r, --resumeResume by session id or name, or show an interactive picker
--fork-sessionOn resume, create a new session id instead of reusing the original
--session-idUse a specific session id (must be a valid UUID)
-n, --nameGive the session a display name, shown in /resume and the terminal title
--no-session-persistenceDo not write the session to disk
-w, --worktreeCreate an isolated worktree and start there
--tmuxCreate a tmux session for the worktree (requires --worktree)

Model, effort, and thinking

FlagEffect
--modelAlias (sonnet, opus, haiku, fable) or a full model id
--effortlow, medium, high, xhigh, max, or ultracode
--fallback-modelFall back automatically when the primary model is overloaded
--advisorEnable the server-side advisor tool with a model alias or id
--autocompactSet the auto-compact window for this session

Permissions, tools, and directories

FlagEffect
--permission-modeStart in a named mode; see the table below
--allowedToolsTools that execute without prompting, using permission-rule syntax
--disallowedToolsDeny rules; a bare name removes the tool entirely
--toolsRestrict which built-in tools Claude can use at all
--add-dirGrant read and edit access to additional directories
--dangerously-skip-permissionsEquivalent to --permission-mode bypassPermissions
--permission-prompt-toolAn MCP tool that answers permission prompts non-interactively

Output and scripting

FlagEffect
-p, --printNon-interactive: answer and exit
--output-formattext, json, or stream-json
--input-formattext or stream-json
--json-schemaValidate the final answer against a JSON Schema, returned in structured_output
--include-partial-messagesEmit token-level deltas (needs -p and stream-json)
--forward-subagent-textEmit subagent text and thinking blocks into the stream
--max-turnsCap the number of agentic turns (print mode only)
--max-budget-usdStop after this much API spend (print mode only)
--verboseFull turn-by-turn output

Configuration and startup

FlagEffect
--bareSkip discovery of hooks, skills, plugins, MCP servers, auto memory, and CLAUDE.md
--settingsA settings file path, or an inline JSON string
--setting-sourcesWhich of user, project, local to load
--mcp-configLoad MCP servers from JSON files or strings
--strict-mcp-configUse only the servers from --mcp-config
--agentsDefine custom subagents inline as JSON
--append-system-promptAppend text to the default system prompt
--system-promptReplace the system prompt entirely
--safe-modeStart with all customizations disabled, to isolate a broken config
--debugDebug output, with optional category filtering

Permission modes

The values --permission-mode accepts, and what each is for.

ModeBehaviourUse for
defaultPrompts before each consequential action (shown as Manual in the mode indicator)Normal interactive work
planReads and analyses only; proposes a plan and edits nothingAnything large or unfamiliar
acceptEditsWrites files without prompting, and auto-approves mkdir, touch, mv, cpTrusted, well-scoped tasks
autoA classifier decides which actions still need youReducing prompt fatigue without going open loop
dontAskDenies anything outside your allow rules and the read-only command setLocked-down CI runs
bypassPermissionsNo prompts at allContainers and disposable VMs only

Plan mode is the one that repays learning. Agreeing an approach before any file changes prevents the expensive failure, which is a long confident run in the wrong direction that you then have to unwind. <kbd>Shift</kbd>+<kbd>Tab</kbd> cycles modes mid-session, so you can drop into plan the moment a task turns out bigger than you thought.

Worktree sessions from the CLI

Running two agents in one checkout means they overwrite each other. -w makes that structurally impossible without you managing git by hand.

One command per isolated session.
claude -w feature-auth
claude -w bugfix-login     # in another terminal

# from a pull request; quote it so the shell does not eat the #
claude --worktree "#1234"

# with its own tmux session
claude -w feature-auth --tmux

By default the worktree is created under .claude/worktrees/<name>/ at your repository root, on a branch named worktree-<name>, branched from the repository default branch. Omit the name and Claude Code generates one. Add .claude/worktrees/ to your .gitignore.

Questions people ask

Use claude -p "your prompt", which answers and exits. Add --output-format json for a machine-readable result carrying the answer, the session id, token usage, and total_cost_usd. Add --bare in CI so the run does not pick up local hooks, plugins, or CLAUDE.md.

claude -c continues the most recent conversation in the current directory. claude -r resumes a specific one by session id or by the name you gave it with -n, or shows an interactive picker if you pass nothing.

Yes, in print mode. Piping works as you would expect, which is what makes patterns like npm test 2>&1 | claude -p "why did this fail?" useful. Piped stdin is capped at 10MB; beyond that, write a file and reference its path.

Pass --model with an alias such as sonnet or opus, or a full model id. It applies to that invocation only. --effort sets the reasoning level separately, from low through max.

It prints read-only installation and settings diagnostics without starting a session: install health, PATH, settings-file validation errors, the result of the last update attempt, and suggested fixes. Run it before concluding anything is broken.

Give each one its own git worktree with claude -w name. Claude Code creates it under .claude/worktrees/, and then actively blocks that session from editing the main checkout, running commands there, or redirecting git into it.

--print runs one prompt in the foreground and exits with the answer. --bg starts a full session as a background agent and returns immediately, and you manage it afterwards with claude agents, claude attach, claude logs, and claude stop.

Inside a container or disposable VM, yes, because the sandbox is the boundary. On your own machine it lets the agent run any command without asking. If you want fewer prompts without that trade, use the sandboxed Bash tool or --permission-mode auto instead.

Sources

Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.

  1. Claude Code CLI reference
  2. Run Claude Code programmatically
  3. Run parallel sessions with worktrees
  4. Agent SDK TypeScript reference
Try it

The flags,
as controls.

Continuum surfaces model, effort, and mode as chips per session, switchable mid-run, across every agent it drives.

free app · your subscriptions · local-first