Claude Code CLI flags and commands: the full reference
The claude command starts a session; flags change how it starts. The ones you will use most are -c to continue the last conversation, -r to pick an older one, -p to answer once and exit (for scripts), --model to choose the model, --permission-mode to start in plan or another mode, and -w to work in a separate Git worktree.
Daily use
Take this page into your AI
Open in ChatGPT (new tab)Open in Claude (new tab)Everything starts with claude. Typed alone in a folder it opens an interactive session there. Flags after it change how that session starts, and a few words after it, such as claude update, run a separate job and exit.
Flags apply to one session. To make a choice stick, such as a default model or a permission rule, put it in a settings file instead. A flag overrides the settings for that session.
The flags you will use every day
claude -c # carry on with the last conversation here
claude -r # pick an older conversation from a list
claude -r billing-bug # reopen the one you named billing-bug
claude -n billing-bug # start one and give it that name
claude --model opus # start with a particular model
claude --permission-mode plan # start in plan mode: read and propose, no edits
claude -w fix-header # work in a separate Git worktree
-w is worth knowing early. It creates a Git worktree under .claude/worktrees/, a second checkout of the same repository on its own branch, and starts the session inside it. 2 sessions in 2 worktrees can edit at the same time without touching each other's files.
One-off and scripted runs
-p (print) is the flag that turns Claude Code into a command-line tool. It runs the task, prints the answer and exits:
claude -p "summarize what changed in the last 5 commits"
git diff main | claude -p "write a pull request description for this diff"
claude -p "list every TODO in src/ as JSON" --output-format json
Several flags only work with -p, because they only make sense when no one is watching: --max-turns and --max-budget-usd stop a run that goes on too long, --output-format json returns the result with its cost and session id, and --json-schema makes the answer match a shape your script can read. Scripts and CI covers these runs in full.
Permissions from the command line
You can set what a session may do as you start it:
claude --allowedTools "Bash(npm test *)" "Bash(git diff *)" "Read"
claude --disallowedTools "Bash(git push *)" "WebFetch"
--allowedTools lets matching calls run without asking. --disallowedTools blocks them. --tools goes further and decides which built-in tools exist at all.
--dangerously-skip-permissions turns every permission prompt off. The name is the warning: use it only on a machine or container you can throw away, never on your own laptop with your keys and your production access. Permissions explains the safer options.
Adding to Claude Code's instructions
--append-system-prompt "..." adds text to the end of the instructions Claude Code gives the model, and --append-system-prompt-file does the same from a file. Use them for rules that belong to one run, such as a reply language or an output format.
--system-prompt replaces those instructions entirely, including the guidance on using tools safely. Keep it for agents that are not coding assistants, such as a script that sorts support tickets. For rules your whole project follows, CLAUDE.md is the better place.
Commands that do not start a session
claude update installs the latest version, claude doctor checks your install, and claude auth status tells a script whether it is signed in. claude mcp add connects MCP servers and claude plugin install adds plugins. claude setup-token makes a long-lived token for CI.
Mistype one and Claude Code suggests the closest match instead of starting a session: claude udpate asks whether you meant claude update.
Every flag and command
Search by name or by job, such as "resume", "budget" or "worktree". claude --help leaves some flags out, so this list is longer than what it prints.
105 flags and commands
claudeStartStarts an interactive session in the current folder. Put a task in quotes after it to start with that message.
claude "explain how the build works"
--continue, -cStartReopens the most recent conversation in this folder.
claude -c
--resume, -rStartReopens a conversation by its name or id, or shows a list to pick from. Add a message to send it straight away.
claude -r auth-refactor "finish the tests"
--fork-sessionStartWith --resume or --continue, copies the conversation into a new session instead of adding to the old one.
claude -r auth-refactor --fork-session
--name, -nStartNames the session, so claude --resume can find it by that name.
claude -n "billing-bug"
--session-idStartUses a session id you choose, which must be a UUID.
claude --session-id "550e8400-e29b-41d4-a716-446655440000"
--from-prStartLists only the sessions linked to a pull request, by number or link.
claude --from-pr 123
--worktree, -wStartStarts in a separate Git worktree under .claude/worktrees/, so this session's edits do not collide with another's. Pass a pull request number to branch from it.
claude -w feature-auth
--tmuxStartWith --worktree, opens the session in its own tmux session or iTerm2 pane.
claude -w feature-auth --tmux
--add-dirStartLets Claude read and edit files in more folders than the one you started in.
claude --add-dir ../shared ../docs
--bg, --backgroundStartStarts the session in the background and returns at once, printing its id. Watch it with claude agents.
claude --bg "investigate the flaky test"
--execStartWith --bg, runs a shell command as a background job instead of a Claude session.
claude --bg --exec 'pytest -x'
--version, -vStartPrints the version.
claude -v
--modelModelSets the model for this session, by alias (sonnet, opus, haiku, fable) or full name.
claude --model opus
--effortModelSets how much the model reasons for this session, from low to max. Not saved.
claude --effort high
--fallback-modelModelNames models to switch to, in order, if the main one is overloaded or gone.
claude --fallback-model sonnet,haiku
--advisorModelGives the session a second model to ask for advice at hard moments.
claude --advisor opus
--autocompactModelSets how full the context window gets before it compacts, for this session only.
claude --autocompact 500k
--betasModelAdds beta headers to API requests. API key users only.
claude --betas interleaved-thinking
--permission-modePermissionsStarts in a permission mode - default (Manual), acceptEdits, plan, auto, dontAsk or bypassPermissions.
claude --permission-mode plan
--allowedToolsPermissionsTools, or patterns of them, that run without asking. Quote each rule.
claude --allowedTools "Bash(npm test *)" "Read"
--disallowedToolsPermissionsDeny rules. A bare tool name removes the tool; a pattern such as "Bash(rm *)" blocks only matching calls.
claude --disallowedTools "Bash(git push *)"
--toolsPermissionsLimits which built-in tools exist at all. "" for none, "default" for the usual set, or a list.
claude --tools "Read,Edit,Bash"
--dangerously-skip-permissionsPermissionsSkips permission prompts, the same as --permission-mode bypassPermissions. Only for isolated machines or containers.
claude --dangerously-skip-permissions
--allow-dangerously-skip-permissionsPermissionsAdds bypassPermissions to the Shift+Tab cycle without starting in it.
claude --permission-mode plan --allow-dangerously-skip-permissions
--permission-prompt-toolPermissionsIn a script, sends permission questions to an MCP tool of yours to answer.
claude -p --permission-prompt-tool mcp_auth_tool "query"
--permission-promptsPermissionsIn a script, none denies every permission question when nobody is there to answer.
claude -p --permission-prompts none "query"
--restrictedPermissionsRestricted mode for test harnesses on shared machines - no tools that run commands or code, file tools kept to the working folders, and no user or project settings.
claude --restricted -p "query"
--print, -pScriptsAnswers once and exits, with no interactive session. The basis of every script and CI job. Pipe text in to give it input.
cat error.log | claude -p "explain this error"
--output-formatScriptsWith -p, prints text, json (one object with the result, cost and session id) or stream-json (one event per line).
claude -p "list the API routes" --output-format json
--input-formatScriptsWith -p, reads input as text or as a stream of JSON messages.
claude -p --input-format stream-json --output-format stream-json
--json-schemaScriptsWith -p, returns JSON that matches the schema you give, checked when the task ends.
claude -p --json-schema '{"type":"object"}' "summarize the diff"
--max-turnsScriptsWith -p, stops after this many agent turns and exits with an error.
claude -p --max-turns 5 "fix the lint errors"
--max-budget-usdScriptsWith -p, stops once the estimated spend reaches this many dollars. The estimate can differ from your bill, so leave room.
claude -p --max-budget-usd 2 "review this PR"
--no-session-persistenceScriptsWith -p, does not save the session, so it cannot be resumed.
claude -p --no-session-persistence "query"
--bareScriptsSkips loading hooks, skills, plugins, MCP servers, memory and CLAUDE.md, so scripted runs start faster and behave the same on every machine.
claude --bare -p "query"
--verboseScriptsShows the full output of every turn. Needed with -p and stream-json.
claude -p --output-format stream-json --verbose "query"
--include-partial-messagesScriptsWith stream-json, also sends the answer as it is written, piece by piece.
claude -p --output-format stream-json --verbose --include-partial-messages "query"
--include-hook-eventsScriptsWith stream-json, also reports when hooks start and finish.
claude -p --output-format stream-json --verbose --include-hook-events "query"
--forward-subagent-textScriptsWith stream-json, includes what subagents write, so each one's transcript can be rebuilt.
claude -p --output-format stream-json --verbose --forward-subagent-text "query"
--replay-user-messagesScriptsWith stream-json in and out, echoes each message it receives back on its output.
claude -p --input-format stream-json --output-format stream-json --verbose --replay-user-messages
--prompt-suggestionsScriptsWith stream-json, adds a guess at your next prompt after each turn.
claude -p --prompt-suggestions --output-format stream-json --verbose "query"
--exclude-dynamic-system-prompt-sectionsScriptsMoves per-user details out of the system prompt so the same job run by many users shares the prompt cache.
claude -p --exclude-dynamic-system-prompt-sections "query"
--initScriptsWith -p, runs your Setup hooks with the init matcher before the task.
claude -p --init "query"
--init-onlyScriptsRuns the Setup and SessionStart hooks, then exits.
claude --init-only
--maintenanceScriptsWith -p, runs your Setup hooks with the maintenance matcher before the task.
claude -p --maintenance "query"
--append-system-promptPromptAdds your text to the end of Claude Code's own instructions, keeping them.
claude --append-system-prompt "Answer in British English"
--append-system-prompt-filePromptAdds the contents of a file to the end of Claude Code's own instructions.
claude --append-system-prompt-file ./style.md
--system-promptPromptReplaces Claude Code's instructions entirely, including its guidance on tools and safety. For agents that are not coding assistants.
claude -p --system-prompt "You sort support tickets" "query"
--system-prompt-filePromptReplaces Claude Code's instructions with the contents of a file.
claude --system-prompt-file ./prompts/triage.txt
--system-prompt-snapshotPromptoff rebuilds the system prompt on every request instead of keeping the one the conversation started with, useful while you tune it.
claude --system-prompt-snapshot off
--append-subagent-system-promptPromptWith -p, adds your text to every subagent's instructions.
claude -p --append-subagent-system-prompt "Cite file paths" "query"
--append-subagent-system-prompt-filePromptWith -p, adds a file's contents to every subagent's instructions.
claude -p --append-subagent-system-prompt-file ./subagent-rules.txt "query"
--settingsExtendLoads settings from a file or a JSON string for this session, on top of your settings files.
claude --settings ./ci-settings.json
--setting-sourcesExtendChooses which settings files load - user, project, local.
claude --setting-sources user,project
--mcp-configExtendLoads MCP servers from JSON files or strings.
claude --mcp-config ./mcp.json
--strict-mcp-configExtendUses only the MCP servers from --mcp-config and ignores all others.
claude --strict-mcp-config --mcp-config ./mcp.json
--agentExtendRuns the session as one of your subagents, with its instructions and tools.
claude --agent code-reviewer
--agentsExtendDefines subagents for this session as JSON.
claude --agents '{"reviewer":{"description":"Reviews code","prompt":"You review code for bugs"}}'
--plugin-dirExtendLoads a plugin from a folder or .zip for this session only. Repeat it for more.
claude --plugin-dir ./my-plugin
--plugin-urlExtendDownloads a plugin .zip from a link for this session only.
claude --plugin-url https://example.com/plugin.zip
--disable-slash-commandsExtendTurns off all skills and commands for this session.
claude --disable-slash-commands
--safe-modeExtendStarts with every customization off - CLAUDE.md, skills, plugins, hooks, MCP servers, memory - to find out whether one of them is causing a problem.
claude --safe-mode
--chromeExtendTurns on Claude in Chrome for browser tasks.
claude --chrome
--no-chromeExtendTurns off Claude in Chrome for this session.
claude --no-chrome
--ideExtendConnects to your code editor at start, if exactly one is found.
claude --ide
--channelsExtendListens for messages pushed by channel plugins, such as a chat app or your own server. Research preview.
claude --channels plugin:my-notifier@my-marketplace
--dangerously-load-development-channelsExtendAllows channels that are not on the approved list, for testing your own.
claude --dangerously-load-development-channels server:webhook
--teammate-modeExtendSets how agent team members are shown - in-process, auto, tmux or iterm2.
claude --teammate-mode tmux
--cloudCloudStarts a new session in the cloud with the task you give, or sends a message to an existing cloud session.
claude --cloud "fix the login bug"
--teleportCloudBrings a cloud session into your terminal.
claude --teleport
--remote-control, --rcCloudStarts a session you can also drive from claude.ai or the Claude app.
claude --rc "my project"
--remote-control-session-name-prefixCloudSets the start of automatic Remote Control session names, which is otherwise your computer's name.
claude remote-control --remote-control-session-name-prefix dev-box
--environmentCloudStarts a cloud session on your organization's own self-hosted environment.
claude -p "run the smoke test" --environment ccpool_abc123
--refCloudWith --environment, starts the cloud session from a named branch instead of your current commit.
claude -p "run the smoke test" --environment ccpool_abc123 --ref main
--desktopCloudOpens the Claude desktop app on this folder, or on a session with --continue or --resume.
claude --desktop --continue
--debugDebugTurns on debug logging, optionally for some areas only.
claude --debug='mcp,startup'
--debug-fileDebugWrites the debug log to a file you name.
claude --debug-file /tmp/claude-debug.log
--ax-screen-readerDebugPlain output for screen readers, with no borders or animation.
claude --ax-screen-reader
claude updateSubcommandsInstalls the newest version now.
claude update
claude installSubcommandsInstalls or reinstalls the program, at a version, stable or latest.
claude install stable
claude doctorSubcommandsChecks the install and your settings files without starting a session.
claude doctor
claude auth loginSubcommandsSigns in. --console bills a Console account instead of a Claude plan; --sso forces single sign-on.
claude auth login --console
claude auth logoutSubcommandsSigns out.
claude auth logout
claude auth statusSubcommandsShows how you are signed in, as JSON, and exits with 0 if you are and 1 if not. --text for plain words.
claude auth status --text
claude setup-tokenSubcommandsMakes a long-lived sign-in token for CI and scripts, printed once and not saved. Needs a Claude plan.
claude setup-token
claude mcpSubcommandsAdds, lists and removes MCP servers.
claude mcp add --transport http notion https://mcp.notion.com/mcp
claude mcp loginSubcommandsSigns in to an MCP server that needs it, without opening /mcp. --no-browser prints the link instead, for SSH.
claude mcp login sentry
claude mcp logoutSubcommandsRemoves an MCP server's saved sign-in.
claude mcp logout sentry
claude pluginSubcommandsInstalls, lists and manages plugins. Also claude plugins.
claude plugin install code-review@claude-plugins-official
claude agentsSubcommandsOpens agent view, to start and watch sessions running in the background. --json lists them for scripts.
claude agents
claude attachSubcommandsJoins a background session in this terminal.
claude attach 7c5dcf5d
claude logsSubcommandsPrints the latest output of a background session.
claude logs 7c5dcf5d
claude stopSubcommandsStops a background session. Also claude kill.
claude stop 7c5dcf5d
claude respawnSubcommandsRestarts a background session with its conversation, for example to pick up a new version. --all for every one.
claude respawn --all
claude rmSubcommandsRemoves a background session from the list. Its transcript stays on your machine.
claude rm 7c5dcf5d
claude daemonSubcommandsLooks after the process that hosts background sessions - logs, run, status and stop.
claude daemon status
claude remote-controlSubcommandsRuns a server so you can start and drive sessions on this machine from claude.ai or the Claude app.
claude remote-control --name "work laptop"
claude importSubcommandsBrings settings, instructions, MCP servers and skills over from OpenAI Codex, Gemini CLI or Cursor.
claude import codex --dry-run
claude purgeSubcommandsDeletes everything Claude Code stored locally for a project - transcripts, edit history, prompt history. --dry-run previews.
claude purge ~/work/repo --dry-run
claude auto-mode defaultsSubcommandsPrints the rules auto mode's safety check uses, as JSON. claude auto-mode config shows yours with your settings applied.
claude auto-mode defaults
claude auto-mode resetSubcommandsRemoves your own auto mode rules from your user settings, back to the defaults.
claude auto-mode reset
claude ultrareviewSubcommandsRuns the deep cloud code review from a script and prints the findings. --post adds them to a GitHub pull request.
claude ultrareview 1234 --json
claude gatewaySubcommandsRuns a self-hosted gateway that signs a company's developers in and sends their requests to Bedrock, Google Cloud or Foundry. For administrators.
claude gateway --config gateway.yaml
claude self-hosted-runnerSubcommandsRegisters this machine to run your organization's cloud sessions on its own infrastructure.
claude self-hosted-runner setup
Questions
- What does claude -p do?
- It runs Claude Code once without the interactive screen. It takes your prompt, works through the task, prints the result and exits. It is how you use Claude Code in scripts, Git hooks and CI. Pipe text into it to give it input, as in cat error.log | claude -p "explain this".
- What is the difference between claude -c and claude -r?
- claude -c reopens the most recent conversation in the current folder with no questions. claude -r reopens a particular one, by name or id, or shows a list to choose from when you give neither.
- Should I use --system-prompt or --append-system-prompt?
- Almost always --append-system-prompt. It adds your rules and keeps Claude Code's own instructions, including how to use its tools safely. --system-prompt replaces all of them, which only makes sense for an agent that is not meant to be a coding assistant.
- Why does claude --help not show every flag?
- The help text leaves some flags out. A flag missing from claude --help can still work; the reference on this page lists them all.
Sources