Code Quality Skill
Purpose
Perform systematic code reviews, identify issues, suggest refactorings, and enforce best practices. Acts as an automated code reviewer catching problems before they reach production.
Activation Triggers
Activate this skill when:
- User says "review this code"
- User asks "can this be improved?"
- User mentions "refactoring", "optimization", or "code smell"
- Before git commits (pre-commit review)
- After completing a feature
- User says "is this code good?"
Comprehensive Review Checklist
1. Code Structure
Single Responsibility Principle (SRP)
- Check: Each function/class has one clear purpose
- Red Flag: Functions doing multiple unrelated things
- Fix: Split into focused, single-purpose functions
DRY (Don't Repeat Yourself)
- Check: No duplicated logic
- Red Flag: Copy-pasted code blocks
- Fix: Extract to shared function/utility
Function Length
- Check: Functions under 50 lines (prefer under 30)
- Red Flag: Functions over 100 lines
- Fix: Break into smaller, composable functions
Naming Clarity
- Check: Names clearly describe purpose
- Red Flag: Vague names (data, info, temp, x, y)
- Fix: Use descriptive, intention-revealing names
Magic Numbers
- Check: Constants are named
- Red Flag: Unexplained numbers in code
- Fix: Extract to named constants
2. Error Handling
All Errors Caught
- Check: Error handling around risky operations
- Red Flag: Unhandled exceptions, missing error handling
- Fix: Add comprehensive error handling
No Silent Failures
- Check: Errors are logged or surfaced
- Red Flag: Empty catch blocks, ignored errors
- Fix: Log errors with context, alert user appropriately
User-Friendly Error Messages
- Check: Errors explain what went wrong and what to do
- Red Flag: Technical jargon exposed to users
- Fix: Translate technical errors to user language
Logging for Debugging
- Check: Appropriate logging at key points
- Red Flag: No logging or excessive logging
- Fix: Add structured logging with context
Edge Cases Covered
- Check: Boundary conditions handled (null, empty, zero)
- Red Flag: Assumptions about inputs
- Fix: Add defensive checks and validation
3. Security
Input Validation
- Check: All user inputs validated and sanitized
- Red Flag: Raw user input used directly
- Fix: Add validation with schema validation library
SQL Injection Prevention
- Check: Parameterized queries or ORM used
- Red Flag: String concatenation in SQL
- Fix: Use prepared statements or ORM methods
XSS Prevention
- Check: HTML output escaped, CSP headers set
- Red Flag: Raw HTML rendering of user content
- Fix: Use safe rendering or sanitize before output
Sensitive Data Handling
- Check: Passwords hashed, PII encrypted, secure transmission
- Red Flag: Plain text secrets, sensitive data in logs
- Fix: Use bcrypt/argon2, encrypt at rest, sanitize logs
Environment Variables for Secrets
- Check: API keys, credentials in environment or secret manager
- Red Flag: Hardcoded credentials in code
- Fix: Move to environment variables, use secret managers
4. Performance
No N+1 Queries
- Check: Batch queries, eager loading used
- Red Flag: Query inside loop
- Fix: Use includes/joins, batch operations
Appropriate Caching
- Check: Expensive operations cached
- Red Flag: Repeated identical API calls or computations
- Fix: Add caching layer (Redis, in-memory, etc.)
Database Indexes
- Check: Indexed columns used in WHERE/JOIN clauses
- Red Flag: Full table scans on large tables
- Fix: Add indexes on frequently queried columns
Unnecessary Computations
- Check: Early returns, lazy evaluation
- Red Flag: Work done before checking preconditions
- Fix: Move expensive operations after validation
Memory Leak Prevention
- Check: Resources cleaned up, connections closed
- Red Flag: Growing collections, unclosed connections
- Fix: Add cleanup in finally blocks, use resource management patterns
5. Testing
Tests Exist
- Check: Tests cover new functionality
- Red Flag: No tests for new code
- Fix: Write tests for all new functions/components
Edge Cases Tested
- Check: Boundary conditions handled
- Red Flag: Only happy path tested
- Fix: Add tests for edge cases and error conditions
Happy Path Tested
- Check: Normal operation verified
- Red Flag: No positive test cases
- Fix: Add tests for expected behavior
Error Conditions Tested
- Check: Invalid inputs, failures handled
- Red Flag: Error paths not verified
- Fix: Add tests for error scenarios
Tests Are Maintainable
- Check: Clear test names, minimal duplication
- Red Flag: Complex test setup, brittle assertions
- Fix: Extract test helpers, use clear assertions
Review Process
Step 1: Determine Scope
Ask user what to review:
- Current staged changes (
git diff --cached)
- Current unstaged changes (
git diff)
- Specific file or directory
- Entire feature
- Recent commits
Step 2: Analyze Code
Run appropriate git diff or read files:
# For staged changes
git diff --cached
# For unstaged changes
git diff
# For specific file
Read file_path
# For feature
git diff main...HEAD
Step 3: Apply Checklist
Systematically go through:
- Code Structure (5 checks)
- Error Handling (5 checks)
- Security (5 checks)
- Performance (5 checks)
- Testing (5 checks)
UltraThink Architectural Issues:
If review reveals fundamental architectural problems, activate deep thinking:
Say: "This code has architectural issues. Let me ultrathink whether refactoring or redesign is needed."
When to UltraThink:
- Code violates multiple principles (SRP, DRY, YAGNI)
- Tight coupling makes testing difficult
- Similar logic duplicated across multiple files
- Error handling is scattered and inconsistent
- Performance issues suggest wrong data structure/algorithm
Question deeply:
- Is this a symptom of wrong architecture?
- Would refactoring fix root cause or just move complexity?
- What would this look like if designed from scratch?
- What's preventing clean separation of concerns?
- Is the domain model wrong?
After UltraThink: Recommend tactical fixes (refactor) vs. strategic redesign with clear reasoning.
Step 4: Generate Review Report
Review Output Format
## Code Review: [File/Feature Name]
### Strengths
[List what's done well - be specific and encouraging]
- Clear function naming in authentication module
- Comprehensive error handling for API calls
- Good test coverage (87%)
### Issues Found
#### Priority: High - Must Fix Before Merge
1. **[Issue Title]**
- **Location:** `file:line`
- **Problem:** [Specific description]
- **Risk:** [What could go wrong]
- **Fix:** [How to resolve]
#### Priority: Medium - Should Address
1. **[Issue Title]**
- **Location:** `file:line`
- **Problem:** [Description]
- **Impact:** [Effect on code quality]
- **Suggestion:** [Improvement approach]
#### Priority: Low - Consider Improving
1. **[Issue Title]**
- **Location:** `file:line`
- **Note:** [Observation]
- **Enhancement:** [Optional improvement]
### Refactoring Suggestions
#### Suggestion 1: [Title]
**Current Code:**
[Show problematic pattern]
**Refactored Code:**
[Show improved version]
**Benefits:**
- [Benefit 1]
- [Benefit 2]
### Code Metrics
- **Complexity:** [Low/Medium/High]
- **Test Coverage:** [X%]
- **Maintainability:** [A/B/C/D/F]
- **Lines of Code:** [N]
- **Duplicated Code:** [X%]
### Action Items
- [ ] Fix high-priority issues
- [ ] Address medium-priority items
- [ ] Consider refactoring suggestions
- [ ] Add tests for uncovered paths
- [ ] Update documentation
---
**Overall Assessment:** [Summary statement]
**Recommendation:** [Approve/Request Changes/Reject]
[Confidence: X.X]
Examples
Example 1: Pre-Commit Review
User: "I'm about to commit, can you review my changes?"
Process:
- Run
git diff --cached to see staged changes
- Identify changed files
- Apply 25-point checklist
- Generate report with priorities
Focus on: Input validation, error handling, security, and test coverage for new code.
Example 2: Refactoring Request
User: "Can you suggest improvements for this module?"
Process:
- Read the file(s)
- Identify code smells: magic numbers, duplicated logic, long functions
- Propose specific refactorings with before/after pseudocode
- Explain benefits of each change
Focus on: Named constants, extracted functions, input validation, and cleaner error handling.
Integration Points
- Works with
spec-driven-implementation skill during execution phase
- Works with
git-workflow skill for pre-commit reviews
- Works with
systematic-debug skill to verify test quality
- Triggered automatically before commits if integrated
Notes
- Be thorough but constructive
- Prioritize issues appropriately
- Always provide specific code examples
- Explain WHY something is an issue, not just WHAT
- Offer concrete solutions, not just criticism
- Balance between perfectionism and pragmatism
- Focus on high-impact improvements
1---2name: review3description: 25-point code quality checklist covering structure, errors, security, performance, and testing. Use before commits or when reviewing code.4---5
6# Code Quality Skill
7
8## Purpose
9
10Perform systematic code reviews, identify issues, suggest refactorings, and enforce best practices. Acts as an automated code reviewer catching problems before they reach production.
11
12## Activation Triggers
13
14Activate this skill when:
15- User says "review this code"
16- User asks "can this be improved?"
17- User mentions "refactoring", "optimization", or "code smell"
18- Before git commits (pre-commit review)
19- After completing a feature
20- User says "is this code good?"
21
22## Comprehensive Review Checklist
23
24### 1. Code Structure
25
26**Single Responsibility Principle (SRP)**
27- Check: Each function/class has one clear purpose
28- Red Flag: Functions doing multiple unrelated things
29- Fix: Split into focused, single-purpose functions
30
31**DRY (Don't Repeat Yourself)**
32- Check: No duplicated logic
33- Red Flag: Copy-pasted code blocks
34- Fix: Extract to shared function/utility
35
36**Function Length**
37- Check: Functions under 50 lines (prefer under 30)
38- Red Flag: Functions over 100 lines
39- Fix: Break into smaller, composable functions
40
41**Naming Clarity**
42- Check: Names clearly describe purpose
43- Red Flag: Vague names (data, info, temp, x, y)
44- Fix: Use descriptive, intention-revealing names
45
46**Magic Numbers**
47- Check: Constants are named
48- Red Flag: Unexplained numbers in code
49- Fix: Extract to named constants
50
51### 2. Error Handling
52
53**All Errors Caught**
54- Check: Error handling around risky operations
55- Red Flag: Unhandled exceptions, missing error handling
56- Fix: Add comprehensive error handling
57
58**No Silent Failures**
59- Check: Errors are logged or surfaced
60- Red Flag: Empty catch blocks, ignored errors
61- Fix: Log errors with context, alert user appropriately
62
63**User-Friendly Error Messages**
64- Check: Errors explain what went wrong and what to do
65- Red Flag: Technical jargon exposed to users
66- Fix: Translate technical errors to user language
67
68**Logging for Debugging**
69- Check: Appropriate logging at key points
70- Red Flag: No logging or excessive logging
71- Fix: Add structured logging with context
72
73**Edge Cases Covered**
74- Check: Boundary conditions handled (null, empty, zero)
75- Red Flag: Assumptions about inputs
76- Fix: Add defensive checks and validation
77
78### 3. Security
79
80**Input Validation**
81- Check: All user inputs validated and sanitized
82- Red Flag: Raw user input used directly
83- Fix: Add validation with schema validation library
84
85**SQL Injection Prevention**
86- Check: Parameterized queries or ORM used
87- Red Flag: String concatenation in SQL
88- Fix: Use prepared statements or ORM methods
89
90**XSS Prevention**
91- Check: HTML output escaped, CSP headers set
92- Red Flag: Raw HTML rendering of user content
93- Fix: Use safe rendering or sanitize before output
94
95**Sensitive Data Handling**
96- Check: Passwords hashed, PII encrypted, secure transmission
97- Red Flag: Plain text secrets, sensitive data in logs
98- Fix: Use bcrypt/argon2, encrypt at rest, sanitize logs
99
100**Environment Variables for Secrets**
101- Check: API keys, credentials in environment or secret manager
102- Red Flag: Hardcoded credentials in code
103- Fix: Move to environment variables, use secret managers
104
105### 4. Performance
106
107**No N+1 Queries**
108- Check: Batch queries, eager loading used
109- Red Flag: Query inside loop
110- Fix: Use includes/joins, batch operations
111
112**Appropriate Caching**
113- Check: Expensive operations cached
114- Red Flag: Repeated identical API calls or computations
115- Fix: Add caching layer (Redis, in-memory, etc.)
116
117**Database Indexes**
118- Check: Indexed columns used in WHERE/JOIN clauses
119- Red Flag: Full table scans on large tables
120- Fix: Add indexes on frequently queried columns
121
122**Unnecessary Computations**
123- Check: Early returns, lazy evaluation
124- Red Flag: Work done before checking preconditions
125- Fix: Move expensive operations after validation
126
127**Memory Leak Prevention**
128- Check: Resources cleaned up, connections closed
129- Red Flag: Growing collections, unclosed connections
130- Fix: Add cleanup in finally blocks, use resource management patterns
131
132### 5. Testing
133
134**Tests Exist**
135- Check: Tests cover new functionality
136- Red Flag: No tests for new code
137- Fix: Write tests for all new functions/components
138
139**Edge Cases Tested**
140- Check: Boundary conditions handled
141- Red Flag: Only happy path tested
142- Fix: Add tests for edge cases and error conditions
143
144**Happy Path Tested**
145- Check: Normal operation verified
146- Red Flag: No positive test cases
147- Fix: Add tests for expected behavior
148
149**Error Conditions Tested**
150- Check: Invalid inputs, failures handled
151- Red Flag: Error paths not verified
152- Fix: Add tests for error scenarios
153
154**Tests Are Maintainable**
155- Check: Clear test names, minimal duplication
156- Red Flag: Complex test setup, brittle assertions
157- Fix: Extract test helpers, use clear assertions
158
159## Review Process
160
161### Step 1: Determine Scope
162
163Ask user what to review:
1641. Current staged changes (`git diff --cached`)
1652. Current unstaged changes (`git diff`)
1663. Specific file or directory
1674. Entire feature
1685. Recent commits
169
170### Step 2: Analyze Code
171
172Run appropriate git diff or read files:
173```bash
174# For staged changes
175git diff --cached
176
177# For unstaged changes
178git diff
179
180# For specific file
181Read file_path
182
183# For feature
184git diff main...HEAD
185```
186
187### Step 3: Apply Checklist
188
189Systematically go through:
1901. Code Structure (5 checks)
1912. Error Handling (5 checks)
1923. Security (5 checks)
1934. Performance (5 checks)
1945. Testing (5 checks)
195
196**UltraThink Architectural Issues:**
197If review reveals fundamental architectural problems, activate deep thinking:
198
199> Say: "This code has architectural issues. Let me ultrathink whether refactoring or redesign is needed."
200
201**When to UltraThink:**
202- Code violates multiple principles (SRP, DRY, YAGNI)
203- Tight coupling makes testing difficult
204- Similar logic duplicated across multiple files
205- Error handling is scattered and inconsistent
206- Performance issues suggest wrong data structure/algorithm
207
208**Question deeply:**
209- Is this a symptom of wrong architecture?
210- Would refactoring fix root cause or just move complexity?
211- What would this look like if designed from scratch?
212- What's preventing clean separation of concerns?
213- Is the domain model wrong?
214
215**After UltraThink:** Recommend tactical fixes (refactor) vs. strategic redesign with clear reasoning.
216
217### Step 4: Generate Review Report
218
219## Review Output Format
220
221```markdown
222## Code Review: [File/Feature Name]
223
224### Strengths
225
226[List what's done well - be specific and encouraging]
227- Clear function naming in authentication module
228- Comprehensive error handling for API calls
229- Good test coverage (87%)
230
231### Issues Found
232
233#### Priority: High - Must Fix Before Merge
2341. **[Issue Title]**
235 - **Location:** `file:line`
236 - **Problem:** [Specific description]
237 - **Risk:** [What could go wrong]
238 - **Fix:** [How to resolve]
239
240#### Priority: Medium - Should Address
2411. **[Issue Title]**
242 - **Location:** `file:line`
243 - **Problem:** [Description]
244 - **Impact:** [Effect on code quality]
245 - **Suggestion:** [Improvement approach]
246
247#### Priority: Low - Consider Improving
2481. **[Issue Title]**
249 - **Location:** `file:line`
250 - **Note:** [Observation]
251 - **Enhancement:** [Optional improvement]
252
253### Refactoring Suggestions
254
255#### Suggestion 1: [Title]
256**Current Code:**
257[Show problematic pattern]
258
259**Refactored Code:**
260[Show improved version]
261
262**Benefits:**
263- [Benefit 1]
264- [Benefit 2]
265
266### Code Metrics
267
268- **Complexity:** [Low/Medium/High]
269- **Test Coverage:** [X%]
270- **Maintainability:** [A/B/C/D/F]
271- **Lines of Code:** [N]
272- **Duplicated Code:** [X%]
273
274### Action Items
275
276- [ ] Fix high-priority issues
277- [ ] Address medium-priority items
278- [ ] Consider refactoring suggestions
279- [ ] Add tests for uncovered paths
280- [ ] Update documentation
281
282---
283
284**Overall Assessment:** [Summary statement]
285**Recommendation:** [Approve/Request Changes/Reject]
286
287[Confidence: X.X]
288```
289
290## Examples
291
292### Example 1: Pre-Commit Review
293
294**User:** "I'm about to commit, can you review my changes?"
295
296**Process:**
2971. Run `git diff --cached` to see staged changes
2982. Identify changed files
2993. Apply 25-point checklist
3004. Generate report with priorities
301
302Focus on: Input validation, error handling, security, and test coverage for new code.
303
304### Example 2: Refactoring Request
305
306**User:** "Can you suggest improvements for this module?"
307
308**Process:**
3091. Read the file(s)
3102. Identify code smells: magic numbers, duplicated logic, long functions
3113. Propose specific refactorings with before/after pseudocode
3124. Explain benefits of each change
313
314Focus on: Named constants, extracted functions, input validation, and cleaner error handling.
315
316## Integration Points
317
318- Works with `spec-driven-implementation` skill during execution phase
319- Works with `git-workflow` skill for pre-commit reviews
320- Works with `systematic-debug` skill to verify test quality
321- Triggered automatically before commits if integrated
322
323## Notes
324
325- Be thorough but constructive
326- Prioritize issues appropriately
327- Always provide specific code examples
328- Explain WHY something is an issue, not just WHAT
329- Offer concrete solutions, not just criticism
330- Balance between perfectionism and pragmatism
331- Focus on high-impact improvements