AnthropicClaude Certified Architect – Foundations2026-103.6 Integrate Claude Code into CI/CD pipelines
Bound unattended jobs with explicit controls
Completed by the knowledge check
Learning objective
Run unattended jobs with -p (--print), explicit permission policy and --max-turns, so automation cannot stall on interactive approvals.
Core idea
An unattended Claude Code job needs three separate controls: a non-interactive invocation, a policy that decides tool requests without a person, and a limit on agentic turns. -p supplies the first control. It does not grant tool permissions or bound the amount of work.
Choose these controls from the job’s actual assignment. A reviewer that receives a diff needs different tools from a test generator that edits files and runs tests. The goal is a completed assignment under an explicit policy, with an incomplete or failed outcome when the assignment cannot finish under that policy.
See 0.6 for tool availability versus approval. This lesson applies that distinction to continuous integration (CI) and the anthropics/claude-code-action workflow integration.
How it works
Select print mode and a permission baseline
Run claude -p or claude --print with a prompt. Claude Code prints its result without entering interactive mode. It accepts piped standard input, so a pipeline can supply the diff without granting Bash permission merely to retrieve it. The process exits with code 0 on success and a non-zero code on failure. Invalid flags are reported to stderr before execution; failures inside the run can appear in the result on stdout.
Set --permission-mode dontAsk for a job that should deny operations requiring approval unless its rules already allow them. Actions that need no approval in Manual mode, including reads within working directories and the documented read-only command set, can still run. dontAsk is not a policy that denies every unlisted operation.
Pre-approve required operations with --allowedTools, for example "Read,Bash(npm test *)". This flag grants permission; it is not an exclusive tool menu. Use --tools to restrict built-in tool availability, and --disallowedTools for explicit denials. The built-in tool menu does not restrict MCP tools; --disallowedTools "mcp__*" denies those when the job should use no MCP tools.
A read-only review can use this control pattern:
claude -p "Review the supplied diff for correctness defects" \
--permission-mode dontAsk --permission-prompts none \
--tools "Read" --allowedTools "Read" \
--disallowedTools "mcp__*" --max-turns 8 < pr.diffHere pr.diff is a pipeline-produced file, and eight turns is an example job budget, not an Anthropic recommendation. The command supplies the diff and permits local file inspection. It does not permit an implementation step that needs Edit or Bash.
Remove unanswered permission requests
Print mode without a permission host denies requests it cannot approve. When an Agent SDK host or --permission-prompt-tool handles approvals, however, a run can wait for that host to answer. --permission-prompts none prevents consulting that host and denies unresolved requests instead. It also tells Claude that nobody can approve the request and not to retry it.
The flag requires Claude Code v2.1.259 or later. Permission rules, the selected permission mode, and PermissionRequest hooks still evaluate requests; a hook can allow a request that would otherwise prompt. Setting the flag does not remove policy checks or turn a denial into an approval. If necessary work is denied, correct the job’s scoped grants or assignment rather than assuming the review completed.
An unresolved request waits only when a permission host is consulted; otherwise it is denied.
Bound turns and elapsed time separately
--max-turns limits agentic turns in print mode. There is no limit by default, and reaching the limit exits with an error. A job that hits its cap has exhausted its execution budget; a partial investigation is not a clean review.
A turn cap is not a wall-clock timeout. Anthropic’s GitHub Actions guidance also recommends workflow-level timeouts. A print-mode run can wait for background work after its main turn finishes. Bare mode prevents background tasks, but changes context loading too; see 3.6.3. Decide the mode before relying on that behavior.
For a simple unattended job, avoid interactive question tools, long-running watchers, and unspecified approval hosts. Make the prompt say what evidence the job needs and what result it should return if that evidence is unavailable. This lets the permission policy remain narrow without disguising missing work as success.
Configure the GitHub Action’s trigger and tools
Anthropic’s documentation uses anthropics/claude-code-action@v1. With no prompt input, the action responds to its trigger phrase, @claude by default, in supported issue or PR events. With a prompt input, it runs an automation without waiting for a mention, subject to the action’s actor checks.
Pass CLI options through claude_args, including --max-turns and explicit --allowedTools entries for the operations the automation needs. A GitHub App’s repository permissions do not by themselves pre-approve every Claude tool call. The action’s README describes GitHub APIs and file operations, with additional tools enabled through configuration.
The word “interactive” in the action’s mode describes responding to a GitHub request. It does not mean that a person types approvals into the CI runner. Conversely, an automation prompt does not mean that tools or comment posting are automatically unrestricted. Automation results appear in the workflow log by default; posting requires instructions and a tool that can post.
Key distinctions and trade-offs
The controls answer different questions:
| Control | Question it answers |
|---|---|
-p / --print | Does the process run without an interactive terminal session? |
--permission-mode dontAsk | How are tool calls that would require approval resolved? |
--allowedTools | Which calls receive explicit pre-approval? |
--permission-prompts none | Can an unresolved request wait for a permission host? |
--max-turns | How many agentic turns can this assignment consume? |
Narrow grants can cause a job to fail when necessary evidence is inaccessible. Broad grants can let an assignment perform unrelated operations. Give the job the smallest useful scope and treat denials as evidence about incomplete execution.
Architecture / decision scenario
A developer-productivity pipeline runs a correctness review whenever a PR changes. The workflow supplies an automation prompt to anthropics/claude-code-action@v1, passes the selected permission policy and turn cap through claude_args, and explicitly allows the tools used to inspect the diff and source.
A separate CLI review script uses -p with the read-only pattern shown here. It cannot wait for an approval host, and the CI workflow imposes an elapsed-time timeout. If the reviewer needs a denied command or reaches --max-turns, the pipeline records an incomplete review and repairs the assignment or grants. It does not publish “no defects” from a truncated run.
Common exam traps
- Using a longer timeout to repair an interactive invocation.
- Treating
-pas permission to execute every tool. - Treating
--allowedToolsas an exclusive tool list. - Assuming
dontAskdenies reads that normally need no approval. - Confusing the action’s mention mode with interactive terminal input.
- Treating a turn-limit error as a successful empty review.
Where the exam guide differs
The exam guide says to use the “-p flag to prevent interactive input hangs.” A print run without a permission host denies unresolved requests, but a run with an SDK canUseTool host or --permission-prompt-tool can wait for that host. Set --permission-prompts none when nobody can answer; it requires Claude Code v2.1.259 or later. In an exam item describing a job stuck in an interactive session, -p remains the expected fix. Host-mediated approval waits require the additional control.
What to remember
Use -p, select a permission baseline, grant required tools explicitly, and set --max-turns. Add --permission-prompts none when nobody can answer approvals, with the documented version requirement. In GitHub Actions, prompt selects automation and claude_args carries CLI controls; trigger selection, tool approval, and execution limits remain distinct.
Knowledge check
A CI test-generation job runs claude "Write unit tests for the modules changed in this pull request". The runner log shows an interactive session waiting for input until the 30-minute timeout kills it. Which change switches this invocation to non-interactive execution?
--allowedTools "Read,Edit" to the existing command-p to the existing command--output-format json to the existing command-p the command opens an interactive session; adding it prints the result and exits instead of keeping that session open. --allowedTools pre-approves tool calls but does not change the invocation, and --output-format shapes print-mode output without switching the run into print mode.A review job runs claude -p with --permission-mode dontAsk. Its prompt asks Claude to run npm test, but every run reports that the Bash call was denied. The job must keep denying every other operation that needs approval. Which change lets the tests run?
--permission-prompts none to the review command--tools "Read,Bash" to the command--max-turns for the command--allowedTools "Bash(npm test *)" to the commanddontAsk denies any call that would need approval unless a rule already allows it, so the fix is a scoped pre-approval for the one command. --tools controls which built-in tools are available, not which calls are approved; --permission-prompts none denies unresolved requests rather than approving them; and more turns repeat the same denial.A nightly job uses Claude Code v2.1.259 or later and runs claude -p with --permission-prompt-tool pointing at an approval tool that a teammate answers during working hours. Overnight, runs sit waiting on approval requests that nobody answers. The job must keep its permission policy and immediately deny requests that would otherwise wait for the host. Which change meets this?
--permission-prompts none to the command--permission-mode bypassPermissions--max-turns for the command--permission-prompts none stops consulting it and denies unresolved requests while allow rules still apply. Bypassing permissions approves everything, the opposite of the requirement. A turn cap does not bound a wait inside a turn, and a timeout only kills the stalled run.A workflow passes a prompt input to anthropics/claude-code-action@v1 and --max-turns 10 through claude_args. The GitHub App already has permission to write comments, but Claude has no posting tool grant or instruction to post. Runs finish with reviews in the workflow log. Which change posts a pull request comment while keeping the automation trigger?
prompt input and trigger runs with @claude-p and --output-format json to the claude_args inputclaude_args and ask Claude to post--allowedTools in claude_args . Removing prompt makes the action wait for an @claude mention instead, and the app’s repository permissions do not pre-approve Claude’s tool calls.An unattended review reaches --max-turns 8 and exits with an error before completing its investigation. It has not reported any defects. How should CI record the result?
--max-turns exits with an error and leaves the investigation incomplete; an absence of findings from that run is not a completed clean review. A turn cap bounds agentic turns, independently of tool approval and the workflow’s elapsed-time timeout.References
- Anthropic, Run Claude Code programmatically
- Anthropic, CLI reference
- Anthropic, Claude Code GitHub Actions
- Anthropic, Claude Code Action README
- Anthropic, Claude Certified Architect – Foundations Exam Guide