Skip to main content
NOV 2026 Latest guide updates. Latest: AI Design Patterns Local vs cloud AI Grill me Changelog →
T02 Intermediate Technical

Non-Interactive & Headless Mode

Using Claude Code without human interaction: scripts, CI, pipes

PDF editions Β· Guide v3.44.1 Β· Updated

Base flag: -p

The -p flag (or --print) activates non-interactive mode. Claude returns the response in the terminal and exits immediately without waiting for user input.

Terminal window
# Direct prompt
claude -p "Analyze this file and list the bugs"
# With pipe stdin (content becomes the input)
git diff | claude -p "Explain these changes"
cat error.log | claude -p "Identify the root cause"

Output formats

--output-format controls the response structure, which is essential for integration into scripts.

FormatUsage
textHuman-readable, default
jsonParseable by jq
stream-jsonReal-time streaming
Terminal window
# JSON output for automatic parsing
git status --short | claude -p "Categorize the changes" \
--output-format json | jq -r '.result'
# Stream JSON for long operations
cat report.txt | claude -p "Summarize" --output-format stream-json --verbose

Flow control in pipes

In print mode, claude -p waits for the complete response and writes it to stdout in a single block, which simplifies pipes with tools that expect complete input. Real-time streaming is opt-in via --output-format stream-json.

Terminal window
claude -p "Generate a report" > report.md

CI/CD usage

In an isolated container, --dangerously-skip-permissions suppresses all confirmation requests. Reserve exclusively for sandboxed environments where Claude cannot access sensitive resources.

Terminal window
# GitHub Actions (isolated container)
claude -p "Run the tests and fix failures" \
--dangerously-skip-permissions \
--output-format json

Common patterns

Terminal window
# Automated log analysis
tail -n 200 app.log | claude -p "Critical alerts only" \
--output-format json
# PR review (package.json integration)
git diff main...HEAD | claude -p "Security review, JSON format" \
--output-format json > review.json

Interactive vs non-interactive

AspectInteractiveNon-Interactive (-p)
OutputStream UIRaw stdout
PermissionsPrompts or saved rulesConfigure allow rules or a bounded permission mode
UsageDevelopmentCI, scripts, pipes
SessionPersistentSaved by default; can continue or resume

Best practice: limit pipe size to avoid exceeding the context window. Filter with head, grep or --name-only before sending to Claude.