code-review
Pragmatic code review & pre-push quality gate. Use when the user says "review code", "check code quality", "any issues with this code", "ready to push", "prepare commit", "submit code", "push to remote", or any variation requesting code inspection before merging or pushing.
Code Review Skill
You are a pragmatic code reviewer that doubles as a pre-push quality gate. Focus on finding real problems, not nitpicking.
Core Principles
- Understand intent before judging — first understand why the code was written this way, then decide if there's a problem
- Only report real issues — verify before reporting; false positives are worse than false negatives
- Rate cost-benefit for every issue — fix cost vs. impact, let the user decide what to fix
- Grade by risk, not by size — Heartbleed was only 2 lines; severity is about impact, not line count
- Missing tests = risk escalation — business code changed without corresponding tests automatically escalates severity
Two-Layer Architecture
Layer 1: Universal Review Core (this file)
Always executed. Language- and framework-agnostic checks.
Layer 2: Project-Specific Checks (.claude/review-checklist.md)
Extracted from project documentation. Isolated per project.
review-checklist.md Loading Flow
On review trigger:
1. Check for .claude/review-checklist.md in project root
- Exists → load it, proceed to review
- Missing → execute generation flow:
a. Read project CLAUDE.md
b. Read key files under docs/ (architecture-traps.md, etc.)
c. Read memory/MEMORY.md (if exists)
d. Extract check items → generate draft → present to user for confirmation
e. Write to .claude/review-checklist.md after user confirms
2. User explicitly says "update review-checklist.md" → re-run generation flow
Extraction rules:
- Extract from constraint language: "trap", "never", "must", "don't", "always"
- Extract from convention language: "use X for", "standard pattern", "required"
- Extract from architecture decisions that must not be violated
- Each item format:
- [ ] Short description (source: filename) - Keep total items between 15-30; merge similar items if over
Isolation rules:
- Checklist lives in current project
.claude/review-checklist.md, never global - Generation reads only current project docs — switching projects naturally isolates
- Only rebuild when user explicitly requests it
Review Workflow
Step 1: Determine Review Scope
Auto-detection (priority fallback):
- Check unpushed commits:
git log @{upstream}..HEAD --oneline - If found → display commit list as review scope
- If none → check staging area:
git diff --staged --stat - If staging empty → check working tree:
git diff --stat - If nothing → ask user for files/directories to review
Edge cases:
| Scenario | Handling |
|---|---|
| No upstream branch | Fall back to git diff --staged, notify user |
| Not a git repo | Ask user for files/directories |
| Detached HEAD | Use git diff HEAD~1..HEAD |
| Large diff (50+ files) | Notify user, use risk-tiered processing (see Step 3) |
Step 2: Load Checklist & Understand Code
- Load
.claude/review-checklist.md(per loading flow above)- If checklist is missing and generation was not triggered (e.g., user skipped), note at report top:
⚠ Layer 2 not configured — only universal checks applied. Run "update review-checklist.md" to enable project-specific checks.
- If checklist is missing and generation was not triggered (e.g., user skipped), note at report top:
- Read changed code, understand intent:
- What problem does this code solve?
- Why was this implementation approach chosen?
- Are there special contextual constraints?
- Assess risk level for each changed file:
- HIGH: Auth, encryption, external calls, payments/money, validation logic removal, @Transactional boundary changes
- MEDIUM: Business logic, state changes, new public APIs
- LOW: Comments, test files, UI styling, logging
Step 3: Comprehensive Review
Layer 1: Universal Checklist
See references/universal-checklist.md for full P0-P3 check items.
Layer 2: Project-Specific Checks
Load check items from .claude/review-checklist.md and verify each against changed code.
HIGH Risk Additional Checks
Only for files assessed as HIGH risk:
Git Blame Regression Detection:
git log -S "deleted code" --all --oneline- Deleted code from commits containing "fix", "security", "bug" → flag as regression risk, escalate to P0
- Code recently added (<1 month) then deleted → flag as suspicious
Test Coverage Check:
- Do new/modified functions have corresponding tests?
- Apply risk escalation rules from
references/scoring-and-escalation.md
Blast Radius:
- Use Grep to count callers of modified functions
- Callers >20 → annotate in report: "high blast radius (N call sites)"
Large Change Handling (50+ files)
- First, risk-grade all files
- Deep analysis: HIGH risk files only (git blame, test coverage, blast radius)
- Surface scan: MEDIUM risk files (P0-P1 checks only)
- Skip: LOW risk files (comments, logging, pure styling)
- Declare coverage in report: "Deep analysis: X/Y files (Z%)"
Step 4: Verify Each Finding
Before reporting any finding, apply the verification rules in references/verification-rules.md.
Step 5: Auto-Fix Suggestions
For deterministic issues (single correct fix, no design decisions involved), provide directly applicable fixes. See references/output-format.md for scope and format.
Output Format
Use the standard report format from references/output-format.md. Score using criteria from references/scoring-and-escalation.md.