{"slug": "run-a-claude-code-review-in-ci-with-one-claude-p-line", "title": "Run a Claude Code review in CI with one claude -p line", "summary": "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.", "body_md": "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.\n\n```\ngit diff origin/main...HEAD | claude -p \"Review this diff. List real bugs only. If there are none, print exactly: LGTM\" --output-format text\n```\n\nPiped stdin becomes context, `-p` runs non-interactively, and the output is plain text you can grep.\n\n``` bash\n#!/usr/bin/env bash\nset -euo pipefail\nout=$(git diff origin/main...HEAD | claude -p \\\n  \"Review this diff for bugs, missing error handling and leaked secrets. If nothing is wrong, reply with exactly LGTM.\" \\\n  --allowedTools \"Read,Grep\" --max-turns 3)\necho \"$out\"\n[[ \"$out\" == \"LGTM\" ]] || exit 1\n```\n\n`--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`.\n\n```\n- name: Claude review\n  env:\n    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}\n  run: |\n    npm i -g @anthropic-ai/claude-code\n    ./scripts/claude-review.sh\n```\n\nKeep the key in repository secrets, never in the script.\n\n`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.\nI 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/](https://justly-mia-429.rehost.page/)", "url": "https://wpnews.pro/news/run-a-claude-code-review-in-ci-with-one-claude-p-line", "canonical_source": "https://dev.to/vildandenai/run-a-claude-code-review-in-ci-with-one-claude-p-line-1i8c", "published_at": "2026-11-05 01:11:40+00:00", "updated_at": "2026-11-05 01:22:47.835320+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "mlops"], "entities": ["Claude Code", "Anthropic", "GitHub Actions", "Vildanden Agent Config"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/run-a-claude-code-review-in-ci-with-one-claude-p-line", "markdown": "https://wpnews.pro/news/run-a-claude-code-review-in-ci-with-one-claude-p-line.md", "text": "https://wpnews.pro/news/run-a-claude-code-review-in-ci-with-one-claude-p-line.txt", "jsonld": "https://wpnews.pro/news/run-a-claude-code-review-in-ci-with-one-claude-p-line.jsonld"}}