Skip to lesson

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.diff

Here 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.

An unresolved request waits only when a permission host is consulted; otherwise it is deniedStarts at a tool request, which permission rules, the mode and hooks evaluate first. A request they allow runs. An unresolved request is denied when --permission-prompts none is set. Without the flag, it is denied when there is no permission host, and waits for that host to answer when an Agent SDK host or --permission-prompt-tool handles approvals.allowunresolvedsetnot setnonehandles approvalsTool requestPermission rules,mode and hooksevaluateRequest allowed--permission-promptsnone?Permission host?Unresolved requestdeniedWait for that hostto answer

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:

ControlQuestion it answers
-p / --printDoes the process run without an interactive terminal session?
--permission-mode dontAskHow are tool calls that would require approval resolved?
--allowedToolsWhich calls receive explicit pre-approval?
--permission-prompts noneCan an unresolved request wait for a permission host?
--max-turnsHow 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 -p as permission to execute every tool.
  • Treating --allowedTools as an exclusive tool list.
  • Assuming dontAsk denies 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

Note:

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

References