WORKFLOW · multi-agent-orchestration
Fan-out review workflow
A headless script plus GitHub Actions wrapper that runs three domain reviewers (security, performance, test coverage) in parallel over a PR diff and gates on blocking findings.
✓ verified 2026-06-10 · stack: github-actions, claude-code · source
Three fresh-context reviewers, one lens each, run in parallel over the same
PR diff. This is the documented domain-partitioned review trio (security
implications, performance impact, test coverage) built on the documented
headless fan-out shape (claude -p invocations as one-shot workers). Each
reviewer receives the diff on stdin and nothing else, which is the
fresh-context mechanism in its purest form: only the diff and the criteria.
Parallel invocation is safe because reviewers never edit the repo and each
writes to its own output file.
#!/bin/bashset -euo pipefail
BASE="${1:?usage: fan-out-review.sh <base-ref>}"OUT="reviews"mkdir -p "$OUT"
git diff "$BASE"...HEAD > "$OUT/pr.diff"if [[ ! -s "$OUT/pr.diff" ]]; then echo "Empty diff against $BASE — nothing to review." exit 0fi
COMMON='You are reviewing a pull request diff, provided after theseinstructions. Apply ONLY the review lens given below. Report only findingsthat affect correctness or the stated lens — never style. You were asked tofind problems, so you will be inclined to report some even in sound code:every finding must cite a file and hunk from the diff and describe a concretefailure scenario, and a clean result is a valid result. Mark each findingBLOCKING or NON-BLOCKING. End your output with exactly one line:VERDICT: PASSorVERDICT: BLOCK(BLOCK if and only if at least one BLOCKING finding exists.)'
run_review() { local domain="$1" lens="$2" claude -p --permission-mode default "${COMMON}
Review lens: ${lens}" < "$OUT/pr.diff" > "$OUT/review-${domain}.md"}
run_review security "Security implications. Injection, authn/authz gaps, \secrets or credentials in the diff, unsafe deserialisation, SSRF, \path traversal." &run_review performance "Performance impact. N+1 queries, unbounded \collections or queries, blocking calls on hot paths, missing pagination, \accidental O(n^2)." &run_review test-coverage "Test coverage. New behaviour without tests, edge \cases visible in the diff but untested, assertions that cannot fail, \deleted or weakened tests." &wait
STATUS=0for f in "$OUT"/review-*.md; do if ! grep -q "^VERDICT: " "$f"; then echo "FAIL-CLOSED: $f has no verdict line." STATUS=1 elif grep -q "^VERDICT: BLOCK" "$f"; then echo "BLOCK: $f reported blocking findings." STATUS=1 else echo "PASS: $f" fidoneexit "$STATUS"name: Fan-out Reviewon: pull_request: branches: [main]
jobs: fan-out-review: name: Fan-out Review runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install Claude Code run: npm install -g @anthropic-ai/claude-code - name: Run domain reviewers env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} # For AWS Bedrock instead of the direct API: # CLAUDE_CODE_USE_BEDROCK: "1" # AWS_REGION: eu-west-2 # plus OIDC-assumed credentials run: ./scripts/fan-out-review.sh "origin/${{ github.base_ref }}" - name: Upload review outputs if: always() uses: actions/upload-artifact@v4 with: name: fan-out-reviews path: reviews/Make the script executable and commit both files. On AWS, swap the API key
for Bedrock auth: set CLAUDE_CODE_USE_BEDROCK=1 and provide AWS credentials
(OIDC role assumption in Actions), per the documented authentication options.
To make the check mandatory, add the Fan-out Review job name as a required
status check in a ruleset. The wiring is in
required checks for agent PRs.
What it does
- Runs the documented three-lens partition in parallel, so each fresh context attends fully to one class of issue instead of a single reviewer gravitating toward one type of finding.
- Feeds each reviewer only the diff and its criteria (no implementer
rationale, no shared state between reviewers) and collects three
machine-checkable
VERDICT:lines. - Fails closed: a missing verdict line (truncated output, refusal, API error mid-stream) fails the job rather than passing silently.
- Stays inside the safe-parallelism rule: read-only workers, disjoint output files, no repo edits: the shapes where fan-out pays.
For a managed alternative driven by GitHub events, see the claude-code-action PR review workflow. Use that when you want Anthropic’s maintained action; use this fan-out script when you need custom lenses or Bedrock-only auth.
Failure modes
- Diff-only context cuts both ways. Reviewers cannot see surrounding code, so findings of the form “this caller may not handle X” can be wrong in either direction. Treat BLOCK verdicts as a gate for human attention, not an oracle; if you need repo-aware review, run the adversarial reviewer subagent from a checkout instead.
- The verdict line is a prompt contract. A model can emit prose around it or omit it; the fail-closed check converts that into a visible failure, but expect occasional retries.
- Large diffs can exceed the context window. Very large PRs need splitting (per-directory diffs) or a path filter on the workflow trigger; a truncated diff reviews the wrong thing silently.
- Cost scales with pushes. Three full-diff reviews per push; add
paths:filters or a label condition if the bill surprises you. - The permission mode is pinned on purpose. From Claude Code v2.1.285,
claude -pon Bedrock (or with telemetry off) starts in auto mode when nothing sets a mode, while the same call against the Anthropic API starts indefault(permission modes docs, re-checked 2026-10-05). Without the flag, the Bedrock variant of this job would let a reviewer reading an untrusted diff run shell commands on a runner holding OIDC-assumed AWS credentials, approved by a classifier rather than refused.--permission-mode defaultkeeps both auth paths on the behaviour this artifact was verified under. Copies taken before 2026-10-05 lack the flag: add it. - Install and flags drift. The npm package name and CLI behaviour are version-sensitive: re-verify the install step against the current Claude Code docs when adopting.
Verified against the Claude Code best-practices headless fan-out shape, domain-partitioned review trio, and fresh-context reviewer mechanism, 2026-06-10.