/review
/review - Code Review Command
Section titled “/review - Code Review Command”Purpose
Section titled “Purpose”Comprehensive code review that analyzes quality, security, performance, and maintainability. Acts as an automated code reviewer that checks for issues across multiple dimensions before code reaches production.
/review [file path | 'staged' | 'pr' | PR number]Arguments
Section titled “Arguments”[file path]- Review specific file(s), supports glob patternsstaged- Review all staged changes (git diff --staged)pr- Review current branch changes vs main[PR number]- Review specific pull request from GitHub
How It Works
Section titled “How It Works”The /review command executes a comprehensive 5-phase review process:
Phase 1: Identify Review Scope
Section titled “Phase 1: Identify Review Scope”-
Determine What to Review
- Single file: Reads the specified file
staged: Gets staged changes withgit diff --stagedpr: Gets branch diff withgit diff main...HEAD- PR number: Fetches PR details with
gh pr view
-
Gather Context
- Understands the purpose of changes
- Checks related tests
- Reviews CLAUDE.md for project standards
Phase 2: Code Quality Review
Section titled “Phase 2: Code Quality Review”Checks each file for:
-
Correctness
- Logic errors and bugs
- Edge case handling
- Null/undefined safety
- Type correctness
-
Clarity
- Clear naming (variables, functions, classes)
- Readable structure
- Appropriate comments
- Self-documenting code
-
Consistency
- Follows project conventions
- Matches existing patterns
- Style guide compliance
-
Complexity
- Function length (prefer <30 lines)
- Cyclomatic complexity
- Nesting depth
Phase 3: Security Review
Section titled “Phase 3: Security Review”Checks for security issues:
-
Input Validation
- User input sanitization
- Type validation
- Size/length limits
-
Authentication/Authorization
- Proper auth checks
- Role-based access control
- Session management
-
Data Protection
- Sensitive data handling
- Encryption where needed
- PII protection
-
Injection Prevention
- SQL injection
- XSS vulnerabilities
- Command injection
-
Secrets
- No hardcoded credentials
- No API keys in code
- Proper env var usage
Phase 4: Performance Review
Section titled “Phase 4: Performance Review”Checks for performance issues:
-
Algorithmic Efficiency
- Time complexity
- Unnecessary loops
- Redundant operations
-
Memory Usage
- Large object creation
- Memory leaks
- Unbounded caches
-
Database
- N+1 queries
- Missing indexes
- Large result sets
-
Async Operations
- Proper async/await
- Parallel where possible
- Timeout handling
Phase 5: Maintainability Review
Section titled “Phase 5: Maintainability Review”Checks for maintainability:
-
SOLID Principles
- Single responsibility
- Open/closed
- Dependency injection
-
DRY
- Code duplication
- Opportunity for reuse
-
Testing
- Test coverage
- Test quality
- Edge case tests
-
Documentation
- API documentation
- Complex logic explanation
- Usage examples
Review Output Format
Section titled “Review Output Format”## Code Review: src/api/users.ts
**Reviewed**: 1 file, 142 lines**Verdict**: Request Changes
---
### Critical Issues (Must Fix)
#### 1. [Security] SQL Injection Risk**File**: `src/api/users.ts:42`**Severity**: Critical
```typescript// Current codeconst query = `SELECT * FROM users WHERE id = ${userId}`;Issue: User input directly interpolated into SQL query.
Fix:
const query = 'SELECT * FROM users WHERE id = $1';const result = await db.query(query, [userId]);Recommendations (Should Fix)
Section titled “Recommendations (Should Fix)”1. Missing Error Handling
Section titled “1. Missing Error Handling”File: src/services/auth.ts:78
// Currentconst user = await db.findUser(email);return user.password; // May throw if user is nullSuggestion:
const user = await db.findUser(email);if (!user) { throw new NotFoundError('User not found');}return user.password;Suggestions (Nice to Have)
Section titled “Suggestions (Nice to Have)”-
Consider extracting the validation logic in
src/utils/validate.ts:23into a separate function for reusability. -
The constant
MAX_RETRIESinsrc/api/client.tscould be moved to configuration.
What’s Good
Section titled “What’s Good”- Clean separation of concerns between controller and service layers
- Comprehensive error handling in the authentication flow
- Good test coverage for edge cases in
auth.test.ts
Summary
Section titled “Summary”Found 1 critical issue (security), 2 recommendations, and 2 suggestions.
Priority Actions:
- Fix SQL injection vulnerability immediately
- Add null check for user lookup
Ready for merge: No - Critical issues must be addressed first
## Review Checklist
### Security- [ ] No hardcoded secrets- [ ] Input validation present- [ ] Output encoding for rendered content- [ ] SQL parameterization- [ ] Proper auth checks- [ ] No eval() or dynamic code execution
### Quality- [ ] Clear naming conventions- [ ] Functions are focused (single responsibility)- [ ] Error handling is complete- [ ] No commented-out code- [ ] No debug statements left
### Testing- [ ] New code has tests- [ ] Edge cases covered- [ ] Tests are deterministic
### Documentation- [ ] Public APIs documented- [ ] Complex logic explained- [ ] Breaking changes noted
## Flags
| Flag | Description | Example ||------|-------------|---------|| `--mode=[mode]` | Use specific behavioral mode | `--mode=review` || `--persona=[type]` | Apply persona expertise | `--persona=security` || `--depth=[1-5]` | Review thoroughness level (1=quick, 5=exhaustive) | `--depth=5` || `--format=[fmt]` | Output format (concise/detailed/json) | `--format=detailed` || `--focus=[area]` | Focus on specific area | `--focus=performance` || `--save` | Save review to file | `--save` |
### Persona Options
| Persona | Focus Area ||---------|------------|| `security` | Vulnerabilities, auth, data protection || `performance` | Efficiency, queries, caching || `architecture` | Patterns, coupling, SOLID || `testing` | Coverage, test quality || `accessibility` | A11y compliance |
### Focus Areas
| Focus | Checks ||-------|--------|| `security` | OWASP top 10, auth, input validation || `performance` | N+1 queries, complexity, memory || `quality` | Readability, maintainability || `testing` | Coverage, test patterns |
### Flag Examples
```bash# Security-focused review of auth code/review --persona=security src/auth/
# Thorough review of staged changes/review --depth=5 --format=detailed staged
# Performance-focused review/review --focus=performance src/services/heavy-computation.ts
# Deep review with saved report/review --mode=deep-research --save prExamples
Section titled “Examples”Review Staged Changes
Section titled “Review Staged Changes”Input:
/review stagedOutput: Complete review of all staged changes with:
- Security vulnerability scan
- Code quality assessment
- Performance analysis
- Actionable feedback organized by severity
Review Pull Request
Section titled “Review Pull Request”Input:
/review pr #142Output:
- Fetches PR from GitHub
- Reviews all changed files
- Categorizes issues by severity
- Provides approval recommendation
Security-Focused Review
Section titled “Security-Focused Review”Input:
/review --persona=security --depth=5 src/api/Output:
- Deep security analysis
- OWASP top 10 checks
- Auth/authorization review
- Input validation verification
Deliverables
Section titled “Deliverables”After running /review, you receive:
- Issue List - Organized by severity (Critical, Recommendations, Suggestions)
- Code Examples - Before/after code snippets for fixes
- Checklist Results - Security, quality, testing, documentation
- Verdict - Approve, Request Changes, or Needs Discussion
- Action Items - Prioritized list of required fixes