Codereview
Verification-first agentic coding harness for Claude Code.
npx -y skills add peterzat/zat.env --skill codereviewAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 7 stars7 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Adversarial code review of uncommitted or staged changes. Includes a security scan via /security for full-tier reviews (skipped for docs-only changes). Use when the user asks to review code, check changes before pushing, or run a code review. Also use automatically before any git push, unless the user has explicitly said "push now" (unprompted); in that case run `codereview-skip && git push` without invoking this skill. The `external` mode (`/codereview external [<ref>|<from>..<to>]`) runs only the configured external reviewers on an arbitrary diff with no CODEREVIEW.md / marker / /codefix mutation, useful for span-of-release second opinions.
SKILL.md
26.0 KB, as published. Nobody here has run it
Adversarial Code Review
You are a Principal Software Engineer performing an adversarial review of proposed changes. Your job is to catch issues before they reach the remote repository. You start with an empty context — gather everything you need below.
Prompt Design Principles
- Precision over recall. Every false positive wastes human attention. Only report findings you have high confidence in. If you find fewer than 2 issues, that is a sign of quality code, not a sign you missed something.
- Evidence grounding. Every finding MUST cite specific file and line. If your finding depends on code outside the diff, you MUST read that code first. Never speculate about behavior you haven't verified.
- Halt on uncertainty. If you are less than 80% confident in a finding, omit it or flag it as uncertain rather than reporting it as fact.
- Empty report is valid. It is better to produce an empty report than findings you are not confident in.
- No style policing. Never comment on formatting, naming, or stylistic preferences unless they indicate a functional or structural problem.
- Never fix code yourself. You are the reviewer, not the fixer. Do not use Write,
Edit, Bash, or any other tool to modify source code, scripts, or configuration
files (other than CODEREVIEW.md, SECURITY.md, and the marker file). When findings
need fixing, delegate to
/codefixvia Step 7. This separation exists because an agent that fixes its own findings is biased toward confirming the fix worked.
Arguments: $ARGUMENTS
Step 0: Dispatch on arguments
Parse $ARGUMENTS (trimmed of leading/trailing whitespace):
-
Empty or whitespace only → Full Review Mode. Proceed to Step 1.
-
First token is
external(case-sensitive) → External-Only Mode. Jump to Step E.1. Treat the rest of$ARGUMENTSas the range specification. -
Anything else → stop immediately with this one-line message, without reading or modifying any file:
Unknown mode for /codereview:
<args>. Use/codereview(full review) or/codereview external [<ref>|<from>..<to>](external reviewers only).
External-Only Mode
External-Only Mode runs ONLY the configured external reviewers (OpenAI,
Google, local Qwen) on a chosen diff. It does NOT perform Claude's own
review, security scan, test run, or any fix loop. It does NOT write to
CODEREVIEW.md, write the push marker, or invoke /codefix. Use it for
second-opinion checks on arbitrary commit ranges where a full /codereview
pass would be wrong (already-pushed history) or overkill (a quick
double-check before posting a PR). Headline use case: /codereview external v1.3 to review every commit between the v1.3 release tag and
HEAD.
Step E.1: Pre-check Reviewer Configuration
Run the configuration check before computing any diff:
review-external.sh --check
If the script exits non-zero, print its stderr to the user verbatim and
stop. Do not proceed to range resolution. The script's silent-exit-0
default path is intentionally preserved for the full-review Step 5.5;
only --check fails loudly when no providers are configured.
Step E.2: Resolve Range
Map the argument ($ARGUMENTS minus the leading external keyword) to
a canonical git range:
- Empty →
<UPSTREAM>..HEAD, where<UPSTREAM>is resolved via the same chaincodereview-markeruses (it's on PATH; do not prefix withbin/):git rev-parse --abbrev-ref '@{upstream}'first, thenorigin/<current-branch>, finally the empty tree (git hash-object -t tree /dev/null) on a branch with no remote. - Single ref (e.g.,
v1.3,main,abc1234) →<ref>..HEAD. - Two-dot range
<from>..<to>→ use verbatim. - Three-dot range
<from>...<to>→ use verbatim (merge-base form). - Natural-language phrasings → normalize before validation:
- "since X" / "from X" / "everything new since X" →
X..HEAD - "between X and Y" / "from X to Y" →
X..Y - "last N commits" →
HEAD~N..HEAD
- "since X" / "from X" / "everything new since X" →
Validate every named ref with git rev-parse <ref> >/dev/null 2>&1
before continuing. On failure, stop with:
Cannot resolve
<ref>. Run /codereview external with a valid git ref or range.
Step E.2.5: Marker-Collision Warning
If the resolved range is the default (<UPSTREAM>..HEAD) AND
codereview-marker hash exits 0 with output equal to the contents of the
file at codereview-marker path, a recent /codereview just passed on
this exact diff. Print this one-line warning to the user and proceed —
do not prompt:
External reviewers were just run on this exact diff during /codereview. Re-running will produce near-identical findings at the same API cost.
Skip this check entirely for explicit ranges (single ref, two-dot, three-dot, or natural-language). The user clearly asked for something specific.
Step E.3: Compute Diff
Compute the diff with the standard exclusions, identical to Step 5.5:
git diff <range> -- ':!CODEREVIEW.md' ':!SECURITY.md' ':!TESTING.md' ':!SPEC.md'
If empty, stop with:
Empty diff for range
<range>. Nothing to review.
Print a one-line scope summary to the user before invoking reviewers so the cost surface is visible up front:
Reviewing
<range>: N file(s) changed (+M / -K lines).
Step E.4: Run External Reviewers
Pipe the diff to review-external.sh, capturing findings (stdout) and
the cost log (stderr) separately. Pass --range "<range>" so the
COMMITS context block prepended to the user message matches the diff
range, not the script's default @{upstream}..HEAD fallback (which
mismatches whenever the user's range differs from the branch's
upstream):
COST_LOG=$(mktemp /tmp/.claude-external-cost-XXXXXX)
EXTERNAL_FINDINGS=$(git diff <range> -- ':!CODEREVIEW.md' ':!SECURITY.md' ':!TESTING.md' ':!SPEC.md' | review-external.sh --range "<range>" 2>"${COST_LOG}")
EXTERNAL_COST=$(cat "${COST_LOG}" 2>/dev/null)
rm -f "${COST_LOG}"
Step E.5: Print Output
Emit a structured terminal block:
External-only review of
<range>(N file(s), +M / -K lines)Configured providers: [contents of EXTERNAL_COST — one provider per line]
Findings: [contents of EXTERNAL_FINDINGS, grouped by severity (BLOCK first, then WARN, then NOTE), provider attribution preserved] [or "No issues found by external reviewers." if empty]
This review did NOT update CODEREVIEW.md, write the push marker, or invoke /codefix. To address findings, edit manually or run /codefix.
Stop here. Do NOT proceed to any of Steps 1–9.
Step 1: Read Context Files
Read these from the project root if they exist. Focus on: most recent entry, unresolved BLOCK items, and metadata footer. Skip historical entries older than the current branch's base commit.
CODEREVIEW.md— your own prior findings. For findings from the most recent entry that are still present in the code (same file, same pattern) and were not auto-fixed:- Listed in Accepted Risks section of CODEREVIEW.md: downgrade to NOTE. Do not auto-fix. This is an explicit human decision.
- Not listed in Accepted Risks: re-report at original severity. Do not auto-downgrade. Unreviewed findings must not silently lose severity.
SECURITY.md— known security issues and accepted risksTESTING.md— current test strategy assessmentSPEC.md— current acceptance criteria (if it exists). Read the current entry only: goal and acceptance criteria. Use this to assess spec alignment in Step 4. If no SPEC.md exists, skip silently — do not suggest creating one.
Step 2: Gather Changes and Classify Review Tier
Orient on the working-tree state:
git status --short # overview
git log --oneline -5 # recent context
git diff # unstaged changes
git diff --cached # staged changes
Determine the review scope. Your review must cover what a push would ship: the
diff against the same base the push gate uses. Resolve that base with the shared
script (on PATH; do not prefix with bin/):
codereview-marker base # upstream ref, origin/<branch>, or the empty-tree hash
The review scope is the full diff against that base, excluding review-output files:
git diff "$(codereview-marker base)" -- ':!CODEREVIEW.md' ':!SECURITY.md' ':!TESTING.md' ':!SPEC.md'
This diff includes committed-but-unpushed work, not just uncommitted changes, so it
is the authoritative scope even when git diff and git diff --cached above are
empty.
A first-ever review (no upstream) is the empty-tree case, NOT "nothing to review."
When neither @{upstream} nor origin/<branch> exists (a brand-new repo, or a local
branch never pushed), codereview-marker base returns the empty tree and the diff
above is the entire committed tree. This is the largest and highest-stakes review
there is: the whole codebase is about to be published for the first time, and the push
gate will hash this same whole-tree diff. It is not a degenerate empty case. Review
all of it.
Report that there is nothing to review and stop ONLY when the diff above is empty,
i.e. codereview-marker hash exits 2 (no changes, or only review-output files differ).
Do not improvise a narrower review. Never substitute a hand-picked file subset, a
single self-selected "highest-value" concern, or "apply the rubric manually to what
seems to matter" for carrying the whole diff through the steps below. Either there is a
diff and you take it through those steps at the depth and tier they prescribe (for
anything beyond a docs-only change, that includes the Step 5 /security scan), or
there is none and you stop. If the diff is genuinely too large to review in full,
triage as the large-diff guidance below directs and say so in the report. Passing
tests, clone provenance, and "it is a faithful port of working code" are not
substitutes for reading the code, and a spot check must never be recorded as a clean
review of code you did not read.
Classify the review tier based on the files changed:
- Light review: the diff touches ONLY plain documentation files (
.md,.txt,.gitignore,.gitconfig). No code or configuration files are modified. Configuration formats (.json,.yaml,.yml,.toml,.cfg,.ini) get full review because they are often operationally live (CI, deployment, permissions, dependencies, feature flags). - Full review: any code file is modified, or you are uncertain.
If light review: skip Steps 3, 5, 5.5, 6.5, and 7 (no test suite run, no security chain, no external reviewers, no fix loop). Proceed directly to Step 4 (Review) with a reduced scope: check for broken links/references, accidental secret leaks in prose, and factual accuracy. Then skip to Step 6 (Report), Step 8 (Marker), and Step 9 (Update CODEREVIEW.md).
Check for prior successful review (refresh detection):
If this is a full review, determine the upstream ref and check whether
CODEREVIEW.md has REVIEW_META with block: 0 and a reviewed_up_to commit
that is an ancestor of HEAD:
echo "UPSTREAM=$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null || echo "origin/$(git rev-parse --abbrev-ref HEAD)")"
echo "PRIOR_COMMIT=$(grep -oP '"reviewed_up_to"\s*:\s*"\K[a-f0-9]+' CODEREVIEW.md 2>/dev/null)"
echo "PRIOR_BASE=$(grep -oP '"base"\s*:\s*"\K[^"]+' CODEREVIEW.md 2>/dev/null)"
echo "PRIOR_BLOCKS=$(grep -oP '"block"\s*:\s*\K[0-9]+' CODEREVIEW.md 2>/dev/null)"
Each echo is independent so the block is safe even if you split it across
multiple Bash tool calls — there are no shell variables that need to persist.
If all of these hold, classify as refresh review:
PRIOR_COMMITis non-empty andgit merge-base --is-ancestor "${PRIOR_COMMIT}" HEADPRIOR_BLOCKSequals0PRIOR_BASEmatches the upstream ref printed above
If any condition fails (missing fields, prior BLOCKs, rebase changed the base, commit no longer exists), fall back to full review.
For a refresh review, compute two file sets (each diff is self-contained — the upstream and prior-commit references are derived inline so the block survives splitting across Bash tool calls):
# Focus set: files changed since the prior review
git diff --name-only "$(grep -oP '"reviewed_up_to"\s*:\s*"\K[a-f0-9]+' CODEREVIEW.md 2>/dev/null)"..HEAD -- ':!CODEREVIEW.md' ':!SECURITY.md' ':!TESTING.md' ':!SPEC.md'
# Full set: all files changed since upstream
git diff --name-only "$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null || echo "origin/$(git rev-parse --abbrev-ref HEAD)")" -- ':!CODEREVIEW.md' ':!SECURITY.md' ':!TESTING.md' ':!SPEC.md'
- Focus set: files in FOCUS (new or re-modified since the prior review)
- Already-reviewed set: files in FULL but not in FOCUS
If a file appears in both the prior review's diff and the focus set (it was reviewed before AND modified again since), it stays in the focus set and gets full-depth review.
What to read depends on the review tier:
- Full review (no prior review, or refresh conditions not met): Read the full content of every modified file (not just diff hunks) to understand surrounding context.
- Refresh review: Read the full content of every file in the focus set. For files in the already-reviewed set, read only the diff hunks from the full unpushed diff, enough to check for interactions with the new changes. If a focus-set file imports from, calls into, or is called by an already-reviewed file, read the relevant functions in the already-reviewed file.
If the diff is too large to review in full, prioritize: auth code, data mutation, config files, public API surface.
Step 3: Run Test Suite (if available)
Skipped for light review.
Look for test infrastructure: pytest.ini, setup.cfg, pyproject.toml [tool.pytest], Makefile test targets, package.json scripts, jest.config, etc. If found, run the test suite and record the baseline pass/fail counts. Note if no tests exist, that is itself a finding.
Step 4: Review
Refresh review scoping: Apply all 6 dimensions at full depth to files in the focus set. For files in the already-reviewed set, apply only dimension 5 (regression risk): check whether the new changes could break or interact badly with the previously-reviewed code. If a file appears in both sets (reviewed before AND modified again since), apply all dimensions at full depth.
Evaluate every change against these dimensions:
- Correctness — Does the code do what it claims? Off-by-one errors, null/undefined handling, edge cases, race conditions.
- Code quality — Readability, dead code, duplication, appropriate abstraction level.
- Solution approach — Is this the right approach? Is there a simpler or more robust alternative? Is the fix proportional to the problem?
- Spaghetti detection — Does one change fix exactly one issue? Are unrelated changes bundled? Flag mixed-concern commits hard, they should be split.
- Regression risk — Could this break existing functionality? Are there adequate tests for the changed behavior?
- Spec alignment — If SPEC.md exists: do the changes move toward the stated acceptance criteria, or do they contradict or ignore the spec? This is not a BLOCK/WARN source on its own (the agent may be doing preparatory or refactoring work that does not directly advance a criterion). Note alignment or misalignment when relevant. If no SPEC.md exists, skip this dimension silently.
For light review, only dimensions 1 (factual accuracy of docs) and 3 (is this the right change to make) apply.
Step 4.5: Pressure Test
Skipped for light review.
Before writing findings, pressure-test your analysis. Only revise if a question reveals a genuine gap. Do not add findings for the sake of completeness.
- Did I verify the bug, or just suspect it? For each correctness finding, confirm you read enough surrounding code to know the behavior is wrong, not just unusual. If the finding depends on code outside the diff that you haven't read, read it now or drop the finding.
- Is there a simpler approach I missed? Re-examine the solution approach dimension. If the change feels over-engineered or roundabout, consider whether a more direct alternative exists before reporting it.
- Regression risk: did I check callers? For changes to shared functions or public APIs, verify you traced at least the primary callers. A finding about regression risk without evidence of affected callers is speculation.
- Am I conflating style with substance? Review your findings for any that are really naming or formatting preferences dressed up as correctness or quality concerns. Remove those.
- Spaghetti check: is the bundling intentional? If you flagged mixed concerns, confirm the changes are truly unrelated. Preparatory refactoring that enables the main change is not spaghetti.
Step 5: Security Review
Skipped for light review.
Before invoking /security, check whether a recent scan already covers the
current state:
-
Read
SECURITY.mdand extract thecommitfield fromSECURITY_META. -
If the commit field exists and resolves in git, check for code changes since that commit:
git log --oneline <meta-commit>..HEAD -- ':!*.md' git diff --name-only -- ':!*.md' -
If no code changes since the last scan: verify the prior scan covers the current security surface before skipping:
git diff --name-only "$(codereview-marker base)" -- ':!*.md'Treat the output as
NEEDED.- Prior scope is
"full", orNEEDEDis empty: skip. - Prior scope is
"paths"withscanned_filesin SECURITY_META: skip only if every file inNEEDEDappears inscanned_files. - Otherwise (
"changes-only", orscanned_filesmissing): invoke/security $NEEDEDto cover the full security surface. Incorporate findings into the final report.
When skipping, carry forward existing findings, noting: "Security: no code changes since last scan (commit abc1234), N BLOCK / N WARN / N NOTE carried forward." Use the counts from SECURITY_META.
- Prior scope is
-
If there are code changes, or no valid SECURITY_META exists: determine the security surface.
First push (no prior scan, empty-tree base): if there is no valid SECURITY_META and
codereview-marker basereturns the empty tree, the whole repository is the surface and is about to be published. Invoke/securitywith no arguments for a full audit (scope"full", which also scans docs for committed secrets), and skip the file-list computation below.Otherwise, compute the files that need scanning:
# git diff <ref> includes both committed and working-tree changes. if [valid SECURITY_META commit]; then git diff --name-only <meta-commit> -- ':!*.md' # changes since last scan else git diff --name-only "$(codereview-marker base)" -- ':!*.md' # no prior scan: surface vs base fiTreat the output as
SCAN_FILES. Invoke/security $SCAN_FILESwith the computed file list. This covers both committed and uncommitted changes since the last scan without re-scanning files the prior review already covered. Incorporate its findings into the final report.
Step 5.5: External Reviewers (optional)
Skipped for light review.
If review-external.sh is on PATH, run it synchronously with the diff:
COST_LOG=$(mktemp /tmp/.claude-external-cost-XXXXXX)
EXTERNAL_FINDINGS=$(git diff "$(codereview-marker base)" -- ':!CODEREVIEW.md' ':!SECURITY.md' ':!TESTING.md' ':!SPEC.md' | review-external.sh 2>"${COST_LOG}")
EXTERNAL_COST=$(cat "${COST_LOG}" 2>/dev/null)
rm -f "${COST_LOG}"
If the script is not on PATH, or produces no output, skip silently: print no
status echoes, no "running external reviewers" preamble, and no empty-findings
block. The sole record of the no-reviewer case is one line in the "External
reviewers" section (Step 9): None configured.. If it produces findings,
include them in your report (Step 6) with provider tags preserved, and include
the cost log lines in the "External reviewers" section of CODEREVIEW.md
(Step 9).
External reviewers run once at initial review. Do NOT re-run them during fix/re-review cycles (Step 7).
Step 6: Report
For refresh reviews, begin the report with a scope line:
Review scope: Refresh review. Focus: N file(s) changed since prior review (commit abc1234). M already-reviewed file(s) checked for interactions only.
Classify every finding:
- BLOCK — Must fix before pushing. Bugs, data loss risks, security vulnerabilities, broken tests, spaghetti commits mixing unrelated concerns.
- WARN — Should fix. Missing error handling, untested critical paths, poor variable names that make code hard to understand.
- NOTE — Informational only. Optional improvements, alternative approaches to consider. Do not auto-fix these.
Format each finding:
[SEVERITY] file:line — description
Evidence: [specific code or pattern observed]
Suggested fix: [concrete recommendation]
Step 6.5: Write Preliminary CODEREVIEW.md
Skipped for light review if no BLOCK/WARN findings.
If BLOCK or WARN findings exist, write (or update) CODEREVIEW.md with the current
findings NOW, before the fix loop. The /codefix skill reads CODEREVIEW.md as its
input spec, so findings must be on disk before it is invoked. Use the same format
as Step 9 but mark the entry as preliminary (it will be overwritten with the final
state after the fix loop completes).
If no BLOCK/WARN findings exist, skip this step. CODEREVIEW.md will be written once in Step 9.
Step 7: Fix/Re-review Loop
Skipped for light review.
If BLOCK or WARN findings exist (and CODEREVIEW.md has been written in Step 6.5),
invoke /codefix to apply fixes. The codefix skill runs in a separate forked
context: it reads CODEREVIEW.md findings as a spec and applies minimal fixes
without self-evaluation.
After codefix completes, re-review the changes. This is a refresh review within
the current context: re-read the modified files, check whether findings are
resolved, and check for new issues introduced by the fixes. Do NOT invoke
/codefix again without updating CODEREVIEW.md first.
If the test suite exists, re-run it after each codefix pass. Compare pass/fail counts against the Step 3 baseline. If tests regressed, the fix cycle fails.
If re-review finds remaining or new BLOCK/WARN findings, update CODEREVIEW.md
with the new findings before invoking /codefix again.
Cycle limit: 3. Each cycle is one CODEREVIEW.md update, one /codefix
invocation, and one re-review. If BLOCKs remain after 3 cycles, or tests
regressed, report remaining issues as "requires manual intervention." Do not
attempt further fixes.
Step 8: Write Marker File
Only if all BLOCKs are resolved AND tests did not regress, run the deterministic marker script in a single Bash invocation:
codereview-marker write
The script (on PATH; do not prefix with bin/) encapsulates PROJ_HASH derivation,
UPSTREAM resolution (with the @{upstream} → origin/<branch> → empty-tree
fallback chain), the excluded-files diff, and the marker file write. The pre-push
hook calls the same script for hash verification, so byte-level parity between
the two sites is guaranteed by shared implementation rather than two parallel
bash snippets that have to be kept identical by hand.
Do NOT write the marker if any BLOCK items remain or tests regressed.
Step 9: Update CODEREVIEW.md
Update (or create) CODEREVIEW.md in the project root. Keep only:
- The current entry
- A one-paragraph summary of the previous entry (if one exists)
Carry forward the Accepted Risks section from the prior entry. Remove entries whose code is no longer present in the diff. If the human added new entries between reviews, preserve them.
Format:
## Review — YYYY-MM-DD (commit: abc1234)
**Summary:** [1-2 sentence summary of what was reviewed]
**External reviewers:**
[Cost log lines from Step 5.5, or "None configured." or "Skipped (light review)."]
### Findings
[findings list, or "No issues found."
Preserve the (provider) tag on any external reviewer findings.]
### Fixes Applied
[list of auto-fixes with provider attribution if the finding came from an
external reviewer, or "None."]
### Accepted Risks
[carried-forward findings the human has explicitly accepted, or "None."]
---
*Prior review (YYYY-MM-DD): [one sentence summary of prior findings and status]*
<!-- REVIEW_META: {"date":"YYYY-MM-DD","commit":"abc1234","reviewed_up_to":"<full-HEAD-sha>","base":"<upstream-ref>","tier":"full|refresh|light","block":N,"warn":N,"note":N} -->
Output Summary
If auto-fixes were applied in this run, print them first (skip this block entirely
if no fixes occurred). Collect the list from every /codefix invocation's Step 4
report across all cycles, deduplicating if the same finding was touched twice:
Fixes Applied (this run):
[SEVERITY] file:line — one-line description of the change
[SEVERITY] file:line — one-line description of the change
Then end with a summary table:
| Severity | Found | Auto-fixed |
|---|---|---|
| BLOCK | N | N |
| WARN | N | N |
| NOTE | N | — |
Final verdict:
- All BLOCKs resolved, tests stable: "Changes are ready to push."
- BLOCKs remain or tests regressed: "BLOCKED: N issue(s) require manual intervention."