All articles

Running Claude Code in CI Pipelines

Claude Code is not only for sitting at your terminal. With the right flags it becomes a step in an automated pipeline, doing the same reasoning work without a human present.

The core recipe

The foundation is headless mode plus JSON output. -p runs once and exits; --output-format json gives you a structured result your pipeline can parse.

claude -p "review the changes in this PR for obvious bugs" --output-format json

This pairing is the basis for CI and automation. Because the output is structured, a later step can read a field, decide pass or fail, and act on it without guessing at free text.

Feeding it real data

CI is full of command output, so lean on pipes to supply the input:

git diff origin/main | claude -p "summarize risky changes" --output-format json

You can also add --append-system-prompt to set consistent rules for every run, so the review behaves the same on every build.

Keeping it safe

Permission modes matter more in CI, where nobody is watching the prompts. Choose the least power the job needs. A read-only review can run in plan mode. Only loosen permissions when the task genuinely has to change files, and be very careful before removing prompts entirely.

Beyond the CLI

Headless claude -p --output-format json covers a lot of scripting and CI needs on its own. If you outgrow it and want to embed the same agent loop inside your own service, the Claude Agent SDK exists for that. For most pipeline steps, though, the CLI is all you need.

Comments

Be the first to comment.