TellWorldAI World Archive
Ask中文

Home›Practice›Practice

Practice

Claude Code CLI reference: commands and flags by task

A grouped cheat sheet for Claude Code's command line: starting and resuming sessions, one-off prompts in scripts, and controlling permissions, models and spend, plus what to do about flags missing from --help.

Who this is for

People who already have Claude Code installed and want to start sessions, run one-off prompts from scripts, or control permissions and models from the command line. After reading, you can pick the right flag group for a task and know where to look when a flag is not in --help.

What it is

The command-line entry point is claude. Run with no arguments, it opens an interactive session. Add -p and it sends one query, prints the response and exits, which suits scripts and pipes.[1] Flags fall into groups by purpose: starting and resuming, permissions, models, output, budget and troubleshooting.

Setup

  • Install Claude Code and confirm that claude runs in your terminal.
  • Sign in with claude auth login. Add --console to sign in through Anthropic Console for API usage billing instead of a Claude subscription.[1]
  • Check the login with claude auth status. It prints JSON by default; add --text for readable output. It exits with code 0 when you are logged in and 1 when you are not, so a script can branch on the result.[1]

Starting and resuming

  • claude starts an interactive session.[1]
  • claude "query" starts one with an initial prompt, for example claude "explain this project".[1]
  • claude -p "query" sends one query and exits.[1]
  • cat logs.txt | claude -p "explain" processes piped content.[1]
  • claude -c continues the most recent conversation in the current directory. claude -r "<session>" "query" resumes a session by ID or name.[1]

Permissions and tools

These flags decide what Claude can do without asking, so read them carefully.

  • --permission-mode starts the session in a chosen mode: default, acceptEdits, plan, auto, dontAsk, bypassPermissions or manual.[1]
  • --dangerously-skip-permissions skips permission prompts and is equivalent to --permission-mode bypassPermissions.[1]
  • --allowedTools lists tools that run without a prompt, and accepts rules such as "Bash(git log *)".[1]
  • --disallowedTools takes deny rules. A bare tool name such as Edit removes that tool from Claude's context. A scoped rule such as Bash(rm *) leaves the tool available and denies only the matching calls.[1]
  • --tools restricts the built-in tools: "" disables all of them, "default" selects the default set, and a list such as "Bash,Edit,Read" enables only the tools named.[1]

Models and effort

  • --model takes an alias such as sonnet, opus, haiku or fable, or a full model name. It overrides both the model setting and the ANTHROPIC_MODEL environment variable.[1]
  • --effort takes low, medium, high, xhigh, max or ultracode. Which levels are available depends on the model.[1]
  • --fallback-model switches to the listed models, tried in order, when the primary model is overloaded or unavailable, for example a retired model. It takes a comma-separated list, such as claude --fallback-model sonnet,haiku.[1]

Output, scripts and system prompts

  • --output-format accepts text, json or stream-json in print mode.[1]
  • --bare skips auto-discovery of hooks, skills, plugins, MCP servers, auto memory and CLAUDE.md, so scripted calls start faster.[1]
  • --system-prompt replaces the default system prompt, and --append-system-prompt adds text to the end of it.[1]
  • --mcp-config loads MCP servers from JSON files or strings. --strict-mcp-config skips servers configured elsewhere, such as .mcp.json, and loads only the ones passed with --mcp-config.[1]
  • The two append flags can be combined. In the example below, Claude receives the default system prompt, then the contents of style.md, a blank line, and then the inline instruction.[1]
claude -p --append-system-prompt-file ./style.md --append-system-prompt "Always reply in French" "Summarize README.md"

Budget

--max-budget-usd applies in print mode. It stops the run once estimated API spend reaches the amount, and spend from subagents counts toward the cap. The check uses Claude Code's client-side cost estimate, which can differ from your bill.[1]

Subcommands worth knowing

  • claude agents opens agent view to watch and dispatch parallel background sessions. It needs an interactive terminal. claude agents --json prints the active sessions as a JSON array.[1]
  • claude mcp login <name> runs an MCP server's OAuth flow. Over SSH, add --no-browser to print the authorization URL instead of opening a browser.[1]
  • claude ultrareview [target] runs ultrareview non-interactively and prints findings to stdout. --json prints the raw payload, and --timeout <minutes> overrides the 45-minute default.[1]
  • claude purge [path] deletes all local Claude Code state for a project, including transcripts and prompt history. --dry-run previews the result.[1]

Troubleshooting

  • **A flag is missing from --help:** claude --help does not list every flag, so a flag that is absent from it may still be available.[1]
  • A subcommand is mistyped: Claude Code does not run it. It suggests the closest match and exits without starting a session; claude udpate prints Did you mean claude update?.[1]
  • The install or settings look wrong: claude doctor prints read-only installation and settings diagnostics without starting a session. Inside a session, /doctor can also apply fixes.[1]
  • A customization may be breaking things: start with --safe-mode. CLAUDE.md, skills, plugins, hooks, MCP servers, custom commands and auto memory do not load, which helps isolate the cause.[1]

Next steps

For the full flag table and the Claude Code version each flag requires, use the official CLI reference.[1]

Sources

  1. 1
    CLI referenceAnthropic Claude Code docs

Cite this page: Claude Code CLI reference: commands and flags by task. TellWorld, https://www.tellworld.net/practice/practice-claude-code-cli-reference. Updated 2026-11-14

Related news

View all