@expo/code-review-cli
A config-driven, multi-agent AI code reviewer. Specialist agents review a diff in
parallel; a coordinator consolidates their findings into one structured review.
The same engine runs locally (advisory) and in CI (posts one PR comment). The CLI
is the engine — each repo supplies its own agents and settings under
.expo-agents/code-review/, so behavior is configured per-repo, not baked in.
(Repos set up before 0.15 keep their .expo-code-review/ directory: every command
looks for the new name first and falls back to the old one, and ecr init reuses
an existing legacy directory rather than starting a second one.)
Status: experimental. Comment-only and non-blocking — it never blocks a merge
and never auto-approves. See ROADMAP.md.
Inspired in part by Cloudflare's How we built our AI code review bot.
This README is the scannable overview. Every subsystem has a detailed design doc
under llp/ — start with
LLP 0000, the system map.
flowchart TD
SRC["Source<br/>local git · GitHub PR (gh)"] --> FILTER["Noise filter<br/>drop lockfiles · generated · binary"]
FILTER --> CHUNK["Chunk<br/>by changed lines (large diffs only)"]
CHUNK --> AGENTS["Agents (parallel)<br/>each .md in agents/ · read·grep·glob·list"]
CHUNK --> XCUT["Cross-cutting pass<br/>multi-file issues (large diffs)"]
AGENTS --> COORD["Coordinator<br/>dedupe · re-judge · decide"]
XCUT --> COORD
COORD --> VERIFY["Verify<br/>quote-ground · adversarially verify criticals"]
VERIFY --> REPORT["Reporter<br/>one PR comment (CI) · terminal (local)"]
Why not just claude -p "review this diff"?
A one-shot prompt in a workflow works — until the failure modes show up. The
engine exists for those:
- Everything the reviewer reads is attacker-controlled. The diff, the PR
description, and the repo files are all input an outside contributor wrote —
and a bare CLI run obeys instruction files from that same checkout
(
CLAUDE.md, .mcp.json, plugins) while holding the model credential and
comment token. Here, configuration comes only from the trusted base commit,
those files are scrubbed before the engine starts, and every pass is read-only
(details below).
- Confident-but-wrong findings post as-is. Raw model output is the review.
Here, every finding is quote-grounded against the real file and criticals are
adversarially verified before anything is posted.
- Failures read as silence or approval. A one-shot call that stalls, gets
rate-limited, or returns garbage either fails the job or posts nothing. Here,
each failure class has its own bounded retry, a failed run never renders as a
clean result, and CI always posts a terminal comment.
- Big diffs blow the context window. Large PRs are chunked with a separate
cross-cutting pass for multi-file issues; specialist agents run in parallel; the
prompt layout is cache-stable, and every run reports tokens, cost, and cache
hit rate.
- Noise wastes the model's attention. Lockfiles, generated bundles, and
binaries are filtered before the model sees them — recorded, never silently
dropped.
- Comment spam. One fingerprinted comment updated in place, with
/dismiss,
severity floors, inline ignores, and author-reply tracking — not a new wall of
text per push.
- Review prompts rot.
ecr ref-check fails when a prompt cites code that
moved or vanished, and every run warns loudly if a provider substituted a
different model than configured.
The security gap, specifically
A review bot is a process holding a model credential and a GitHub write token
that reads attacker-controlled input for a living. A bare claude -p workflow
typically checks out the PR head and hands the model broad tools — so a PR that
says the right words can run code, read secrets, or post as you. The trust model
here (LLP 0001) is built around that:
- No PR-controlled code is ever built or executed. The engine runs as the
published npm package via
npx; the scaffolded workflows check out only the
base commit, with persist-credentials: false.
- The model has no write tools and no ambient web.
Read/Grep/Glob only
— never Bash, Edit, or WebFetch. An injected instruction has nothing to
act with; the worst it can do is produce a wrong finding, which then has to
survive verification.
- Review policy is not PR-editable. Config, prompts, rosters, and the auth
mapping load from the PR's immutable base commit;
tokenEnv is honored in
exactly one root-owned place, enforced at the schema level and again by an
independent CI guard step.
- Credentials are compartmentalized. Child environments are allowlists that
omit ambient keys; the research MCP never sees a model credential, the model
process never sees the search key, and outbound research queries fail closed
on credential-shaped input.
- Untrusted text can't impersonate the reviewer. PR prose travels inside
sanitized boundary markers, and every
<!-- in it is escaped so a forged
state marker can't hijack the dismissal list. critical/secrets findings
can't be dismissed or cleared by replies — enforced in code, not the prompt.
- The blast radius is capped by design. The review is advisory and
comment-only: even a fully fooled model can't approve, merge, or block
anything.
Usage
Run via npx @expo/code-review-cli <command> (or the ecr / expo-code-review
binary once installed). On a repo that already has .expo-agents/code-review/ set up,
getting model credentials for local runs is one command:
npx @expo/code-review-cli setup-auth
Reviewing a PR (--pr/ci) needs the GitHub CLI — brew install gh && gh auth login.
Everything else the reviewer needs (including the opencode runtime) ships with the
package.
First-time setup
# 1. Scaffold .expo-agents/code-review/ + a CI workflow (--no-workflow to skip)
npx @expo/code-review-cli init
# 2. Get model credentials — guided; prints the export lines for your shell config
npx @expo/code-review-cli setup-auth
# 3. Verify env, config, and credentials
npx @expo/code-review-cli doctor
setup-auth reads the repo's config and walks through each credential it needs.
The scaffolded default is Anthropic via the Claude Code CLI: locally your
claude login is enough, and for CI it helps you mint a token with
claude setup-token. It also handles the alternatives (an OpenAI API key,
a ChatGPT/Codex subscription sign-in, or a Meta Model API key for Muse
Spark). doctor offers to run it whenever a credential is missing.
In CI, store the credential as the repo secret the scaffolded workflow forwards
(CLAUDE_CODE_REVIEW_SHARED_API_TOKEN by default — an sk-ant-oat… token from
claude setup-token, or an sk-ant-api… Console key; the CLI reads either).
Prefer Muse Spark, OpenAI (API key, or a ChatGPT/Codex subscription, or
both mixed), or another provider? See Other providers & auth modes
below.
Reviewing (already configured)
# Review working-tree changes; prints here, posts nothing
ecr review
# Review a GitHub PR by number (preview only)
ecr review --pr 123
# …and post it as the PR comment
ecr review --pr 123 --post
# Preview once, save the exact result, and post it later without another model run
ecr review --repo owner/repo --pr 123 --save-review --json
ecr post-review --artifact .expo-agents/code-review/.runs/deferred/<artifact>.json --repo owner/repo --pr 123
Options (most to least common):
| Flag |
What it does |
--pr <n> |
Review GitHub PR #n by number (diff fetched via gh, no checkout); not combinable with --base/--head/--staged. |
--post |
With --pr, also post the result as the PR comment (needs gh auth). Omit to preview only; re-run with --post to publish. |
--save-review |
With explicit --repo + --pr, save the exact preview as a private postable artifact. Mutually exclusive with --post. |
--staged |
Review only staged changes (index vs HEAD; not combinable with --base/--head). |
--base <ref> |
Base ref to diff against (default: merge-base with the default branch). |
--head <ref> |
Head ref to diff (default: working tree, incl. uncommitted changes). |
--agents <a,b> |
Run only these agents (comma-separated ids), even when their paths match no changed file; default: all. |
--route |
Let an LLM router pick the relevant agents from the diff. |
--repo <owner/repo> |
Repo for --pr (default: inferred from the current checkout). |
--json |
Emit machine-readable JSON on stdout. |
--no-fail |
Always exit 0 (otherwise a request_changes decision exits non-zero). |
-h, --help |
Show help. |
--pr uses the PR's diff (authoritative) and checks the PR head out into a
throwaway worktree so the agents' surrounding-source reads and the verifier see the
PR's versions of files — no manual gh pr checkout needed, and your working tree is
left untouched. (If that materialization can't run — e.g. not a git checkout — it
falls back to reading the current working directory.)
In CI it runs automatically from the scaffolded workflows — by label or a /review
comment (see CI usage). From Claude Code (or another agent), add a slash command
that runs it; eas-cli's
/expo-review
is a ready example to adapt.
Command reference
| Command |
What it does |
ecr init [--no-workflow] [--force] |
Scaffold .expo-agents/code-review/ (config, agents, prompts) + a CI workflow. |
ecr init --monorepo |
…and add a routing.jsonc routing manifest (one default scope). |
ecr init --scope <dir> |
Scaffold a per-team scope under <dir> and register it in the manifest. |
ecr setup-auth [--yes] |
Walk through getting model credentials for local runs (ChatGPT/Claude sign-in and/or API keys), printing the export lines for your shell config. |
ecr review [options] |
Review local changes and print an advisory review (default command). |
ecr review --scope <name> |
Review only one routing scope over just that scope's changed files. |
ecr post-review --artifact <path> --repo <owner/repo> --pr <n> |
Post an exact saved PR preview without re-running models; refuses target, head, config, or break-glass drift. |
ecr ci |
Review the current GitHub PR and post/update a comment. For GitHub Actions. |
ecr attach --pr <n> |
Reopen a finished review. An anthropic model opens in Claude Code. Any other model opens in the OpenCode shipped with this CLI. |
ecr doctor [--list-scopes] |
Check environment, config, credentials, and (with a manifest) scopes. |
ecr feedback [--repo <owner/repo>] |
Report which findings PR authors pushed back on, across history. See below. |
ecr ref-check [--json] |
Fail when the review setup cites code that moved or vanished. See below. |
Extra flags for monorepos: review/ci --config-dir <dir> (load config from an
alternate dir; also ECR_CONFIG_DIR), ci --scopes a,b (limit the fan-out to
named scopes), ci --comment single|per-scope (override the manifest). Both
review and ci also take --context-file <path> (inject a file's text as
untrusted external context; see below).
(When developing this repo itself, use bun run src/cli.ts <command>.)
Storing review sessions
ecr ci can store the transcript of each review pass in a private repository.
Storage is off until the ecr ci step of the workflow sets two variables:
SESSION_STORE_REPO: the owner/name of a private repository. Each run
becomes one release there. ecr ci does not upload to a repository that is not
private.
SESSION_STORE_TOKEN: a token that can create a release in that repository
(contents: write). The workflow's own GITHUB_TOKEN cannot write to another
repository. Only the upload receives this token.
A transcript holds the prompts, the diff, and the file contents the reviewers read.
Everyone who can read the store repository can read them, so give the store the same
readers as the code.
ecr attach --pr <n> reopens one stored pass on your machine, on the commit that
was reviewed. It downloads with your own gh login, which needs read access to the
store. An anthropic pass opens in Claude Code with the read tools only. Any other
pass opens in OpenCode, which asks before it runs a command, edits a file, or uses
the network.
Keeping prompts true (ecr ref-check)
Good reviewer prompts cite real code ("every webhook router must call
sanitizeSecrets"). Then the code moves and the prompt keeps citing a path that no
longer exists — the reviewer reasons from a fiction on every PR. ecr ref-check
makes those citations checkable: pin each one with a @ref comment (<!-- … --> in
Markdown, // in JSONC):
<!-- @ref server/src/session.ts#createSession — the only place a session is minted -->
<!-- @ref glob:**/*WebhookRouter.ts — the routers this rule is about -->