Code Review
Perform a thorough code review of the current changes. Act as a senior developer reviewing a pull request.
Steps
Gather changes based on scope:
- If
$ARGUMENTS contains "staged": only git diff --cached
- If
$ARGUMENTS contains "unstaged": only git diff
- If
$ARGUMENTS contains "last-commit": git rev-parse HEAD~1 >/dev/null 2>&1 && git diff HEAD~1 || git diff $(git hash-object -t tree /dev/null) (falls back to the empty tree on a repo's first commit)
- Otherwise: both
git diff and git diff --cached (all pending changes)
- Also run
git status for context
Read full files: For every file that has changes, read the COMPLETE file (not just the diff) to understand the full context around the modifications.
Analyze each change against this checklist:
Logic & Correctness
- Are there logic errors, off-by-one mistakes, or wrong conditions?
- Are edge cases handled (null, undefined, empty arrays, missing fields)?
- Do loops and iterations behave correctly?
- Are return values used correctly?
Security
- Any injection risks (SQL, command, XSS)?
- Is user input validated and sanitized?
- Are there exposed secrets or credentials?
- Are auth checks present where needed?
Data & State
- Are data operations correct (correct methods, field names, query parameters)?
- Is state managed correctly (component state, query cache)?
- Are race conditions possible?
- Is data transformed correctly between layers?
Error Handling
- Are async operations properly awaited?
- Are errors caught where they should be?
- Do error paths leave the app in a consistent state?
- Are failures observable - is the error logged with enough context (ids, operation), and do logs avoid leaking secrets/PII?
Performance
- Any unnecessary re-renders or re-fetches?
- N+1 query problems?
- Large data sets loaded without pagination?
- Missing memoization for expensive computations?
Project Constraints
- Read CLAUDE.md (if it exists) for project-specific constraints and verify changes don't violate them.
Breaking Changes
- Could this change break existing functionality?
- Are API contracts preserved?
- Are backwards-incompatible changes flagged?
- Produce the review report in the following format:
Output Format
For each issue found, report:
[SEVERITY] Category — File:line
Description of the issue and why it matters.
Suggested fix (if applicable).
Severity levels:
- CRITICAL: Bugs, security holes, data corruption risks — must fix before shipping
- WARNING: Potential problems, edge cases, code smells — should fix
- INFO: Minor suggestions, style issues, improvements — nice to have
At the end, provide a Summary with:
- Total issues by severity
- Overall assessment (safe to ship / needs fixes / needs major rework)
- The single most important thing to address
If no issues are found, say so clearly.
$ARGUMENTS
1---2name: review3description: Review code changes for flaws, bugs, security issues, and potential problems4---56# Code Review78Perform a thorough code review of the current changes. Act as a senior developer reviewing a pull request.910## Steps11121. **Gather changes based on scope**:13 - If `$ARGUMENTS` contains "staged": only `git diff --cached`14 - If `$ARGUMENTS` contains "unstaged": only `git diff`15 - If `$ARGUMENTS` contains "last-commit": `git rev-parse HEAD~1 >/dev/null 2>&1 && git diff HEAD~1 || git diff $(git hash-object -t tree /dev/null)` (falls back to the empty tree on a repo's first commit)16 - Otherwise: both `git diff` and `git diff --cached` (all pending changes)17 - Also run `git status` for context18192. **Read full files**: For every file that has changes, read the COMPLETE file (not just the diff) to understand the full context around the modifications.20213. **Analyze each change** against this checklist:2223### Logic & Correctness24- Are there logic errors, off-by-one mistakes, or wrong conditions?25- Are edge cases handled (null, undefined, empty arrays, missing fields)?26- Do loops and iterations behave correctly?27- Are return values used correctly?2829### Security30- Any injection risks (SQL, command, XSS)?31- Is user input validated and sanitized?32- Are there exposed secrets or credentials?33- Are auth checks present where needed?3435### Data & State36- Are data operations correct (correct methods, field names, query parameters)?37- Is state managed correctly (component state, query cache)?38- Are race conditions possible?39- Is data transformed correctly between layers?4041### Error Handling42- Are async operations properly awaited?43- Are errors caught where they should be?44- Do error paths leave the app in a consistent state?45- Are failures observable - is the error logged with enough context (ids, operation), and do logs avoid leaking secrets/PII?4647### Performance48- Any unnecessary re-renders or re-fetches?49- N+1 query problems?50- Large data sets loaded without pagination?51- Missing memoization for expensive computations?5253### Project Constraints54- Read CLAUDE.md (if it exists) for project-specific constraints and verify changes don't violate them.5556### Breaking Changes57- Could this change break existing functionality?58- Are API contracts preserved?59- Are backwards-incompatible changes flagged?60614. **Produce the review report** in the following format:6263## Output Format6465For each issue found, report:6667**[SEVERITY] Category — File:line**68Description of the issue and why it matters.69Suggested fix (if applicable).7071Severity levels:72- **CRITICAL**: Bugs, security holes, data corruption risks — must fix before shipping73- **WARNING**: Potential problems, edge cases, code smells — should fix74- **INFO**: Minor suggestions, style issues, improvements — nice to have7576At the end, provide a **Summary** with:77- Total issues by severity78- Overall assessment (safe to ship / needs fixes / needs major rework)79- The single most important thing to address8081If no issues are found, say so clearly.8283$ARGUMENTS