claude -p "prompt" is the only way to run Claude Code non-interactively. Without -p, Claude enters interactive mode and waits for terminal input. In CI, there is no terminal. The process hangs silently until the timeout kills it with exit code 137.
This is the single most common CI integration failure. No output, no error message, just a hang.
The Command Pattern
# Text output (PR comments, logs)
claude -p "Review this PR for security vulnerabilities"
# Structured JSON output (dashboards, APIs)
claude -p "Extract code metrics" --output-format json
# Captured to file
claude -p "Analyze code quality" --output-format json > results.json
-p handles non-interactive execution. --output-format json handles structured output. Stdout captures the result. These three pieces compose for any CI integration.
Diagnosing Missing -p
A CI pipeline with these symptoms is almost certainly missing -p:
| Symptom | Cause |
|---|---|
| No output at all | Claude waiting for interactive input |
| Silent hang until timeout | No terminal in CI |
| Exit code 137 | Killed by timeout after hanging |
| Works locally, fails in CI | Local terminal provides interactive input |
One team’s logs showed: 7 successful runs with claude -p "..." completing in 30-90 seconds, and 3 failures with claude "..." (no -p) timing out at 300 seconds. The failures started after a CI config update that accidentally removed the -p flag from some commands.
Things That Do Not Exist
Every alternative to -p that teams try is fictional:
--batchflag — Does not exist. There is no batch mode.CLAUDE_HEADLESS=true— Not a real environment variable.CLAUDE_CI=true— Not a real environment variable.--no-interactive— Not a real flag.--stdin— Not a real flag.CLAUDE_OUTPUT_FORMAT=json— Not a real environment variable. Use--output-format json.--format json— Not the correct flag. It is--output-format json.
Non-interactive mode is controlled exclusively through the -p command-line flag. Not environment variables, not stdin redirection, not any other flag.
Piping Does Not Replace -p
echo "analyze code" | claude > output.txt does not guarantee non-interactive mode. Without -p, Claude may still attempt interactive behavior regardless of piped input. Always use the explicit -p flag.
Argument Order
The standard pattern is claude -p "prompt". One team experienced intermittent failures after refactoring their CI config from:
# Before (working)
claude -p "Review support flows" > review.txt
# After (intermittent failures)
claude "Review support flows" -p > review.txt
Moving -p after the prompt string caused argument parsing confusion in some runs. Keep the prompt immediately after -p.
Multi-Stage Pipelines
Different CI stages can use different output formats while all sharing -p for non-interactive execution:
# Stage 1: text for PR comment
claude -p "Review code for issues" > review.txt
# Stage 2: JSON for dashboard
claude -p "Extract quality metrics" --output-format json > metrics.json
Both stages use -p. The output format flag varies per stage’s needs. Do not combine both prompts into one call if they need different output formats.
CLAUDE.md Provides CI Context Automatically
CLAUDE.md loads for every claude -p call just as it does for interactive sessions. Project review criteria, coding standards, and review guidelines all apply automatically in CI without extra configuration. This ensures CI-invoked Claude has the same context as a developer running Claude locally.
One-liner: claude -p "prompt" is the only non-interactive mode — without it, CI jobs hang silently until timeout kills them, producing the most common integration failure.