Run Claude Code non-interactively for scripts, CI pipelines, and programmatic usage.
Headless mode lets you run Claude Code without an interactive terminal session. Pass --print (or -p) and Claude outputs its response to stdout then exits — no UI, no prompts, no spinner.
# Inline promptclaude -p "Summarise the changes in the last git commit"# Prompt as positional argumentclaude --print "List all TODO comments in src/"# Pipe from stdinecho "What does this regex match?" | claude -p
The workspace trust dialog is skipped when using -p. Only run Claude Code with --print in directories you trust.
Specify the complete set of built-in tools available. Use "" to disable all tools, "default" to restore the full set.
# Only file reading toolsclaude -p "Explain the architecture" --tools "Read,Glob,Grep"# No tools at all (pure text conversation)claude -p "What is a monad?" --tools ""
# Use a specific modelclaude -p "Write a haiku" --model claude-sonnet-4-6# Limit agentic turns (exits early after N turns)claude -p "Fix all lint errors" --max-turns 10# Cap spendclaude -p "Large refactoring task" --max-budget-usd 0.50
Load MCP server configuration for a headless run with --mcp-config. Accepts one or more JSON file paths or inline JSON strings.
# From a fileclaude -p "Query the database" --mcp-config ./mcp-servers.json# Inline JSONclaude -p "Use the custom tool" --mcp-config '{"myserver":{"type":"stdio","command":"node","args":["server.js"]}}'# Use only the servers from --mcp-config, ignoring all other MCP configclaude -p "Query the database" --mcp-config ./mcp-servers.json --strict-mcp-config