CI/CD Integration
Non-interactive mode
claude -p "prompt" (or --print) runs without a UI. It reads stdin (capped at 10 MB), exits 0 on success and non-zero on failure.
| Need | Option |
|---|---|
| Output format | --output-format text (default), json, or stream-json |
| Schema-validated result | --output-format json --json-schema '<schema>'; the answer is in the structured_output field (text is in result) |
| Auto-approve tools | --allowedTools "Read,Edit,Bash(git diff *)" (trailing * is prefix matching; mind the space) |
| Permission baseline | --permission-mode acceptEdits, auto, or dontAsk (denies anything that would prompt; good for locked-down CI) |
| No prompts at all | --permission-prompts none (anything that would prompt is denied and Claude is told not to retry) |
| Add instructions | --append-system-prompt (keeps defaults); --system-prompt replaces |
| Continue | --continue (most recent) or --resume <session_id> (session_id is in the JSON output) |
| Spend and turns | --max-budget-usd, --max-turns (via claude_args in the action) |
JSON output also reports total_cost_usd and session metadata (client-side estimates).
Reproducible runs: --bare
--bare skips auto-discovery of hooks, skills, commands, subagents, plugins, MCP servers, auto memory and CLAUDE.md, so a run behaves the same on every machine. It does not use subscription login (set ANTHROPIC_API_KEY). Pass any needed context explicitly (--append-system-prompt, --mcp-config, --settings, --agents). It is recommended for scripted and SDK calls. Without it, a -p run loads project hooks and .mcp.json servers even in an untrusted folder, with no trust dialog and no per-server approval.
GitHub Actions
- Action:
anthropics/claude-code-action@v1. Interactive mode (noprompt): responds to@claudein issue/PR comments. Automation mode (promptset): runs on any event, includingschedule. - Auth: secret
ANTHROPIC_API_KEY(orCLAUDE_CODE_OAUTH_TOKEN); never commit keys; store as repository or organization secrets. Workload identity federation avoids long-lived secrets. - Permissions: grant only what is needed (typically
contents,pull-requests,issues,id-token: write). - Pass CLI options through
claude_args(--max-turns,--model,--allowedTools,--mcp-config). - Who can trigger: the actor needs write access; bots are rejected unless listed in
allowed_bots. CLAUDE.mdin the repo defines review criteria and standards; keep it concise since it is read every run.- GitHub does not trigger workflows on commits made with the default
GITHUB_TOKEN; let the action authenticate as the Claude GitHub App for downstream CI to run. - Cost control: specific requests, concise CLAUDE.md,
--max-turns, workflow timeouts, concurrency limits.
Review bots and false positives (design guidance)
- Put explicit, categorical criteria in the prompt or CLAUDE.md (what counts as a bug worth reporting, what to ignore); vague "be thorough" invites noise.
- Run the review with a fresh session per change (no carried-over context) and consider a separate reviewer instance from the one that wrote the code (see Domain 4.6).
- Emit structured findings (
--json-schema) so CI can gate on them.
Exam traps
- Running
-pwithout a permission plan, so it blocks or over-permits. - Expecting an OAuth login in a headless run (authenticate first, or use an API key).
- Hard-coding secrets in the workflow file.
- Forgetting
--bare, so a teammate's hooks or an unvetted.mcp.jsonrun in CI. - Parsing free text when
--json-schemagivesstructured_output.
References
- Run Claude Code programmatically — checked Oct 16, 2026
- Claude Code GitHub Actions — checked Oct 16, 2026
Check your understanding
CI must get a machine-readable verdict. Flags?Show answerHide answer
Answer
--output-format json --json-schema ..., readstructured_output.A locked-down pipeline should deny anything that would prompt. Mode?Show answerHide answer
Answer
--permission-mode dontAsk.Where does the schema-valid result appear?Show answerHide answer
Answer
structured_output.