A Claude Code Review Bot in CI: Headless -p, JSON Findings, Team Rules in Git and a Person on the Merge
Design a pull-request review bot with Claude Code: run it headless with -p, ask for JSON findings with a schema, keep review rules in a committed CLAUDE.md, leave the merge to a person and batch the nightly job.
What you will learn
- Run Claude Code in a CI step with -p so it runs once and exits
- Get findings back in a fixed shape with --output-format json and --json-schema
- Keep the team's review rules in a project CLAUDE.md committed to git
- Keep the bot as an advisor, and send work nobody waits on to the Message Batches API
Before you start
- What Claude Code is
- Basic CI with GitHub Actions
A developer opens pull request 212 on the shop-app repository: a refund rounding fix. Before any person looks at it, a review bot does. It runs Claude Code inside the CI pipeline and leaves its findings as inline comments.
The bot has three jobs on every pull request: review for bugs and security problems, suggest tests the suite is missing, and post feedback as comments. The goal has two halves. The feedback must be actionable, and there must be few false positives, because noisy comments teach people to ignore all of them, the good ones too.
So most of the design is about the pipeline around the model, not the model. Let's make five decisions.
Where Claude review fits in the wider change process (what goes in git, a change gate by path, the GitHub Action) is in Claude in the SDLC.
The system in one picture
Decision 1: the job hangs, so run it headless
A workflow step runs claude "Review the changes in this pull request". On the runner it never finishes, and the log ends with Claude Code waiting for input. Nobody is there to answer.
The fix is the print flag, -p. It is the documented non-interactive mode: it runs once, prints the answer and exits.
claude -p "Review the changes in this pull request"
The workarounds people try first all miss the cause:
- A longer timeout. Nobody will ever answer, so it only hangs longer.
- Piping
yesinto it. That guesses at questions and breaks on any question that isn't yes or no. - A pseudo-terminal that presses Enter. A fragile copy of what
-palready does.
Decision 2: findings must become comments, so ask for a shape
The review comes back as one long paragraph. A script has to post each finding on its own line, at the right file and line. Asking for "a tidy list" and parsing it with a regular expression works until the first time the layout changes, because free text drifts. Running the review twice and keeping the tidier one gives you two unparseable answers instead of one. And describing the layout in CLAUDE.md guides the model, but it doesn't guarantee a shape.
The fix is --output-format json together with --json-schema, where the schema describes one finding. The schema makes the output machine-parseable, so the script can post every finding as an inline comment. The lecture's finding has four fields: file, line, severity and message. As an illustration, a schema for that could look like this:
{
"type": "object",
"properties": {
"findings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"file": { "type": "string" },
"line": { "type": "integer" },
"severity": { "type": "string" },
"message": { "type": "string" }
},
"required": ["file", "line", "severity", "message"]
}
}
},
"required": ["findings"]
}
The posting script then loops over findings and creates one comment per item. No regex, no guessing. The same idea outside Claude Code is in structured LLM output with Pydantic.
Decision 3: the team's rules live in a committed CLAUDE.md
The team has review rules:
- Money is stored in cents, never floats.
- Skip style nitpicks the formatter already handles.
- Every refund path needs a test.
These rules must apply on the CI runner and on every developer's laptop, and they must change through code review. That points to one place: a CLAUDE.md at the repository root, committed to git. The runner and every teammate load the same rules, and changing a rule is a pull request like any other change.
| Where | Why it fails here |
|---|---|
~/.claude/CLAUDE.md on each laptop | Personal, not in git. The runner never sees it. |
CLAUDE.local.md in each checkout | Personal to one checkout, so the team and the runner don't share it. |
| Pasted into the workflow prompt in every repository | Ten copies drift apart, and no developer's own Claude Code reads them. |
| CLAUDE.md at the repo root, in git | Shared by everyone, reviewed like code. |
Decision 4: the bot advises, a person approves
Review time is the bottleneck, and a manager suggests counting the bot's review as the required approval whenever it reports no findings. Don't. Zero findings means the bot found nothing, not that the change is safe. Making the bot stricter so nobody has to look doesn't change that: a stricter bot is still a model and can still miss things. Removing the bot throws away a fast first pass that catches real problems.
Keep the bot as an advisor. Merging still needs passing checks and a person's approval.
Decision 5: the merge check stays synchronous, the nightly job is batched
Claude runs two jobs. One is a check that blocks the merge button until it passes. The other is a nightly job that suggests missing tests across the repository, read at the next morning's standup. The lead wants the lowest cost for both.
The Message Batches API costs less but promises no speed, so use it where nobody is waiting. The nightly job goes through batches. The merge check stays synchronous.
- Both in batches removes the gate: the check exists so the merge waits for it.
- Both synchronous gives up the 50 percent saving on work nobody is waiting for.
- The merge check in batches makes developers wait on a job with no latency promise.
The same "who is waiting decides the lane" rule drives the overnight document pipeline.
Common mistakes
- Fixing a hang with timeouts instead of
-p. - Parsing free text with a regex when the CLI can return JSON that matches a schema.
- Keeping review rules in personal files, so the runner reviews against different rules than the team.
- Letting "no findings" stand in for an approval.
- Batching a check that someone is waiting on.
Recap
| Symptom | Fix |
|---|---|
| The job waits for input | Run it headless with -p |
| Findings must become comments | --output-format json with --json-schema |
| The team has review rules | A CLAUDE.md in the repo, committed to git |
| Who decides the merge | Checks pass and a person approves; the bot advises |
| Nobody is waiting on it | Message Batches; a blocking check stays synchronous |
When two fixes both sound sensible, ask what the cause is: the flag, the schema, the file, the approval or the API. Pick the one that fixes that cause.
Try it yourself
Write the CLAUDE.md for your own repository with three review rules, then sketch the schema for one finding in your project. Which field would your posting script need that the four fields above don't cover?
Related course on Udemy
Claude Certified Developer - Foundations (CCDV-F) Exam Prep
Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)Related posts
CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
Three needs in one repo: a test command, a rule that Claude must never read .env, and a shared deploy skill. See which file each belongs in, how the settings layers merge, and what a plugin manifest carries.
Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
Pack a support team's ticket-triage routine into one skill folder, then watch three requests load one, two or all three levels: the catalog, the SKILL.md body, and a script whose code never enters the context.
One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
Change one line in a repo and ask where it lands. A small resolver for bookshop-bot shows that a new model id in settings.json reaches only CI, a prompt bump reaches dev and CI, and a prod block edit reaches only prod.
Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
Follow one prompt edit from a branch to a merge: version prompts and the model pin like code, keep the API key in GitHub Secrets, gate changes by path, let Claude review the diff, and leave the merge to a person.