Headless mode lets you run Claude Code without an interactive terminal session. PassDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/instructkr/claude-code/llms.txt
Use this file to discover all available pages before exploring further.
--print (or -p) and Claude outputs its response to stdout then exits — no UI, no prompts, no spinner.
Basic usage
The workspace trust dialog is skipped when using
-p. Only run Claude Code with --print in directories you trust.Output formats
Control how Claude’s response is serialised with--output-format. This flag only takes effect when --print is also set.
JSON output structure
With--output-format json, Claude Code writes a single JSON object to stdout after the run completes:
subtype is one of error_during_execution, error_max_turns, or error_max_budget_usd, and an errors array is included.
stream-json event stream
With--output-format stream-json, Claude Code emits newline-delimited JSON events as they happen:
--include-partial-messages to also receive partial assistant message chunks as they stream in.
Tool control
--allowedTools
Restrict which tools Claude can use. Accepts a space- or comma-separated list. Supports permission rule syntax.
--disallowedTools
Block specific tools entirely.
--tools
Specify the complete set of built-in tools available. Use "" to disable all tools, "default" to restore the full set.
Model and limits
MCP servers
Load MCP server configuration for a headless run with--mcp-config. Accepts one or more JSON file paths or inline JSON strings.
Using in scripts
Using in CI pipelines
Additional flags
| Flag | Description |
|---|---|
--system-prompt <text> | Override the system prompt |
--append-system-prompt <text> | Append to the default system prompt |
--permission-mode <mode> | Set permission mode: default, acceptEdits, plan, bypassPermissions, or dontAsk |
--no-session-persistence | Disable saving the session to disk |
--session-id <uuid> | Use a specific session UUID |
-c, --continue | Continue the most recent session in the current directory |
-r, --resume <id> | Resume a specific session by ID |
--settings <file-or-json> | Load additional settings from a file or inline JSON |
--add-dir <directories...> | Grant tool access to additional directories |
--bare | Minimal mode — skip hooks, LSP, plugins, keychain reads, and CLAUDE.md discovery |