Task Statement 3.6·Domain 3 — 20% of exam
CI/CD Integration
Integrate Claude Code into CI/CD pipelines
Official Exam Guide Objectives
The objectives below are quoted from Anthropic's Claude Certified Architect – Foundations exam guide, v1.1. Read the exam guide summary for the full blueprint.
Knowledge of
- The -p (or --print) flag for running Claude Code in non-interactive mode in automated pipelines
- --output-format json and --json-schema CLI flags for enforcing structured output in CI contexts
- CLAUDE.md as the mechanism for providing project context (testing standards, fixture conventions, review criteria) to CI-invoked Claude Code
- Session context isolation: why the same Claude session that generated code is less effective at reviewing its own changes compared to an independent review instance
Skills in
- Running Claude Code in CI with the -p flag to prevent interactive input hangs
- Using --output-format json with --json-schema to produce machine-parseable structured findings for automated posting as inline PR comments
- Including prior review findings in context when re-running reviews after new commits, instructing Claude to report only new or still-unaddressed issues to avoid duplicate comments
- Providing existing test files in context so test generation avoids suggesting duplicate scenarios already covered by the test suite
- Documenting testing standards, valuable test criteria, and available fixtures in CLAUDE.md to improve test generation quality and reduce low-value test output
What You Need to Know
Running Claude Code inside a pipeline changes what it is. There is no operator, no conversation, and nothing that can pause for a decision — it becomes an automated review and generation step. Five concepts are tested here, and the -p flag is the most directly examinable single fact in the domain (it is Question 10 in the sample question set).
A pipeline imposes four requirements that interactive use does not, and each has one answer:
| CI requirement | Mechanism |
|---|---|
| It must not wait for input | -p / --print |
| Its output must be parseable by the next step | --output-format json plus --json-schema |
| No human is there to supply project context | CLAUDE.md |
| It must not repeat itself from run to run | Feed the prior findings back in, with an instruction about them |
The fifth concept, session isolation, is about how the review step is arranged rather than a requirement of running unattended: review in a separate invocation from the one that generated the code.
The -p Flag: Non-Interactive Mode
By default Claude Code opens a conversational interface and waits for you to type. A CI runner has nobody to type, so the process sits there until the job times out — no error, no output, just a job that never finishes.
# WRONG — hangs in CI
claude "Analyse this pull request for security issues"
# CORRECT — runs non-interactively
claude -p "Analyse this pull request for security issues"-p (equivalently --print) selects print mode: the prompt is processed, the result goes to stdout, the process exits.
There is nothing to reason about here — it is recall. Items describe a stalled job with logs showing Claude waiting on input, and the answer is -p. The distractors are inventions: CLAUDE_HEADLESS=true is not a variable, --batch is not a flag, and redirecting stdin from /dev/null does not change the mode Claude Code is running in.
-p is the single most tested fact in Domain 3, step 1: claude \
Structured Output for CI
Output in a pipeline is consumed by software, not read by anyone, so it needs to parse. Two flags cover it:
--output-format json— returns the run inside a JSON envelope carrying the result text alongside the session ID and cost/usage figures, rather than prose meant for a terminal--json-schema— checks the agent's final output against a schema you supply, and is available in print mode only
claude -p \
--output-format json \
--json-schema '{"type":"object","properties":{"findings":{"type":"array","items":{"type":"object","properties":{"file":{"type":"string"},"line":{"type":"integer"},"severity":{"type":"string"},"message":{"type":"string"}}}}}}' \
"Review this PR for security issues"One detail costs people marks: the schema-conforming data sits in the envelope under structured_output, so it is jq '.structured_output' rather than reading the top level. What you get back is validated enough to act on:
- Parse programmatically
- Post as inline PR comments at the exact file and line
- Filter by severity for different notification channels
- Track across review runs
The findings sit under structured_output, not the top level, step 1: claude -p --output-format json --json-schema '...'
A finding schema that survives re-runs
The four-field schema above is enough to post a comment. A schema built for a review bot that runs on every push carries more, and each extra field has a job:
| Field | Why it is there |
|---|---|
file, line (integer, minimum 1) | Where the inline comment goes; a prose location cannot be posted |
severity and category as enums (for example critical/high/medium/low) | Free-text severities drift ("blocker", "major"); an enum lets the pipeline route and filter reliably |
issue, suggested_fix | The comment body: what is wrong and what to do |
finding_id | A stable identifier the next run reuses when it reports the same issue again |
previously_reported (boolean) | Marks a finding already posted and still unaddressed, so the bot can update rather than re-post |
detected_pattern | The code construct that triggered the finding, so dismissed findings can be analysed by pattern (the guide's Task 4.4 skill) |
confidence | Lets findings be routed by confidence (the calibrated review routing of Task 4.6) |
Mark the fields the posting step depends on as required and set "additionalProperties": false, so a finding with a missing line or an invented field fails validation instead of reaching the PR.
Failing loudly when there is no structured output
A run can end without schema-conforming data: it errors, or it gives up on producing output that validates. If the posting step simply reads whatever is there, an empty read posts no comments and the pipeline reports a clean review. Check the envelope first. Here argv is the full claude -p … --output-format json --json-schema … command:
import json, subprocess
def run_review(argv: list[str]) -> dict:
proc = subprocess.run(argv, capture_output=True, text=True, check=True)
envelope = json.loads(proc.stdout) # result, session_id, is_error, ...
if envelope.get("is_error") or "structured_output" not in envelope:
raise RuntimeError(f"review failed: {envelope.get('subtype')}")
return envelope["structured_output"] # the validated payload; "result" is textThe invariant: a missing structured_output fails the job, it is never read as "no findings".
Session Context Isolation
Asking the session that wrote the code to review the code is weaker than asking a fresh one, and not marginally.
Why self-review is weaker:
Generating code leaves a session holding its own reasoning — the approach it settled on, the alternatives it dismissed, the trade-offs it accepted. Reviewing inside that same session means every one of those decisions arrives already justified, and a decision that has been justified is one the reviewer is disinclined to reopen.
The fix: independent review instances
Invoke a second time, with no access to the first session's reasoning. The reviewer then meets the code as code, with no attachment to why it looks the way it does.
# Session A — writes the code
claude -p "Implement the token refresh middleware"
# Session B — separate invocation, no sight of A's reasoning
claude -p "Audit the token refresh middleware: auth bypasses, unhandled failures, edge cases"In a pipeline this has a concrete shape: generation and review run as separate jobs, or at minimum as separate claude -p invocations. Each claude -p call starts its own session, so independence is the default; it is lost only if the review deliberately picks the generating session back up (with -c / --continue or -r / --resume), which reinstates exactly the context the split exists to remove.
The same principle appears in Domain 4 as multi-instance review architecture and in Domain 5 as context management; here it is tested specifically in a pipeline.
An independent session meets the code without attachment, step 1: One session writes the token refresh middleware
Incremental Review Context
Reviews fire on every push, and a review with no memory re-derives its findings from scratch each time. The issues genuinely fixed drop off by themselves, because the code that triggered them is gone. The ones that persist are those the developer read and decided against — and a context-free scan cannot distinguish a rejected suggestion from a new problem, so it raises them again on every push.
Carrying the previous findings forward, with an instruction to report only what is new or still outstanding, is the fix:
claude -p \
--output-format json \
"Review this PR. The previous run reported the following:
${PREVIOUS_FINDINGS}
Return only two categories:
1. Anything not present in that list
2. Anything from that list still unresolved in the current diff
Say nothing about items the developer has evidently seen and chosen to leave."What is at stake is whether anyone reads the output. Five identical comments arriving on every push teach the team that the comments carry no information, and once that lesson lands the genuinely important finding is skipped with the rest.
Report only what's new or still outstanding, step 1: Push 1 — a review with no memory reports 5 findings
Both halves, or it does not work
The fix has two parts, and the exam checks both: include the prior findings in context, and instruct Claude what to do with them (report only new or still-unaddressed issues). Prior findings passed without the instruction just produce the same list again, now with extra context cost. With the re-run-aware schema above, the instruction can be precise: for a still-unaddressed issue, reuse its finding_id and set previously_reported to true; never restate a finding whose code has been fixed or removed.
The prior findings have to come from somewhere the next run can reach: store each run's JSON output as a CI artefact and load it on the next run, or read the bot's existing comments back from the pull request.
CLAUDE.md for CI Context
A CI-invoked run reads the project's CLAUDE.md files exactly as an interactive one does, which makes CLAUDE.md the mechanism for giving an automated run the context it cannot ask for:
- Testing standards: which patterns the team writes tests in, and which it has decided against
- Available fixtures: what already exists to build test data from, and what each one contains
- Review criteria: where the line sits between something worth blocking a merge for and a style preference
- Existing test coverage: what is already exercised, so suggestions land on the gaps
Absent that, generated tests are plausible and worthless — assertions about behaviour nobody was worried about, duplicating coverage that already exists. With it, they follow the conventions the team already uses and test what is actually uncovered.
# .claude/CLAUDE.md — CI-relevant section
## Testing Standards
- Build test data through the factories in test/factories/, never inline literals
- Integration tests reach the database through test/setup/db.ts
- Assert against public API contracts; private internals are not a test surface
- New code is expected to reach 80% branch coverage
- Fixtures on hand: test/fixtures/users.json, test/fixtures/orders.json
## What makes a test valuable here
- Assert behaviour, not implementation; no mock-call-count assertions
- Skip trivial getters and setters, framework-provided behaviour, pure re-exports
- Prefer one parametrised test over five near-duplicates
## Review criteria
- Report: security issues, correctness bugs, data-loss risks,
missing error handling on external calls
- Do NOT report: formatting, naming preferences, or patterns
already used consistently elsewhere in the module
- Severity: critical = security hole, data loss, auth bypass;
high = missing error handling, an uncovered edge caseThe middle block answers the guide's "valuable test criteria": without it, "low-value test output" is whatever a plausible test looks like. The last block is Task 4.1's explicit criteria (what to report versus skip) living in CI configuration, and it is the main lever on false positives in an automated review.
Keeping the runner's own configuration out
A CI runner may carry its own ~/.claude (user CLAUDE.md, user skills and agents), which makes runs differ between machines. --setting-sources project loads only the committed project settings and CLAUDE.md and skips user-level and local configuration. It is partial isolation: managed policy, ~/.claude.json and auto memory are still read. For full isolation, use --bare, at the cost of the project context above.
CLI Flags Reference
-p is the flag the exam tests hardest, but a headless run is shaped by several others: what form the output takes, which system prompt is in force, and how far permissions and tools extend. Everything below works with claude -p in CI and equally with the interactive claude.
System prompt flags. Four exist, and the distinction under test is append versus replace:
| Flag | Effect |
|---|---|
--system-prompt "<text>" | Substitutes your text for the whole default prompt |
--system-prompt-file <path> | Same substitution, with the text read from a file |
--append-system-prompt "<text>" | Leaves the default in place and adds your text after it |
--append-system-prompt-file <path> | Same addition, with the text read from a file |
Append when Claude should remain a coding assistant that additionally follows your rules — the default tool guidance, safety instructions and coding conventions all survive, so you write only the difference. Replace when the role genuinely is not Claude Code's: a non-coding agent running in a pipeline nobody is watching. Replacing discards the whole default prompt, which means anything the task still depends on is now yours to supply.
Headless output and limits (print mode).
| Flag | Effect |
|---|---|
--output-format text | json | stream-json | How -p returns its result; json and stream-json are machine-parseable, text is not |
--input-format text | stream-json | How -p expects its input to arrive |
--json-schema '<schema>' | Validates the final output against your schema; paired with --output-format json the result appears under structured_output |
--max-turns <n> | Stops the run once this many agentic turns have elapsed; a -p run has no turn limit unless you set one |
--max-budget-usd <amount> | Stops the run once its spend reaches this amount |
--verbose | Emits every turn rather than the final result alone |
Reproducibility and bounding. An unattended run should be bounded (it cannot be interrupted by anyone watching) and should behave the same on every runner:
| Flag | Why in CI |
|---|---|
--max-turns, --max-budget-usd | Cap a runaway run by turns and by spend |
--allowedTools / --disallowedTools | No interactive approver exists, so grant the read-only tools the job needs explicitly |
--mcp-config <file> with --strict-mcp-config | Load only the MCP servers the pipeline declares, ignoring any others configured on the runner |
--setting-sources project | Committed project settings only, not the runner's user configuration (partial isolation; see above) |
--append-system-prompt | Adds CI-specific framing for one job without editing CLAUDE.md |
Built up, a review invocation looks like this:
claude -p "$(cat .github/prompts/review.md)" \
--output-format json \
--json-schema "$(cat .github/review-schema.json)" \
--allowedTools "Read" "Grep" "Glob" "Bash(git diff *)" \
--setting-sources project \
--strict-mcp-config --mcp-config .github/ci-mcp.json \
--max-turns 12 --max-budget-usd 2.00Each line answers one requirement: -p prevents the hang, the schema makes the output postable, the tool list and setting sources fix what the run can do and see, and the caps bound it.
Permissions, tools, and context.
| Flag | Effect |
|---|---|
--permission-mode <mode> | Chooses the starting mode: default, acceptEdits, plan, auto, dontAsk, or bypassPermissions |
--allowedTools "<rules>" | Names what may run unprompted, e.g. "Bash(git diff *)" "Read" |
--disallowedTools "<rules>" | Denies matching calls; give a bare tool name and the tool disappears from context altogether |
--tools "Bash,Edit,Read" | Narrows the built-in tools available in the first place |
--add-dir <path> | Extends read and edit access to another directory — file access only, not configuration discovery |
--model <alias | name> | Selects the model for the session (sonnet, opus, or a full identifier) |
Session and start-up. -c / --continue picks the most recent conversation in the current directory back up, while -r / --resume <id|name> targets a specific one. --bare is the minimal mode: auto-discovery is skipped entirely — hooks, skills, plugins, MCP servers, auto memory and CLAUDE.md are all left unloaded — so a scripted call starts quickly with only the Bash and file read/edit tools in hand. It suits scripted runs where speed and predictability matter more than having project configuration present.
Providing Existing Tests to Avoid Duplication
Test generation in CI needs the existing tests in context, and for a reason that only shows up in review: without them Claude Code has no way to know what is already covered, so it proposes tests that duplicate ones already in the suite. Every duplicate costs a developer the time to read it and reject it. Supplied with the current tests, the same run identifies gaps instead. It is the same pattern as incremental review — show what already exists, and say what to do about it:
claude -p "Generate tests for the changes in this PR.
Existing coverage is shown below; do not propose scenarios it already covers.
$(cat tests/test_orders.py tests/test_refunds.py)" \
--output-format json --json-schema "$(cat .github/tests-schema.json)"The existing tests tell the run what is covered; CLAUDE.md tells it how the team writes tests. Duplicated scenarios point at the first gap, inline test data instead of the team's factories at the second.
A Complete Pipeline
A GitHub Actions job that puts the pieces together. It assumes Claude Code is installed on the runner and the API key is held as a repository secret:
on: pull_request
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Claude review
env: { ANTHROPIC_API_KEY: "${{ secrets.ANTHROPIC_API_KEY }}" }
run: |
git diff origin/${{ github.base_ref }}...HEAD > pr.diff
claude -p "$(cat .github/prompts/review.md)" \
--output-format json --json-schema "$(cat .github/review-schema.json)" \
--allowedTools "Read" "Grep" "Glob" --setting-sources project \
--max-turns 12 --max-budget-usd 2.00 < pr.diff > review.json
- run: python .github/scripts/post_comments.py review.json # reads .structured_outputThe diff arrives on stdin, the findings land in review.json, and a separate step posts them. The alternative most teams use is the official action, anthropics/claude-code-action@v1, which takes the prompt as an input and passes CLI flags through claude_args (see Deep Dive).
Precision by Category and Developer Trust
This goes beyond Task 3.6 into Task 4.1, but it is where a CI review bot lives or dies. Tracking which findings developers act on, per category, exposes the problem the guide names: "high false positive categories undermine confidence in accurate categories". An illustrative month of findings:
| Category | Raised | Acted on | Precision |
|---|---|---|---|
| security | 22 | 20 | 0.91 |
| correctness | 50 | 44 | 0.88 |
| maintainability | 22 | 4 | 0.18 |
| performance | 84 | 13 | 0.15 |
Two categories near 0.2 drag down trust in the two near 0.9. The guide's remedy is to temporarily disable the high false-positive categories while improving the prompts for them: not delete them, and not filter on the model's confidence. The detected_pattern field then shows which construct misfires (here, for instance, a database call inside a loop flagged as a performance issue), so the criteria can be fixed for that pattern rather than for the whole category.
Batch API vs Real-Time for CI Workflows
The Message Batches API costs 50% less and takes up to 24 hours, with no guaranteed latency SLA. Those two facts together draw a sharp line:
| Workflow type | API choice | Reason |
|---|---|---|
| Pre-merge checks (blocking) | Real-time (synchronous) | Someone is sitting waiting on the answer |
| Overnight technical debt reports | Batch API | Nobody is blocked, and it costs 50% less |
| Weekly code audit | Batch API | Runs to a schedule, so latency is irrelevant |
| Nightly test generation | Batch API | Finishes overnight and is read the next morning |
The distinguishing question is whether anybody is blocked. A pre-merge check holds up both a developer and a merge, and "up to 24 hours, no guarantee" is not a wait a review gate can absorb — so those go to the real-time API however attractive the saving looks. Work that runs on a schedule and is read whenever someone gets to it is exactly what the 50% discount is for. The exam tests this distinction directly (Sample Question 11).
Deep Dive
--bare mode for reproducible CI runs
--bare reduces startup time by skipping auto-discovery of hooks, skills, plugins, MCP servers, auto memory, and CLAUDE.md — useful for CI and scripts that need the same result on every machine, independent of what happens to be installed locally. Anthropic states --bare is "the recommended mode for scripted and SDK calls, and will become the default for -p in a future release." This trades away exactly the CLAUDE.md context this lesson otherwise relies on — reach for --bare only when reproducibility matters more than project context.
Sourcecode.claude.com › headlessfetched 2026-07-30
JSON output fields: cost tracking and structured_output
With --output-format json, the response payload includes total_cost_usd and a per-model cost breakdown, letting scripted callers track spend per invocation. Combining --output-format json with --json-schema puts the schema-conforming data specifically in the structured_output field, alongside session ID and usage metadata — extract it with jq -r '.structured_output', not from the top level of the envelope. As of v2.1.205, an invalid JSON Schema makes claude exit with an explicit error rather than silently falling back to unstructured text.
Sourcecode.claude.com › headlessfetched 2026-07-30
dontAsk mode for locked-down CI runs
The dontAsk permission mode denies anything not already in your permissions.allow rules or the built-in read-only command set — recommended specifically for locked-down CI runs where nothing should be improvised. In non-interactive -p runs generally, auto mode aborts the session when the classifier repeatedly blocks actions, because there's no user available to prompt.
Sourcescode.claude.com › headlesscode.claude.com › permission-modesfetched 2026-07-30
Operational limits worth knowing for CI
Piped stdin into claude -p is capped at 10MB (as of v2.1.128); exceeding it produces a clear error and non-zero exit status. Stopping a claude -p run with SIGTERM aborts the in-progress turn, terminates the process tree of any running Bash command, runs SessionEnd hooks, and exits with code 143. The stream-json output format's last line is always a result message carrying the final response text, cost, and session metadata.
Sourcecode.claude.com › headlessfetched 2026-07-30
GitHub Actions integration
A simple @claude mention in any PR or issue lets Claude analyse code, create PRs, implement features, and fix bugs while following the project's standards; the integration is built on the Claude Agent SDK. Quick setup runs /install-github-app interactively; manual setup installs the Claude GitHub app, adds ANTHROPIC_API_KEY as a repository secret, and copies the example workflow into .github/workflows/. The app needs read & write on Contents, Issues, and Pull requests. The v1 action auto-detects interactive mode (responding to @claude mentions) versus automation mode (running immediately with a prompt), exposes a unified prompt input plus claude_args for CLI passthrough (for example --json-schema … or --max-turns 12), and defaults its trigger_phrase to "@claude". The docs give no default turn cap for the action, and the CLI reference states that a -p run has no turn limit by default, so pass --max-turns through claude_args if you want one.
Sourcescode.claude.com › github-actionscode.claude.com › cli-referencefetched 2026-11-19
CI gate on MCP/plugin load errors
The stream-json format's system/init event carries plugin_errors and mcp_server_errors fields whose keys are omitted entirely when there are no errors — so a CI gate can simply fail the job when either array is non-empty, without needing to distinguish "no errors" from "empty array."
Sourcecode.claude.com › headlessfetched 2026-07-30
Quick Reference
| Item | Value / behaviour |
|---|---|
| Non-interactive mode | -p / --print — the single most tested fact in Domain 3 |
--output-format values | text (default), json (structured, with cost fields), stream-json (NDJSON, real-time) |
--json-schema | validated JSON in print mode only; lands in structured_output field with --output-format json |
| Cost tracking | --output-format json includes total_cost_usd + per-model breakdown |
--bare | skips hooks/skills/plugins/MCP/auto-memory/CLAUDE.md; reproducible; future -p default |
dontAsk mode | denies anything not pre-approved — for locked-down CI |
| stdin cap | 10MB piped into claude -p; over the cap = error, non-zero exit |
SIGTERM on -p | aborts turn, runs SessionEnd hooks, exits 143 |
| GitHub Actions trigger | @claude mention (default trigger_phrase) |
| GitHub App permissions | Contents, Issues, Pull requests — all read & write |
Turn limit for -p | none by default; set --max-turns yourself (in the action, through claude_args) |
| Bounding a CI run | --max-turns and --max-budget-usd |
| Runner-independent config | --setting-sources project (partial), --strict-mcp-config + --mcp-config, or --bare (full, no CLAUDE.md) |
--json-schema run read from result | wrong field: result is text; a missing structured_output should fail the job |
| Re-run-aware finding fields | finding_id, previously_reported, plus detected_pattern and confidence |
| Duplicate-comment fix | prior findings in context and an instruction to report only new or still-unaddressed issues |
| CI gate signal | non-empty plugin_errors / mcp_server_errors in system/init |
| Session isolation | independent review instance beats same-session self-review |
| Batch API for CI | only for non-blocking workloads (up to 24h, no latency SLA) — never pre-merge checks |
| CLAUDE.md in CI | read identically to interactive mode (not under --bare) — the way to supply testing/review standards |
Exam Traps
More wrong answers, and why each fails
| Tempting answer | Why it fails | Choose instead |
|---|---|---|
--headless, --ci, --non-interactive, or a CLAUDE_CI / CLAUDE_NONINTERACTIVE variable | None of them is a Claude Code flag or variable; the exam habitually offers invented names beside the real one | -p / --print |
--max-turns 1 to stop a hang | A real flag, but it bounds an agentic loop that is already running; a session blocked at the interactive prompt never reaches a turn boundary | -p |
| Regex-parsing prose findings, or asking for a Markdown table in the prompt | A requested shape is not a guaranteed one; a run that words or renders it differently breaks the parser | --output-format json with --json-schema |
--output-format json on its own | The envelope parses, but the findings inside it have no guaranteed structure | Add --json-schema |
| A self-review instruction ("review this as if a stranger wrote it") in the generating session | The justifications are still in context whatever stance is requested | A separate invocation with no shared context |
| Enabling extended thinking for the self-review | More reasoning over the same pre-justified context does not remove the commitment to it | A separate invocation |
| Deduplicating at the posting layer by matching comment text | Matching text cannot tell an issue that is still present from one that was fixed and has since come back, so real regressions are suppressed with the repeats | Prior findings in context, plus the new-or-unaddressed instruction |
| Raising the severity threshold, or reviewing less often, to cut repeated comments | The complaint is repetition, not volume; real findings are dropped and the survivors still repeat | Prior findings in context, plus the instruction |
| Relying on whatever configuration the runner happens to have | Runs differ from machine to machine | --setting-sources project, or --bare for full isolation |
| Leaving a CI run unbounded | A -p run has no turn limit by default, so a runaway costs time and money | --max-turns and --max-budget-usd |
How This Is Tested
| Stem signal | Answer | Wrong-answer pattern beside it |
|---|---|---|
| The pipeline hangs; logs show Claude Code waiting for input | -p | Invented flag or variable; stdin redirect; --max-turns 1 |
| Findings must be posted automatically as inline PR comments | --output-format json with --json-schema | Regex over prose; a requested Markdown table; JSON without a schema |
| The parse comes back empty although the run found issues | Read structured_output, not result or the top level | A side file on disk; a streaming event |
| The same comments appear after every push | Prior findings in context and an instruction to report only new or still-unaddressed issues | Text-matching dedupe; higher severity bar; fewer runs |
| Generated tests duplicate existing coverage | Existing test files in context | A bigger model; more turns |
| Generated tests ignore the team's factories and conventions | Testing standards, valuable-test criteria and fixtures in CLAUDE.md | Assuming -p skips CLAUDE.md; a full style guide |
| How does CI-invoked Claude Code learn the project's conventions? | CLAUDE.md | A prompt rewritten for each job |
| The generating session reviewed its own code and approved it | An independent review instance | Self-review instruction; extended thinking; a stronger model in the same session |
| Blocking pre-merge check versus overnight report, with a 50% saving on offer | Batch for the overnight report only | Batch for both, with polling or a timeout fallback |
Official sample question 10, option by option
The stem: "Your pipeline script runs claude "Analyze this pull request for security issues" but the job hangs indefinitely. Logs indicate Claude Code is waiting for interactive input." The question asks for "the correct approach to run Claude Code in an automated pipeline".
| Option | Verdict | The official explanation |
|---|---|---|
| A. "Add the -p flag: claude -p "Analyze this pull request for security issues"" | Correct | "The -p (or --print) flag is the documented way to run Claude Code in non-interactive mode. It processes the prompt, outputs the result to stdout, and exits without waiting for user input—exactly what CI/CD pipelines require." |
| B. "Set the environment variable CLAUDE_HEADLESS=true before running the command" | Wrong | It references a "non-existent" feature: there is no "CLAUDE_HEADLESS environment variable". |
| C. "Redirect stdin from /dev/null: claude "Analyze this pull request for security issues" < /dev/null" | Wrong | One of the "Unix workarounds that don't properly address Claude Code's command syntax". |
| D. "Add the --batch flag: claude --batch "Analyze this pull request for security issues"" | Wrong | Another "non-existent" feature: there is no "--batch flag". |
Two of the three distractors are invented names, and the third is a shell trick that leaves Claude Code in interactive mode. Knowing the real flag names is worth marks across Domain 3; when an option names a flag or variable you have never seen, that is usually the reason it is there.
Practice Scenario
Your pipeline chains generation and review into a single claude -p call: it writes the migration code, then asks Claude to audit what it has just written before opening the pull request. The audit has approved every run for six weeks. An external security review then found two authentication gaps in code that audit had passed. Which approach should you take?
Practice Questions
Exam simulator
Question 1 of 14
Scenario · Claude Code for Continuous Integration
Your pipeline runs claude "Summarise the risk in this diff" < diff.txt. Locally it works, but in CI the job sits idle until the runner's timeout kills it. A teammate proposes wrapping the step in a 10-minute timeout and retrying once. What change would most effectively fix the job?
Sources
- Claude Code CLI Reference — Anthropic
- Claude Code Headless Mode Documentation — Anthropic
- Claude Code GitHub Actions Documentation — Anthropic
- Claude Certified Architect Foundations Exam Guide — Task Statement 3.6 — Anthropic
- Claude Certified Architect Foundations Exam Guide — Sample Questions 10 and 11 — Anthropic
- Anthropic Message Batches API Documentation — Anthropic
- Claude Code — Permission Modes — Anthropic