| name | code-review |
| description | Use when asked to "review code", "review PR", "review diff", "check this PR", "do a code review", or mentions "code review", "PR review", "full diff", "cross-file patterns", "code quality", "review changes". |
Code Review Best Practices
Core Philosophy
Review at PR level, not file-by-file. Focus on egregious structural issues, not minutia. Look for cross-file patterns that indicate architectural problems.
Quick Start
git diff main...HEAD -- . ':!uv.lock' ':!poetry.lock' > /tmp/pr-diff.txt
wc -lc /tmp/pr-diff.txt
git diff main...HEAD -- . ':!uv.lock' ':!docs/*' > /tmp/code-diff.txt
What to Look For - Egregious Issues Only
Quick Checklist
What NOT to Flag
- Variable naming (unless truly confusing)
- Line length
- Comment style
- Whitespace
- Import order
These are auto-fixable or minor. Focus on structural problems.
Critical Rules Quick Reference
def process(data: Any) -> dict:
def process(data: UserData) -> UserResponse:
if hasattr(obj, "name"):
if isinstance(obj, Named):
def process_order(order_data):
validated = _validate(data)
transformed = _transform(validated)
class CacheDirectory:
def list_entries(self): ...
class StatusDirectory:
def get_all_entries(self): ...
Handling Large Diffs
Keep maximum context to spot cross-file patterns.
Step 1: Remove Lock Files (Always)
git diff main...HEAD -- . ':!uv.lock' > /tmp/diff.txt
wc -lc /tmp/diff.txt
Step 2: Remove Docs (If Still Too Big)
git diff main...HEAD -- . ':!uv.lock' ':!docs/*' > /tmp/code-diff.txt
Step 3: Remove Tests (Last Resort)
git diff main...HEAD -- . ':!uv.lock' ':!docs/*' ':!tests/*' > /tmp/prod.txt
Step 4: Chunk with LARGE Chunks (Rare)
LLM-Based Full Diff Review
Why use external LLM tools? Claude Code has a 25K context limit per tool call. For reviewing entire PR diffs (50K-200K+ tokens), use models with larger context windows.
Benefits:
- Cross-file pattern detection in one pass
- Different models catch different issues
- Faster than file-by-file review
Workflow
./scripts/extract-changes.sh
./scripts/extract-changes.sh abc123
./scripts/extract-changes.sh auth/login
./scripts/llm-review.sh -m gpt-4o
./scripts/llm-review.sh -m claude-3-5-sonnet-latest
./scripts/llm-review-tests.sh -m gpt-4o
./scripts/llm-review-types.sh -m gpt-4o
Setup
Requires Simon Willison's llm tool:
pip install llm
llm keys set openai
pip install llm-claude-3
llm keys set claude
See references/llm-tooling.md for full setup and usage guide.
Using LLM Findings
LLM review provides hints, not final answers:
- Identify areas to investigate deeper
- Cross-check with different models
- Use Claude Code to implement actual fixes
Reference Files
For detailed patterns and examples:
Remember: The ENTIRE POINT of full diff review is cross-file patterns. Don't chunk unless you absolutely must!
Human-in-the-Loop After Code Review
CRITICAL: After completing a code review, ALWAYS:
- Present findings - Output the full review report with all sections
- List suggested actions - Number each potential fix
- Ask for approval - Use AskUserQuestion before creating TODOs or executing
- Wait for explicit approval - User may reject, ask for clarification, or approve selectively
Why this matters:
- LLM reviews often suggest unnecessary changes
- Some suggestions may be wrong or over-engineered
- User knows context that LLM doesn't
- Executing without approval wastes time on rejected work
Example flow:
[Code review findings output]
## Suggested Actions
1. Add format-duration validator to Schema
2. Add tests for format-duration validation
3. Move constant to config class
Which items should I proceed with?