CI/CD & Structured Extraction
Headless mode, JSON output, schemas and validation loops.
Two Scenarios, One Theme
This lesson fuses two exam scenarios that share a single backbone: determinism under automation. Scenario 5 (Claude Code for CI/CD) and Scenario 6 (Structured Data Extraction) both ask the same question — how do you get machine-parseable, trustworthy output with no human in the loop?
The answer is the same in both worlds:
- Headless / non-interactive execution so a pipeline can drive Claude.
- JSON output with a schema so downstream code can parse results.
- Validation loops that catch and repair structural errors before they propagate.
Master this and you cover a meaningful slice of D3 (Config & Workflows) and D4 (Structured Output) — together 40% of the exam.
Headless Mode in CI/CD
A pipeline has no TTY and no human to answer prompts. Claude Code must run non-interactively. The flag for this is -p (also written --print): it runs a single prompt, prints the result, and exits.
Pair it with --output-format json so the pipeline gets a structured envelope instead of free prose. Without these two flags, the command hangs waiting for interactive input and the build stalls.
-p/--print= non-interactive, required in pipelines.--output-format json= parseable result (optionally with a schema).
# Headless review step in a CI job
claude -p "Review the staged diff for correctness bugs only. \
Flag a comment ONLY when it contradicts the code." \
--output-format json \
> review.json
# Pipeline now parses review.json deterministically
jq '.result' review.jsonAll lessons in this course
- Support Agent & Multi-Agent Research
- Code Gen & Developer Productivity
- CI/CD & Structured Extraction
- Conversational Patterns & Agentic Tools