Smart Code Review
Perform thorough, actionable code reviews on git changes. Catches real bugs and security issues, not just style nits.
When to Activate
- User asks to review code changes
- User says
/smart-review or "review my code" or "check this PR"
- User wants feedback before committing or merging
Instructions
Step 1: Determine Review Scope
Identify what to review based on user context:
# Option A: Review uncommitted changes
git diff --stat
git diff
# Option B: Review staged changes
git diff --cached --stat
git diff --cached
# Option C: Review branch vs base (PR review)
BASE_BRANCH="${1:-main}"
git log --oneline "$BASE_BRANCH"..HEAD
git diff --stat "$BASE_BRANCH"..HEAD
git diff "$BASE_BRANCH"..HEAD
# Option D: Review a specific commit
git show --stat <commit>
git show <commit>
If no changes are found, inform the user and stop.
For large diffs (>500 lines changed), read key files individually rather than relying solely on the diff — context from surrounding code matters.
Step 2: Analyze for Issues
Review the diff systematically, checking each category:
Critical (Must Fix)
- Bugs: Logic errors, off-by-one, null/undefined access, race conditions, infinite loops
- Security: SQL injection, XSS, command injection, hardcoded secrets, path traversal, insecure deserialization
- Data loss: Destructive operations without confirmation, missing error handling on writes, uncaught exceptions that could corrupt state
Important (Should Fix)
- Error handling: Missing try/catch on I/O, swallowed errors, generic catch blocks that hide failures
- Edge cases: Empty arrays, null inputs, boundary values, concurrent access, timeout handling
- API contracts: Breaking changes to public interfaces, missing validation on inputs, inconsistent return types
- Resource management: Unclosed connections, memory leaks, missing cleanup in finally blocks
Suggestions (Consider)
- Performance: N+1 queries, unnecessary re-renders, large allocations in hot paths, missing indexes
- Maintainability: Complex conditionals that could be simplified, duplicated logic, unclear variable names
- Testing: Untested code paths, assertions that don't verify the right thing, flaky test patterns
- Design: Tight coupling, mixed responsibilities, patterns that will cause pain as the codebase grows
Step 3: Read Surrounding Context
For each potential issue found in Step 2, read the full file to verify:
# Don't flag something as a bug if the surrounding code handles it
# Don't flag a "missing null check" if the caller guarantees non-null
# Don't flag a performance issue if the data set is always small
Key principle: Only flag issues you're confident about. A false positive wastes the developer's time and erodes trust. When in doubt, phrase it as a question rather than a finding.
Step 4: Generate Review
Organize findings by severity. Use this template:
## Code Review
**Scope**: [what was reviewed — branch, commits, or staged changes]
**Files**: [number] files, [additions] insertions(+), [deletions] deletions(-)
### Critical
> [file:line] **Issue title**
>
> [Explanation of the problem and its impact]
>
> ```diff
> - [current code]
> + [suggested fix]
> ```
### Important
> [file:line] **Issue title**
>
> [Explanation and suggestion]
### Suggestions
> [file:line] **Issue title**
>
> [Explanation and suggestion]
### What Looks Good
- [Positive callout — something done well]
- [Another positive callout]
### Summary
**Verdict**: Ready to merge / Needs minor fixes / Needs rework
[1-2 sentence overall assessment explaining the verdict]
Step 5: Present and Discuss
- Show the review to the user
- Offer to fix any Critical or Important issues directly
- If reviewing a PR, offer to post the review as a comment via
gh pr review
Review Principles
- Be specific: "This could fail when X is null" > "Consider null checks"
- Explain impact: "This SQL is injectable, allowing data exfiltration" > "Security issue"
- Suggest fixes: Show code, not just descriptions. Make it easy to act on.
- Acknowledge good work: Call out clean patterns, good test coverage, clever solutions
- Respect intent: Understand what the developer was trying to do before suggesting alternatives
- Prioritize: A review with 3 real issues beats one with 30 style nits
- Skip the obvious: Don't flag formatting, naming conventions, or import ordering unless they cause actual confusion
Severity Guide
| Severity |
Criteria |
Examples |
| Critical |
Will cause bugs, security holes, or data loss in production |
SQL injection, uncaught exception in payment flow, race condition on shared state |
| Important |
Could cause problems under certain conditions, or makes future bugs likely |
Missing error handling on network call, breaking API change without migration |
| Suggestion |
Improvement that would make the code better but isn't urgent |
Extracting a helper function, adding an index, simplifying a conditional |
Edge Cases
- Trivial changes (typos, formatting): Skip the formal review format, just confirm it looks good
- Generated code (migrations, lockfiles): Note that it's generated and focus only on the generator config
- Dependency updates: Check the changelog for breaking changes, verify version constraints
- Large refactors: Focus on the design rather than line-by-line — does the new structure make sense?
- First contribution: Be extra welcoming. Suggest improvements gently and acknowledge the effort
1---2name: smart-review3description: Performs thorough code review on git changes. Analyzes diffs for bugs, security issues, performance problems, and design concerns. Produces actionable feedback organized by severity. Use when reviewing code, checking a PR, or when the user says /smart-review.4license: MIT5---67# Smart Code Review89Perform thorough, actionable code reviews on git changes. Catches real bugs and security issues, not just style nits.1011## When to Activate1213- User asks to review code changes14- User says `/smart-review` or "review my code" or "check this PR"15- User wants feedback before committing or merging1617## Instructions1819### Step 1: Determine Review Scope2021Identify what to review based on user context:2223```bash24# Option A: Review uncommitted changes25git diff --stat26git diff2728# Option B: Review staged changes29git diff --cached --stat30git diff --cached3132# Option C: Review branch vs base (PR review)33BASE_BRANCH="${1:-main}"34git log --oneline "$BASE_BRANCH"..HEAD35git diff --stat "$BASE_BRANCH"..HEAD36git diff "$BASE_BRANCH"..HEAD3738# Option D: Review a specific commit39git show --stat <commit>40git show <commit>41```4243If no changes are found, inform the user and stop.4445For large diffs (>500 lines changed), read key files individually rather than relying solely on the diff — context from surrounding code matters.4647### Step 2: Analyze for Issues4849Review the diff systematically, checking each category:5051#### Critical (Must Fix)52- **Bugs**: Logic errors, off-by-one, null/undefined access, race conditions, infinite loops53- **Security**: SQL injection, XSS, command injection, hardcoded secrets, path traversal, insecure deserialization54- **Data loss**: Destructive operations without confirmation, missing error handling on writes, uncaught exceptions that could corrupt state5556#### Important (Should Fix)57- **Error handling**: Missing try/catch on I/O, swallowed errors, generic catch blocks that hide failures58- **Edge cases**: Empty arrays, null inputs, boundary values, concurrent access, timeout handling59- **API contracts**: Breaking changes to public interfaces, missing validation on inputs, inconsistent return types60- **Resource management**: Unclosed connections, memory leaks, missing cleanup in finally blocks6162#### Suggestions (Consider)63- **Performance**: N+1 queries, unnecessary re-renders, large allocations in hot paths, missing indexes64- **Maintainability**: Complex conditionals that could be simplified, duplicated logic, unclear variable names65- **Testing**: Untested code paths, assertions that don't verify the right thing, flaky test patterns66- **Design**: Tight coupling, mixed responsibilities, patterns that will cause pain as the codebase grows6768### Step 3: Read Surrounding Context6970For each potential issue found in Step 2, read the full file to verify:7172```bash73# Don't flag something as a bug if the surrounding code handles it74# Don't flag a "missing null check" if the caller guarantees non-null75# Don't flag a performance issue if the data set is always small76```7778**Key principle**: Only flag issues you're confident about. A false positive wastes the developer's time and erodes trust. When in doubt, phrase it as a question rather than a finding.7980### Step 4: Generate Review8182Organize findings by severity. Use this template:8384```markdown85## Code Review8687**Scope**: [what was reviewed — branch, commits, or staged changes]88**Files**: [number] files, [additions] insertions(+), [deletions] deletions(-)8990### Critical9192> [file:line] **Issue title**93>94> [Explanation of the problem and its impact]95>96> ```diff97> - [current code]98> + [suggested fix]99> ```100101### Important102103> [file:line] **Issue title**104>105> [Explanation and suggestion]106107### Suggestions108109> [file:line] **Issue title**110>111> [Explanation and suggestion]112113### What Looks Good114115- [Positive callout — something done well]116- [Another positive callout]117118### Summary119120**Verdict**: Ready to merge / Needs minor fixes / Needs rework121122[1-2 sentence overall assessment explaining the verdict]123```124125### Step 5: Present and Discuss1261271. Show the review to the user1282. Offer to fix any Critical or Important issues directly1293. If reviewing a PR, offer to post the review as a comment via `gh pr review`130131## Review Principles1321331. **Be specific**: "This could fail when X is null" > "Consider null checks"1342. **Explain impact**: "This SQL is injectable, allowing data exfiltration" > "Security issue"1353. **Suggest fixes**: Show code, not just descriptions. Make it easy to act on.1364. **Acknowledge good work**: Call out clean patterns, good test coverage, clever solutions1375. **Respect intent**: Understand what the developer was trying to do before suggesting alternatives1386. **Prioritize**: A review with 3 real issues beats one with 30 style nits1397. **Skip the obvious**: Don't flag formatting, naming conventions, or import ordering unless they cause actual confusion140141## Severity Guide142143| Severity | Criteria | Examples |144|----------|----------|---------|145| Critical | Will cause bugs, security holes, or data loss in production | SQL injection, uncaught exception in payment flow, race condition on shared state |146| Important | Could cause problems under certain conditions, or makes future bugs likely | Missing error handling on network call, breaking API change without migration |147| Suggestion | Improvement that would make the code better but isn't urgent | Extracting a helper function, adding an index, simplifying a conditional |148149## Edge Cases150151- **Trivial changes** (typos, formatting): Skip the formal review format, just confirm it looks good152- **Generated code** (migrations, lockfiles): Note that it's generated and focus only on the generator config153- **Dependency updates**: Check the changelog for breaking changes, verify version constraints154- **Large refactors**: Focus on the design rather than line-by-line — does the new structure make sense?155- **First contribution**: Be extra welcoming. Suggest improvements gently and acknowledge the effort