Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Claude Code CLI Reference Manual

Claude Code CLI Reference Manual


I. CLI Commands

Command Description Example
claude Start an interactive REPL claude
claude "query" Start a REPL with an initial prompt claude "explain this project"
claude -p "query" Query via SDK and then exit claude -p "explain this function"
cat file | claude -p "query" Process piped input cat logs.txt | claude -p "explain"
claude -c Continue the most recent conversation in the current directory claude -c
claude -c -p "query" Continue a conversation via SDK claude -c -p "Check for type errors"
claude -r "" "query" Resume a session by ID/name claude -r "auth-refactor" "Finish this PR"
claude update Update to the latest version claude update
claude mcp Configure MCP servers See details in Claude Code MCP documentation

II. CLI Flags

The following flags can be used to customize Claude Code's runtime behavior:

Flag Description Example
--add-dir Add a working directory (path validity is verified automatically) claude --add-dir ../apps ../lib
--agent Specify a session agent (overrides the default agent setting) claude --agent my-custom-agent
--agents Define custom subagents in JSON claude --agents '{"reviewer":{"description":"Reviews code","prompt":"You are a code reviewer"}}'
--allowedTools Available tools that skip permission prompts (limit the tools used by --tools) "Bash(git log:*)" "Bash(git diff:*)" "Read"
--append-system-prompt Append content to the default system prompt (applies in both interactive and print modes) claude --append-system-prompt "Always use TypeScript"
--betas Attach beta headers to API requests (API key users only) claude --betas interleaved-thinking
--chrome Enable Chrome browser integration (web automation/testing) claude --chrome
--continue, -c Load the most recent conversation in the current directory claude --continue
--dangerously-skip-permissions Skip permission prompts (use with caution) claude --dangerously-skip-permissions
--debug Enable debug mode, with category filtering support (e.g. "api,hooks") claude --debug "api,mcp"
--disallowedTools Disable specified tools (removed from context) "Bash(git log:*)" "Bash(git diff:*)" "Edit"
--fallback-model Automatically switch when the default model is overloaded (print mode only) claude -p --fallback-model sonnet "query"
--fork-session Generate a new ID when resuming a session (used with --resume/--continue) claude --resume abc123 --fork-session
--ide Automatically connect to an available IDE claude --ide
--include-partial-messages Output includes partial streaming events (requires use with --print and --output-format=stream-json) claude -p --output-format stream-json --include-partial-messages "query"
--input-format Print mode input format (optional text/stream-json) claude -p --output-format json --input-format stream-json
--json-schema Output validation results conforming to JSON Schema (print mode only) claude -p --json-schema '{"type":"object","properties":{...}}' "query"
--max-turns Limit agent turns (print mode only; exits with an error when exceeded) claude -p --max-turns 3 "query"
--mcp-config Load MCP configuration from a JSON file/string claude --mcp-config ./mcp.json
--model Specify the session model (supports aliases sonnet/opus or full names) claude --model claude-sonnet-4-5-20250929
--no-chrome Disable Chrome integration claude --no-chrome
--output-format Print mode output format (optional text/json/stream-json) claude -p "query" --output-format json
--permission-mode Start with a specified permission mode claude --permission-mode plan
--permission-prompt-tool Specify a tool for handling permission prompts in non-interactive mode claude -p --permission-prompt-tool mcp_auth_tool "query"
--plugin-dir Load a plugin from a specified directory (can be used multiple times) claude --plugin-dir ./my-plugins
--print, -p Exit after printing the response (non-interactive mode) claude -p "query"
--resume, -r Resume a session by ID/name, or invoke an interactive selector claude --resume auth-refactor
--session-id Specify a session ID (must be a valid UUID) claude --session-id "550e8400-e29b-41d4-a716-446655440000"
--setting-sources Specify settings sources to load (comma-separated user/project/local) claude --setting-sources user,project
--settings Load a custom JSON configuration file/string claude --settings ./settings.json
--strict-mcp-config Use only --mcp-config configuration, ignoring other MCP settings claude --strict-mcp-config --mcp-config ./mcp.json
--system-prompt Replace the default system prompt (applies in both interactive and print modes) claude --system-prompt "You are a Python expert"
--system-prompt-file Load the system prompt from a file (replaces the default, print mode only) claude -p --system-prompt-file ./custom-prompt.txt "query"
--tools Limit the available built-in tools ("" disable all,"default" enable all) claude --tools "Bash,Edit,Read"
--verbose Enable verbose logging, showing complete per-turn output claude --verbose
--version, -v Output the version number claude -v

Tip:--output-format json The flag is well suited to scripting and automation scenarios, allowing Claude's response results to be parsed programmatically.


III. Additional Notes

3.1 Agent Flag Format

--agents The flag accepts a JSON object defining one or more custom subagents. Each subagent needs a unique name configured as a key, with the value being an object containing the following fields:

Field Required Description
description Is Describes the scenarios in which the subagent should be used
prompt Is The system prompt that defines the subagent's behavior
tools No A list of tools specific to the subagent (e.g. ["Read", "Edit"]; if omitted, all tools are inherited)
model No The model used by the subagent (supports sonnet/opus/haiku; if omitted, the default model is used)

Example

claude --agents '{

  "code-reviewer": {

    "description": "Expert code reviewer. Use proactively after code changes.",

    "prompt": "You are a senior code reviewer. Focus on code quality, security, and best practices.",

    "tools": ["Read", "Grep", "Glob", "Bash"],

    "model": "sonnet"

  },

  "debugger": {

    "description": "Debugging specialist for errors and test failures.",

    "prompt": "You are an expert debugger. Analyze errors, identify root causes, and provide fixes."

  }

}'

System Prompt Flags

Claude Code provides 3 ways to customize the system prompt to meet different usage needs:

Flag Behavior Applicable modes Typical use cases
--system-prompt Replace the default system prompt Interactive + print Fully customize Claude's behavior instructions
--system-prompt-file Load a prompt from a file and replace Print only Team-shared prompt templates, version control
--append-system-prompt Append content to the default prompt Interactive + print Keep default functionality while adding personalized instructions

Use cases and examples

  1. --system-prompt: fully take over the system prompt, clearing the default instructions
    claude --system-prompt "You are a Python expert who only writes type-annotated code"
  2. --system-prompt-file: read the prompt from a file, suitable for standardized scenarios
    claude -p --system-prompt-file ./prompts/code-review.txt "Review this PR"
  3. --append-system-prompt: keep default functionality while adding custom requirements (recommended for most scenarios)
    claude --append-system-prompt "Always use TypeScript and include JSDoc comments"

Note:--system-prompt and --system-prompt-file are mutually exclusive and cannot be used together.


Tip: Prefer to use --append-system-prompt, which both preserves Claude Code's built-in capabilities and meets customization needs; use the other two flags only when complete customization is needed.

Print mode (-p) details (output formats, streaming, programmatic integration, etc.), refer to SDK documentation。