Headless runs
One-shot prompt
claude -p "summarize the failing tests"
Runs one prompt and exits. -p prints the answer; pipe context in through stdin. See headless mode.
Review a diff
git diff | claude -p "review this diff for bugs"
Reviews a diff from stdin. Pipes the diff as context and returns a review. See headless mode.
JSON output
claude -p "list failing tests" \
--output-format json
Emits a JSON result. Returns an envelope with result, session, and cost fields. See the CLI reference.
Pre-approve tools
claude -p "fix the lint errors" \
--allowedTools "Read,Edit,Bash"
Pre-approves tools for unattended runs. Headless runs cannot answer prompts, so list only the tools the task needs. See headless mode.
Related links
- Claude Code headless mode (code.claude.com)
- Claude Code CLI reference (code.claude.com)
0 Comments for this cheatsheet. Write yours!