cd /news/ai-agents/run-a-claude-code-review-in-ci-with-… · home › topics › ai-agents › article
[ARTICLE · art-164222] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Run a Claude Code review in CI with one claude -p line

A developer documented a method for running Claude Code as a non-interactive CI step using the CLI's headless mode, `claude -p`, which runs a single prompt, prints the result, and exits. The approach pipes a `git diff` into the prompt and uses `--allowedTools "Read,Grep"` to keep the run read-only and `--max-turns 3` to bound execution, then fails the build unless the output is exactly "LGTM". The writeup recommends storing the API key in repository secrets and running the check with `continue-on-error: true` for a week before making it block builds.

by read1 min views1 publishedNov 5, 2026

Most people only use Claude Code interactively. But the same CLI has a headless mode: claude -p "<prompt>" runs one prompt, prints the answer, and exits. That makes it a normal script step you can drop into CI or a git hook.

git diff origin/main...HEAD | claude -p "Review this diff. List real bugs only. If there are none, print exactly: LGTM" --output-format text

Piped stdin becomes context, -p runs non-interactively, and the output is plain text you can grep.

#!/usr/bin/env bash
set -euo pipefail
out=$(git diff origin/main...HEAD | claude -p \
  "Review this diff for bugs, missing error handling and leaked secrets. If nothing is wrong, reply with exactly LGTM." \
  --allowedTools "Read,Grep" --max-turns 3)
echo "$out"
[[ "$out" == "LGTM" ]] || exit 1

--allowedTools "Read,Grep" keeps the CI run read-only: it can look at files but not edit or run shell commands.--max-turns 3 caps how long it can wander.--output-format json and parse .result with jq.

- name: Claude review
  env:
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  run: |
    npm i -g @anthropic-ai/claude-code
    ./scripts/claude-review.sh

Keep the key in repository secrets, never in the script.

CLAUDE.md and .claude/settings.json still load in headless mode, so your house rules apply in CI too.continue-on-error: true) for a week before you let it fail builds. I keep copy-ready Claude Code configs (CLAUDE.md templates, slash commands, hooks, permission rules) in Vildanden Agent Config. There's a free sample: https://justly-mia-429.rehost.page/

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/run-a-claude-code-re…] indexed:0 read:1min 2026-11-05 · —