YouTip LogoYouTip

Claude Code Cli Ref

* * * ## I. CLI Commands | Command | Description | Example | | --- | --- | --- | | `claude` | Start interactive REPL | `claude` | | `claude "query"` | Start REPL with initial prompt | `claude "explain this project"` | | `claude -p "query"` | Query via SDK and exit | `claude -p "explain this function"` | | cat file | claude -p "query" | Process piped input content | cat logs.txt | claude -p "explain" | | `claude -c` | Continue most recent conversation in current directory | `claude -c` | | `claude -c -p "query"` | Continue conversation via SDK | `claude -c -p "Check for type errors"` | | `claude -r "" "query"` | Resume session by ID/name | `claude -r "auth-refactor" "Finish this PR"` | | `claude update` | Update to latest version | `claude update` | | `claude mcp` | Configure MCP server | See (#) | * * * ## II. CLI Flags You can customize Claude Code behavior using the following flags: | Flag | Description | Example | | --- | --- | --- | | `--add-dir` | Add working directory (automatically validates path) | `claude --add-dir ../apps ../lib` | | `--agent` | Specify session agent (overrides default `agent` setting) | `claude --agent my-custom-agent` | | `--agents` | Define custom sub-agents in JSON | `claude --agents '{"reviewer":{"description":"Reviews code","prompt":"You are a code reviewer"}}'` | | `--allowedTools` | Available tools without permission prompts (restrict tools with `--tools`) | `"Bash(git log:*)" "Bash(git diff:*)" "Read"` | | `--append-system-prompt` | Append content to default system prompt (works 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 most recent conversation in current directory | `claude --continue` | | `--dangerously-skip-permissions` | Skip permission prompts (use with caution) | `claude --dangerously-skip-permissions` | | `--debug` | Enable debug mode with category filtering (e.g., `"api,hooks"`) | `claude --debug "api,mcp"` | | `--disallowedTools` | Disable specified tools (remove from context) | `"Bash(git log:*)" "Bash(git diff:*)" "Edit"` | | `--fallback-model` | Auto-switch when default model is overloaded (print mode only) | `claude -p --fallback-model sonnet "query"` | | `--fork-session` | Generate new ID when resuming session (used with `--resume`/`--continue`) | `claude --resume abc123 --fork-session` | | `--ide` | Auto-connect to available IDE | `claude --ide` | | `--include-partial-messages` | Output includes partial streaming events (must be used 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 error if exceeded) | `claude -p --max-turns 3 "query"` | | `--mcp-config` | Load MCP configuration from JSON file/string | `claude --mcp-config ./mcp.json` | | `--model` | Specify session model (supports aliases `sonnet`/`opus` or full name) | `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 specified permission mode | `claude --permission-mode plan` | | `--permission-prompt-tool` | Specify permission prompt handling tool in non-interactive mode | `claude -p --permission-prompt-tool mcp_auth_tool "query"` | | `--plugin-dir` | Load plugins from specified directory (can be used multiple times) | `claude --plugin-dir ./my-plugins` | | `--print`, `-p` | Print response and exit (non-interactive mode) | `claude -p "query"` | | `--resume`, `-r` | Resume session by ID/name, or invoke interactive selector | `claude --resume auth-refactor` | | `--session-id` | Specify session ID (must be valid UUID) | `claude --session-id "550e8400-e29b-41d4-a716-446655440000"` | | `--setting-sources` | Specify which setting sources to load (comma-separated `user`/`project`/`local`) | `claude --setting-sources user,project` | | `--settings` | Load custom JSON config file/string | `claude --settings ./settings.json` | | `--strict-mcp-config` | Use only `--mcp-config` settings, ignore other MCP configurations | `claude --strict-mcp-config --mcp-config ./mcp.json` | | `--system-prompt` | Replace default system prompt (works in both interactive and print modes) | `claude --system-prompt "You are a Python expert"` | | `--system-prompt-file` | Load system prompt from file (replaces default, print mode only) | `claude -p --system-prompt-file ./custom-prompt.txt "query"` | | `--tools` | Limit available built-in tools (`""` disables all, `"default"` enables all) | `claude --tools "Bash,Edit,Read"` | | `--verbose` | Enable verbose logging, showing full turn-by-turn output | `claude --verbose` | | `--version`, `-v` | Output version number | `claude -v` | > **Tip**: The `--output-format json` flag is ideal for scripts and automation, allowing direct programmatic parsing of Claude's response. * * * ## III. Extended Explanation ### 3.1 Agent Flag Format The `--agents` flag accepts a JSON object to define one or more custom sub-agents. Each sub-agent requires a unique name as the key, with the value being an object containing the following fields: | Field | Required | Description | | --- | --- | --- | | `description` | Yes | Describes the sub-agent's applicable scenarios | | `prompt` | Yes | System prompt defining sub-agent behavior | | `tools` | No | Sub-agent specific tool list (e.g., `["Read", "Edit"]`, inherits all tools if omitted) | | `model` | No | Model used by sub-agent (supports `sonnet`/`opus`/`haiku`, uses default if omitted) | **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
← Claude Code Slash CommandsClaude Code Outputstyles β†’