What Print Mode Does
`claude -p` runs Claude Code in non-interactive print mode. It takes a prompt, runs to completion, and exits with a standard exit code. No approval dialogs, no prompts for user input.
This makes it usable in CI where there is no human to click through permission dialogs.
Basic Usage
claude -p "Review the diff and list any security issues" --max-turns 5Pipe context in via stdin:
git diff HEAD~1 | claude -p "Review this diff for bugs. Output JSON: {issues: []}"GitHub Actions Example
1 - name: AI Code Review 2 env: 3 ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} 4 run: | 5 git diff ${{ github.event.pull_request.base.sha }} > diff.txt 6 claude -p "$(cat diff.txt) 7 8 Review this diff. Return JSON: {\"summary\": \"\", \"issues\": [], \"approved\": true|false}" \ 9 --max-turns 3 \ 10 --output-format json > review.json 11 cat review.json
Exit Codes
`claude -p` exits `0` on success and non-zero on failure. Use this in pipelines:
claude -p "Run the tests and return exit code 1 if any fail" || exit 1Limitations
Print mode does not support interactive tool approval. If a tool requires approval (like running shell commands), it will be blocked unless you add `--allowedTools` flags:
claude -p "Check the build" --allowedTools "Bash,Read"Keep the allowed tool list minimal. In CI, you usually only need `Read` and `Bash` with specific command patterns.
Comments (0)