Automated code review tool that analyzes code quality, detects bugs, identifies security vulnerabilities, and suggests improvements based on industry best practices
Automated code review that analyzes code quality, detects bugs, identifies security vulnerabilities, and suggests improvements. Use before creating a pull request or after implementing features to catch issues early.
/plugin marketplace add mei28/claude-code/plugin install mei28-code-review-code-review@mei28/claude-codePerforms comprehensive automated code review to identify bugs, security vulnerabilities, code smells, and opportunities for improvement before creating a pull request. Combines static analysis principles with AI-powered insights to achieve high-quality code.
/code-review
/code-review src/specific-file.ts
Arguments (optional):
Analyzes code maintainability and readability:
Example Issues:
// ❌ High complexity (cyclomatic complexity: 12)
function processUser(user, action, options) {
if (user.isActive) {
if (action === 'update') {
if (options.validate) {
if (user.email) {
// ... many nested conditions
}
}
}
}
}
// ✅ Refactored (complexity: 3)
function processUser(user, action, options) {
if (!canProcessUser(user, action, options)) return;
const processor = getUserProcessor(action);
return processor.process(user, options);
}
Identifies potential runtime errors and logical bugs:
Example Issues:
// ❌ Potential null pointer
function getUserName(user: User): string {
return user.profile.name; // user.profile might be undefined
}
// ✅ Safe null handling
function getUserName(user: User): string {
return user.profile?.name ?? 'Unknown';
}
Detects security vulnerabilities and risks:
Example Issues:
// ❌ SQL Injection vulnerability
const query = `SELECT * FROM users WHERE id = ${userId}`;
// ✅ Parameterized query
const query = 'SELECT * FROM users WHERE id = ?';
db.execute(query, [userId]);
Identifies performance bottlenecks:
Example Issues:
# ❌ N+1 query problem
for user in users:
posts = db.query(f"SELECT * FROM posts WHERE user_id = {user.id}")
# ✅ Single query with join
posts_by_user = db.query("""
SELECT users.*, posts.*
FROM users
LEFT JOIN posts ON users.id = posts.user_id
""")
Ensures adherence to language and framework conventions:
For frontend code:
# Check what needs review
git status
git diff --staged
If no arguments provided, review all changed files. If file path provided, review only that file.
# Read files to review
Read src/auth/login.ts
Read src/api/users.ts
Create TodoWrite checklist:
## Code Review Progress
- [x] Identify files to review (3 files)
- [ ] Code Quality Analysis
- [ ] Bug Detection
- [ ] Security Analysis
- [ ] Performance Review
- [ ] Best Practices Check
- [ ] Generate Report
Create structured review report with:
# Code Review Report
## Summary
**Files Reviewed**: 3
**Total Issues**: 12
**Critical**: 2 🔴
**High**: 4 🟠
**Medium**: 4 🟡
**Low**: 2 ⚪
## Issues by Category
### Security 🔒 (2 Critical, 1 High)
#### 🔴 CRITICAL: SQL Injection Vulnerability
**File**: `src/api/users.ts:45`
**Issue**: User input directly interpolated into SQL query
**Risk**: Attacker can execute arbitrary SQL commands
```typescript
// Current (vulnerable)
const query = `SELECT * FROM users WHERE email = '${email}'`;
// Recommended fix
const query = 'SELECT * FROM users WHERE email = ?';
const result = await db.execute(query, [email]);
References:
File: src/config/api.ts:12
Issue: API key stored in source code
Risk: Key exposure in version control
// Current (insecure)
const API_KEY = 'sk_live_abc123def456';
// Recommended fix
const API_KEY = process.env.API_KEY;
if (!API_KEY) throw new Error('API_KEY not configured');
Action Required:
.env.example as placeholder.env to .gitignoreFile: src/auth/login.ts:78
Issue: user.profile accessed without null check
Impact: Runtime crash for users without profile
// Current (unsafe)
function getDisplayName(user: User): string {
return user.profile.displayName || user.email;
}
// Recommended fix
function getDisplayName(user: User): string {
return user.profile?.displayName ?? user.email;
}
File: src/utils/validator.ts:34-89
Issue: Function has cyclomatic complexity of 18 (threshold: 10)
Impact: Hard to test, maintain, and understand
Recommendation:
// Current: 56 lines, complexity 18
function validateForm(data) {
if (data.type === 'user') {
if (data.email) {
if (!/@/.test(data.email)) {
// ... many nested conditions
}
}
}
}
// Recommended: Separate validators
const validators = {
user: validateUserForm,
product: validateProductForm,
order: validateOrderForm
};
function validateForm(data) {
const validator = validators[data.type];
if (!validator) throw new Error(`Unknown type: ${data.type}`);
return validator(data);
}
File: src/api/posts.ts:23-27
Issue: Loading comments in loop causes N+1 queries
Impact: Slow response time (O(n) database calls)
// Current (N+1 queries)
const posts = await Post.findAll();
for (const post of posts) {
post.comments = await Comment.findByPostId(post.id);
}
// Recommended (1 query)
const posts = await Post.findAll({
include: [{ model: Comment }]
});
Expected Improvement: ~80% reduction in database calls
File: src/api/upload.ts:45
Issue: Async function without error handling
Impact: Unhandled promise rejections
// Current (no error handling)
async function uploadFile(file) {
const url = await storage.upload(file);
return url;
}
// Recommended
async function uploadFile(file) {
try {
const url = await storage.upload(file);
return url;
} catch (error) {
logger.error('File upload failed', { file: file.name, error });
throw new UploadError('Failed to upload file', { cause: error });
}
}
Fix SQL Injection in src/api/users.ts:45
Remove Hardcoded API Key in src/config/api.ts:12
src/auth/login.ts:78src/utils/validator.ts:34-89src/api/posts.ts:23-27/pr-template to document fixesGenerated by: Claude Code - Code Review Plugin Timestamp: 2026-01-03 20:45:00
## Best Practices
### 1. Review Frequently
Run code review:
- After completing each feature
- Before creating PR
- After addressing review comments
- During refactoring
### 2. Fix High-Severity First
Priority order:
1. 🔴 Critical (Security, Data Loss)
2. 🟠 High (Bugs, Major Quality Issues)
3. 🟡 Medium (Performance, Best Practices)
4. ⚪ Low (Code Style, Documentation)
### 3. Learn from Findings
Each issue is a learning opportunity:
- Understand why it's a problem
- Learn the recommended pattern
- Apply knowledge to future code
### 4. Automate in CI/CD
Integrate into CI pipeline:
```yaml
# .github/workflows/code-review.yml
- name: Code Review
run: claude code-review
Monitor improvements:
1. /dig # Clarify requirements
2. [Implement code]
3. /deslop # Clean up AI-generated code
4. /code-review # Check quality before commit
5. /test-generator # Generate missing tests
6. /commit # Create logical commits
7. /pr-template # Generate PR description
/code-review → /refactor → /code-review
Verify improvements after refactoring.
Configure in CLAUDE.md:
## Code Review
### Standards
- Max cyclomatic complexity: 10
- Min test coverage: 80%
- Required: ESLint, TypeScript strict mode
### Security
- No hardcoded secrets
- All user input must be validated
- Use parameterized queries only
### Exceptions
- Legacy code in `src/legacy/` (lower standards)
- Generated code in `src/generated/` (skip review)
The plugin adapts to:
go vet, golint standards/deslop to catch remaining issues/refactor for code improvementsResearch shows automated code review can:
Sources:
/code-reviewCode review a pull request
/code-reviewCode review a pull request
/code-reviewPerform a comprehensive code review of recent changes