Copilot Review Code
Review code changes locally before opening a PR. Appends findings to docs/specs/{feature}/review-code.md for cross-model continui…
# Local Code Review
Review code changes locally before opening a PR. Appends findings to `docs/specs/{feature}/review-code.md` for cross-model continuity.
## Input
$ARGUMENTS = Optional. One of:
- A file or directory path to review specific files
- `--staged` to review only staged changes
- `--branch` to review all changes vs main (default)
- `--last` to review only changes since last review commit
## Steps
1. **Determine diff scope**:
- `--branch` (default for first review): `git diff main` — full branch changes
- `--last` (default for re-review in fix loop): `git diff HEAD~{number of fix commits}..HEAD` — only changes since last review
- `--staged`: `git diff --cached`
- File/directory path: `git diff main -- {path}`
- **Auto-detection**: If the most recent commit message starts with `fix:` or contains "fix review", automatically use `--last` mode. Otherwise use `--branch`.
- If the diff is empty, inform the user and stop
2. **Read context**:
- Read `CLAUDE.md` — project standards, banned patterns, architectural decisions
- If a corresponding `docs/specs/{feature}/design.md` exists, read it to understand design intent
- If `docs/specs/{feature}/decisions.md` exists, read it — do not flag intentional decisions as issues
- If `docs/specs/{feature}/review-code.md` exists, read the full history to determine current round number and avoid re-raising resolved issues
3. **Check diff size**:
- Count diff lines: `git diff {scope} | wc -l`
- If **≤ 500 lines**: review the full diff in one pass
- If **> 500 lines**: split by file — get changed file list via `git diff {scope} --name-only`, then review each file's diff individually and aggregate findings
4. **Review the diff**, focusing on:
- **Standards compliance**: violations of CLAUDE.md rules and banned patterns
- **Correctness**: logic errors, missing edge cases, off-by-one errors
- **Regression risk**: changes to code marked with `IMPORTANT: Do not change`
- **Design adherence**: if design.md exists, verify implementation matches
- **Test coverage**: bugfixes without regression tests, new features without tests
- **Security**: hardcoded secrets, injection risks, unsafe input handling
- Do NOT re-raise issues already resolved in review-code.md history
5. **Determine round number**: Count existing `## [Role] Round N` entries in review-code.md, increment by 1.
6. **Append findings to `docs/specs/{feature}/review-code.md`**:
```markdown
## [Role] Round N
### Blocking
1. [file:line] Issue description
2. ...
### Suggestions
1. [file:line] Suggestion description
2. ...
### Looks Good
- Specific things done well (reinforces good patterns)
### Confirmed
- Issue X from previous round is resolved ✅
If docs/specs/{feature}/ does not exist (no design phase was run), create it and create review-code.md now.
If no blocking issues remain, also append the approval marker:
## --- CODE REVIEW APPROVED --- approved_by: [Role] date: {today's date}Output summary to user: Display the round number, blocking issue count, and the path where findings were written. If blocking issues exist, prompt next step:
/copilot-dev "fix review: ...".
Notes
- This is a pre-PR review — no GitHub interaction, no comments posted, purely local
- Use after
/copilot-devand/copilot-checkbut before/copilot-pr - review-code.md is append-only — never modify existing entries
- Do not duplicate what
/copilot-checkalready catches (lint, format, type errors) — focus on logic, design, and regression - decisions.md is the source of truth for intentional implementation choices — read it before flagging something as an issue
Fix Loop
If blocking issues are found, the fix cycle is:
/copilot-dev "fix review: {feature}"
→ reads review-code.md latest round for blocking issues
→ fixes issues + commits locally (no push)
/copilot-review-code
→ auto-detects --last mode from commit message
→ appends Round N+1 to review-code.md
Repeat until CODE REVIEW APPROVED marker is appended, then proceed to /copilot-pr.
In /copilot-flow, this loop runs automatically (max 3 rounds). In manual usage, the user drives each iteration.
```
Maintain Copilot Review Code?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Copilot Review Code on getagentictools](https://getagentictools.com/loops/mattshma-local-code-review?ref=badge)