Review the current diff, a commit, or a path with independent read-only reviewers and a validated findings artifact requiring the mandatory correctness axis. Use before merge or after a large change. NOT for applying fixes; use code-remediate.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Code Review?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/borda-code-review-ai-rig)
---
name: Code Review
description: Review the current diff, a commit, or a path with independent read-only reviewers and a validated findings artifact requiring the mandatory correctness axis. Use before merge or after a large change. NOT for applying fixes; use code-remediate.
---
<!-- ../../../../assets/images/code-review-arch.svg diagrams intake, reviewer fan-out, findings validation, verification and finalize. Documentation only, never loaded — update it in the same commit as any change to step order, gate placement, agent fan-out, or process boundary. -->
# Code Review
> Read [Evidence rules](../../references/evidence.md). This workflow is read-only apart from its evidence artifacts, PR preparation (one new dedicated local ref, fetched objects and a disposable review worktree), and dependency provisioning in a throwaway verification environment outside the project. It never writes to GitHub. Follow [Role dispatch](../../references/evidence.md#role-dispatch) for native-agent fallback and stop on reported scope violations. Use the shared [Optional command compression](../../references/evidence.md#optional-command-compression) guidance for read-heavy commands.
```bash
git status --porcelain
git diff --stat | tail -n 20
```
## Input
- `workspace` (default): staged and unstaged changes.
- `path <path>`: one file or directory.
- `commit <rev>`: one commit's changed files.
- `pr <number|url>`: optional PR mode when `gh` is authenticated; resolves the PR head to commit mode. Earlier PR commits are a coverage limit unless separately reviewed.
- Optional: an implementation run ID and acceptance criteria for an implementation handoff.
## Workflow
1. **Classify.** `TRIVIAL`, `LOCAL`, `BROAD`, or `HIGH_RISK`, using the scope thresholds in [Rig Plan, Workflow step 1](../rig-plan/SKILL.md#workflow); read those definitions before classifying. Risk categories set depth; they do not grant execution authority.
2. **Start the run.** Prepare the scope before starting:
- a. For an implementation handoff, first inspect its run with `rig_evidence` (`action: "inspect"`, `run_id: <implementation run ID>`), read its recorded `outputs` and bound plan, and take acceptance criteria from that plan or the supplied criteria. Use only those output paths within the plan's owned scope; exclude unrelated changed paths. If paths or criteria are missing or ambiguous, resolve the scope before starting instead of falling back to every changed path.
- b. For PR mode, resolve the PR repository and head SHA through authenticated `gh`. Count its commits and resolve its identity and provenance with `gh pr view <n> --json commits,number,url,headRefOid,isCrossRepository,headRepository,headRepositoryOwner --repo <owner/repo>`. Use the PR repository's URL as `<pr-repo-url>` (including for fork PRs), its number as `<n>`, and the first 12 characters of the observed head SHA as `<sha12>`.
- c. For PR mode, check `git show-ref --verify --quiet refs/rig-review/pr-<n>-<sha12>`; abort if it exists (exit 0), and proceed only on the absent-ref result (exit 1). Stop on any other error. Read the result with the quiet pattern `git show-ref --verify --quiet <ref> && echo present || echo absent` instead of echoing `$?`.
- d. For PR preparation, fetch that head into the new dedicated local ref by calling `rig_review_prepare` with `pr_number: <n>`, `pr_repo_url: <pr-repo-url>` and `head_sha: <observed head SHA>`; the tool creates the host temp root's `opencode/` directory, confirms the dedicated ref is absent, and performs exactly `git fetch --no-tags --no-write-fetch-head --no-auto-maintenance <pr-repo-url> refs/pull/<n>/head:refs/rig-review/pr-<n>-<sha12>` (no `+`). Stop on failure. Verify with `git rev-parse refs/rig-review/pr-<n>-<sha12>` that the fetched SHA matches the observed PR head; stop on mismatch. Use the receipt's `ref`, `worktree` and verified `head_sha`; do not compose the path or command yourself. Never switch branches or overwrite existing refs.
- e. For PR mode, inspect `git rev-list --parents -n 1 <verified SHA>`. If the head has more than one parent, stop before starting a commit-mode run and record the limit "PR head is a merge commit; review each parent range separately" in the output; do not start a run with an empty scope. Stop if the parent check fails.
- f. Start `rig_evidence` with `action: "start"`, `skill: "code-review"`, the exact target paths, and `commit: <verified SHA>` for commit or PR mode; resolve a commit revision to its SHA first. Record the implementation run ID and acceptance criteria with `action: "record"` in `decision`, and the bound plan in `inputs` when supplied.
- In PR mode, read hosted CI at intake with `gh pr view <n> --repo <owner/repo> --json headRefOid,statusCheckRollup`. For each observation, use `rig_evidence` with `action: "record"` and `decision` to preserve the phase, observed head, check names, states or conclusions, and available job links. Attribute checks only when `headRefOid` matches the verified head SHA. When the read fails, the rollup is empty or `headRefOid` differs from the verified head SHA, use `rig_evidence` with `action: "record"` and `limits: ["PR <n>: hosted CI unavailable at intake for <sha>: <reason>"]`, where `<sha>` is the verified head SHA and `<reason>` names the read error, the empty rollup or the observed head SHA. Continue reviewing immediately, including when checks are pending or failing.
- g. In PR mode, when the commit count is above 1, use `rig_evidence` with `action: "record"` and `limits: ["PR <n>: only head commit <sha> reviewed; <k> earlier commits unreviewed"]`, where `k = commit count - 1` and `<sha>` is the verified head SHA.
- h. In PR mode, record the provenance decision before any verification: the PR number, canonical URL and verified head SHA together with `isCrossRepository` and the head repository in `decision`. An unknown provenance is treated as a fork. For a verification, use the detached worktree and verified `head_sha` returned by `rig_review_prepare`; do not create another worktree or compose its path. Remove the worktree with `git worktree remove --force` after verification, including on failure, as a single literal command with an absolute path — no `; echo "exit=$?"` tail, no shell variables such as `$TMPROOT`, no `2>&1 | tail` wrapper — and check the result with a separate quiet command. Follow the [quiet shell forms](../../references/evidence.md#quiet-shell-forms) for the rest of the review.
3. **Collect exact source.** Record the diff and the complete bytes of every reviewed file. For `workspace`, read the staged and unstaged diffs and current file bytes from the same project root used by `rig_evidence`. Do not use a detached worktree for workspace evidence: it omits uncommitted changes. For commit or PR mode, read the diff and file bytes from the verified commit, not the working tree. For an implementation handoff, compare each output's recorded `sha256` with the new scope entry for that exact path; if an entry is missing or mismatched, stop and report the changed output instead of treating it as the implementation's recorded bytes. A digest change invalidates the review.
4. **Select axes.** `correctness` is mandatory and must be run (cannot be omitted). Add `security` for auth, credentials, deserialization, or network input; `tests` when behavior changes; `api` for public interfaces, always when the diff removes, renames, moves or incompatibly changes a public module, function, class, method, parameter, default or return shape of the public API; `performance`, `docs`, and `data` when the diff warrants. Cap at four axes below `BROAD`, not counting the `api` axis when a public symbol is removed, renamed, moved or incompatibly changed. Promote `docs` when the diff changes a changelog or migration guide, `security` when it changes a CI workflow file, and `performance` for a stated performance or memory claim. Place promoted axes ahead of the other optional axes within the same cap. Axis selection does not change who may run what. Also ensure coverage records what was actually inspected for correctness.
5. **Dispatch independent reviewers.** Use `rig-auditor` (or `rig_dispatch`). Give each only the task and acceptance criteria, role card, exact source bytes or paths that resolve to those bytes, the diff, their digests, and assigned axis. Reviewers are read-only and return JSON findings; the parent never counts its own reading as reviewer evidence.
6. **Validate findings.** Reject any finding without a concrete file and observed evidence. De-duplicate by signature (file + invariant), not by wording. Use `rig_findings` with `action: "write"`, the axes that actually ran, the coverage, and `reviewer` naming the independent reviewer(s). That write records the review evidence bound to the scope digest.
- In PR mode, repeat the intake CI query once at consolidation, record the second observation under the same head check, and report it alongside any change since intake. When the refresh read fails, its rollup is empty or its `headRefOid` differs from the verified head SHA, use `rig_evidence` with `action: "record"` and `limits: ["PR <n>: hosted CI unavailable at consolidation for <sha>: <reason>"]`, where `<reason>` names the read error, the empty rollup or the changed PR head, and identify the intake result as historical. Finish without waiting or polling. Keep hosted check status separate from local verification and from source findings.
7. **Report.** Order by severity. State the axes that ran, the axes that did not, and why. For each selected axis that could not run, report `Unreviewed axis: <axis> — <reason>` on its own line and name that confidence gap with what would close it. An honest partial review beats a fabricated complete one.
8. **Finalize.** `rig_evidence` with `action: "finalize"`. Open findings are a valid review outcome; they are not a completion failure. Source drift is: start a new review instead of certifying changed bytes.
## Improvement claim evidence
Assess every material improvement claimed in the request, PR title/body or reviewed documentation, including claims without supplied benchmarks. Record each claim, its scope and evidence in the existing review report. Include the relevant claims, supplied evidence and this measurement protocol in reviewer context; the parent reconciles claim dispositions in the final report even when a specialist is omitted. Route performance claims to the performance dimension when admitted by the existing selection rules; the parent retains claim coverage when that dimension is not selected. Preserve existing scope, fan-out limits and execution permissions; inspection-only reviewers hand feasible reproduction checks to the parent. Behavioral claims need targeted tests; correctness tests alone do not prove performance or model-quality gains.
Provision a missing Python or Node package in a throwaway verification environment and run the check there. For host verification, create the environment under the OS temp root outside the project and remove it after the check. If Node needs dependencies beside the source, use a disposable source copy there. Leave the project's dependencies and the active environment untouched. Automatically provision only packages the base branch already declares and the package index supplies, following the trust-by-name rule in Rules. Apply the existing pull-request-worktree rule to names added by the change, direct URL or VCS references, and index overrides. Follow the same verification route for provisioning and execution.
Reproduce benchmark and memory claims base against head on this host with the same method and compare the relative effect. Bind numerical comparisons to exact baseline/candidate revisions, commands, representative workload/data, software, relevant hardware and settings. Attribute supplied results separately from independent reproduction. Use a predefined practical tolerance, appropriate warmup and accelerator timing, repeated measurements, raw samples, sample counts, summary statistic and variability. Check correctness and material tradeoffs. Explain hardware relevance and limit conclusions to measured workloads/devices.
Shared local CPU/GPU, memory pressure or swapping, I/O contention and thermal/power changes can confound measurements. Record relevant observable contention and unavailable observations; never assume isolation. Run comparable baseline/candidate samples sequentially in paired, alternating or randomized order; avoid concurrent competing benchmarks or agent-owned heavy checks. Bound reruns and retain noisy attempts and exclusion criteria. More samples do not remove systematic bias. Never stop unrelated processes or change system resource controls without existing authorization. If noise or unequal contention could explain the effect, label measurements inconclusive and name the quieter or representative-hardware check needed; do not confirm or refute the claim from that run.
Give each claim exactly one disposition. Record its provenance, tested scope and whether independent reproduction succeeded. Reconcile the available evidence, then apply the first matching outcome:
- **supported** when evidence supports the claim within the tested scope.
- **contradicted** when reliable counterevidence contradicts the claim.
- **unverified** when a required hardware or OS class is absent from the host. Report `not reproducible on this host: requires <CLASS>` and give the owner and next check.
- **incomplete** when verification remains undone. This includes failed provisioning (network, resolver conflict, unsupported platform or timeout), a check that failed to complete, unavailable execution authority such as a declined or unanswered trust request, and any other outstanding check needed to assess the claim. Record the concrete cause and give the owner and next check.
- **inconclusive** when completed verification cannot resolve the claim, for example because of unresolved noise or conflicting evidence. Name the follow-up that could resolve it.
Missing verification alone is a coverage limit. Preserve each workflow's existing source verdict, readiness and confidence contract.
## Rules
- A fetched PR worktree contains third-party code: running its tests, gate or reproduction executes its configuration, hooks and test code. Read its auto-load surface (`conftest.py`, `pyproject.toml`, `Makefile`, `package.json` scripts, `.pth` files, Git hooks) and the changed files, and report what they contain with an assessed risk (`none`, `borderline`, `high`, `likely-malicious`) — a heuristic, never a safety claim; packages the base already declares and the package index supplies are trusted by name, an added, URL-sourced or lookalike one is reported.
- Select the verification route in this order.
- Under `execution: "all-sandbox"`, use `rig_sandbox` for every verification, including workspace, commit and same-repository PR checks. For a detached review, keep the verified worktree as the sandbox input.
- Under `execution: "fork-sandbox"` (the default), route a forked PR, including unknown provenance, through `rig_sandbox`.
- For host verification, use the hook's trusted-directory rule. A same-repository PR runs on the host if its reviewed commit qualifies. If an untrusted review worktree requires approval, ask the `pr-trust` decision through `question` and record `rig_trust` only after the literal `Trust this PR` answer, subject to the tool's policy ([decision selectors](../../references/decisions.md)).
- For each `rig_sandbox` call, follow the receipt's `disposition` and `next_action`. Use a digest-pinned image and set `network: true` for checks that fetch dependencies. Record the receipt's network setting with the verification evidence.
- For any PR route, if a trust request is declined or unanswered or required verification permission is otherwise unavailable, leave execution stopped and mark the check incomplete. Apply the claim disposition above to the available evidence.
- The hook allows a verification outside the project root only for an own worktree at an ancestor commit or a matching per-commit trust record; anything else falls through to the role's shell rule and asks.
- Apply the dependency provisioning rule under [Improvement claim evidence](#improvement-claim-evidence) to every verification. For `rig_sandbox`, provision eligible missing packages and run the check in the same invocation with the network setting above when fetching packages.
- Keep existing refs, the project's index, working tree and environment untouched. Local writes are limited to review evidence, one new dedicated PR ref and fetched objects, a disposable detached review worktree, and the throwaway verification environment outside the project. Never write to GitHub or switch the project's branch.
- Do not fix findings here; hand them to `code-remediate`.
- A finding must cite source that was actually read; pattern-matched suspicion is labeled as suspicion.
- If an independent reviewer is unavailable, record the gap and the independent review needed to close it. Do not substitute the parent's own analysis.
- Exclude each null, blocked or failed contribution from the confidence judgment and name its gap once. Never substitute a constant score for a reviewer or check with no score of its own.
## Output
> Lead with the [handoff table](../../references/handoff.md): verdict, alignment, findings, next action, confidence. Then the evidence below.
For a change review, `Alignment` judges the diff against the repository's current module layout, naming, documentation, test conventions and dependency policy: name the conventions that decided the level and the surfaces that were not checked. A clean diff that contradicts the documented direction is `partial`, and a risky change that follows the established pattern with the risk stated is `high`.
`Confidence` reflects the weakest accepted evidence and adjusts only for named gaps. For each gap, state what it is and what closes it. Include an unavailable independent reviewer, a selected axis that did not run, an unexecuted required check, or a required hardware or OS class the host lacks when applicable. Record the host operating system and architecture and packages that can be provisioned as facts of the run, never as confidence gaps. Use `not reproducible on this host: requires <CLASS>` for a required hardware or OS class the host lacks.
`Verdict` is the source judgment on the [verdict scale](../../references/handoff.md#verdict-scale), taken from the confirmed findings that remain after refuted, stale and already-fixed claims are removed:
- `MINOR_EDITS`: every required correction has bounded impact and a localized remedy, including localized correctness, compatibility, test and documentation repairs. Documentation and missing-test gaps stay here unless a material consequence is shown.
- `MAJOR_REVISION`: a remaining confirmed defect has material impact (a broken supported workflow or binding contract, data or compatibility loss) or needs substantial coupled repair; cite its finding IDs and why a minor correction is insufficient. A fixable critical defect belongs here even when its change is small. So does a break of the released public API: a removed, renamed, moved or incompatibly changed public module, function, class, method, parameter, default or return shape counts only when it exists in the latest published release. Tiers (PEP 8) — public: no `_`-prefixed segment anywhere in its path, and documented, listed in `__all__` or re-exported by the package `__init__`, including the dunder protocol methods of a public class (`__init__`, `__call__`, `__iter__`, `__eq__`); protected (subclass API): `_x` members a class documented for inheritance offers its subclass authors, checked like public for them; private: `__x`, any other `_` name, imported-only names, tests, scripts and anything marked internal or provisional, free to change at any time and never a break. Name the tier in the finding. A project's written compatibility policy (CONTRIBUTING, docs, CHANGELOG) overrides these defaults; cite it in the finding. An undocumented, unexported name without `_` is medium (ask to underscore or document it), not blocking. A break is cleared only by a transition: an alias or shim that emits a `DeprecationWarning` or `FutureWarning` naming a removal version, or a documented migration path. No transition → high, blocking, rating no better than `MAJOR_REVISION` whatever the repair size; state the SemVer consequence (major, minor while 0.x) and the CHANGELOG or migration note owed (a missing entry alone is not blocking). A shim without the warning or removal version → medium. Latest published release: the project's newest published release, or the newest final-release SemVer tag (`X.Y.Z` with an optional leading `v`; pre-release tags such as `rc1` and non-version tags never count) listed by `git tag --sort=-v:refname`, never `git describe`, which returns the nearest tag reachable from the reviewed head; symbols added after it were never released, so a clean removal or rename is acceptable. Other languages: the exported or documented surface.
- `INSUFFICIENT_BUT_PROMISING` names the missing implementation and the useful initiative; `REJECT` cites the requirement the scope cannot fit and whether a different scope could.
- For every proven rejection, put `REJECT`, the specific reason and the decisive evidence in the opening `Verdict` cell. Use `FALSE_GOAL` when verified behavior or a binding specification disproves the proposal's stated premise, and `DUPLICATE` when the full proposed outcome already ships. For other reasons, carry through any recorded reason code and explain why the evidence rules out the proposal.
- For a duplicate PR, use `REJECT` only when the evidence covers the entire proposal and the target project already ships its intended behavior. In `Next action`, recommend that the maintainer close the PR as a duplicate, link to the original merged change or resolved upstream issue, and say what it delivered. Identify any relevant remaining difference and explain why it leaves the outcome unchanged. If the proposed difference adds value or unreviewed earlier commits leave it uncertain, judge the reviewed scope on its own evidence.
- Judge the remaining required work against the PR's own purpose and size: a confirmed finding whose required resolution reverses or removes the PR's central change, or rewrites most of its diff, is a direction conflict and never `MINOR_EDITS`. Use `MAJOR_REVISION` when the aim stands and the approach must change, `INSUFFICIENT_BUT_PROMISING` when most of the delivered work must be replaced. Establish it from a binding contract, documented policy or verified callers, never reviewer preference, and name the intent and reworked share in the rationale. A bounded fix to a small part of a large diff stays Minor; line counts alone never establish a conflict.
- Weigh the affected surface, realistic trigger and consequence before repair size. Finding count, severity labels or reviewer votes alone never choose the level, and many minor findings never dilute one dominant finding.
- A missing check, unavailable reviewer or absent hardware is a coverage limit that lowers confidence, never grounds for `INSUFFICIENT_BUT_PROMISING` or `REJECT`. An inspected scope that stays undecidable is `null`, with its prerequisite and next check.
Report run ID, scope digest, axes run and skipped, findings by severity, coverage limits, and confidence.
Reviewer independence is instruction-enforced: the tools accept a reviewer identity string without authenticating its dispatch session. Report the actual independent reviewer and any unavailable review; never present that string as session attestation.