Critical Code Review
Perform context-aware critical code review with integrated fix execution.
Review Targets
- Specific file:
src/main.ts
- Branch diff:
main..feature/new-api
- Recent commit:
HEAD~1..HEAD
- Directory:
src/
- PR:
#123
- No argument: diff between current branch and base (main/master/develop)
Target Resolution
- If argument provided: use as review target
- If no argument:
- Get current branch:
git branch --show-current
- Find base branch (priority: main, master, develop)
- Review diff:
git diff <base>...HEAD
- Include unstaged changes
Review Context (Determine First)
- Project phase: MVP/Development/Production/Refactoring
- Priority: Performance/Maintainability/Extensibility
- Tech stack: Languages/Frameworks/Paradigms
- File type: Backend/Frontend/UI Component/Database/Infrastructure
Review Criteria
🔴 High Priority (Critical)
- Security risks: SQL/XSS injection, auth flaws, secret exposure
- Data corruption: Transaction failures, race conditions, improper locking
- System failure: Unhandled exceptions, resource leaks, infinite loops
🟡 Medium Priority (Design Quality)
- Type safety & Domain Modeling: Primitive obsession, invalid state representation, missing smart constructors
- Functional programming violations: Side effects, missing Result types, mutability
- Design principle deviations: SOLID violations, high coupling, low cohesion
- Domain model inconsistencies: Misrepresented business rules, ambiguous boundaries
- Maintainability issues: Untestable design, missing documentation, implicit assumptions
🟢 Low Priority (Improvements)
- Efficiency: N+1 queries, unnecessary computation, cache opportunities
- Code quality: Duplication, naming, readability
🎨 UI/Frontend Specific
- UI state management: Invalid state combinations, missing loading/error states
- Accessibility: Missing ARIA, keyboard navigation, color-dependent information
- Responsive design: Hardcoded sizes, mobile support, breakpoint inconsistencies
- Component boundaries: Props drilling, excessive responsibility
- UI performance: Unnecessary re-renders, heavy components, missing virtualization
Review Process
- Perform self review and Codex review in parallel when feasible to reduce latency.
- Self review: Perform critical review based on criteria above
- Codex review (required when tool available): Request review via
mcp__codex-cli__codex tool with context. If unavailable, explicitly note it.
- Integrate results: Combine self review and Codex review into final issue list
- Present results: Output in the format below only after Codex review is completed or confirmed unavailable
Heuristic Review Guidance
- Understand context, intent, and constraints before judging
- Imagine the code's evolution over the next year
- Use domain knowledge to validate business logic
- Look beyond the listed categories and report issues of equivalent severity
Output Format
### 🔴/🟡/🟢 [Criterion Name]
**Issue**:
- Location (file:line)
- Detailed description
**Impact**:
- Technical: Bug/Performance degradation/Maintainability
- Business: User experience/Development velocity/Cost
**Fix**:
```[language]
// Specific fix code
```
Output Constraints
- Issue count: Max 5 by priority (guideline: 🔴2, 🟡2, 🟢1). If critical issues are numerous, adjust upward while keeping prioritization.
- Specificity: Include file:line, provide code examples
- Conciseness: Consider CLI display, be clear
- Practicality: Provide realistic, implementable fixes
Post-Review Fix Flow
After presenting review results, display:
## 🔧 Fix Options
Execute fixes? (y/n/select)
- y: Execute all
- n: Exit without fixing
- select: Choose items to fix
Selection:
Fix Item Organization
## 🔧 Planned Fixes
### Auto-fix Items (🔴 Critical)
1. [Issue name] - file:line
- Issue: [Brief description]
- Fix: [What will be changed]
### Items Requiring Confirmation (🟡 Design / 🔵 Other)
2. [Issue name] - file:line
- Issue: [Brief description]
- Proposed fix: [Suggestion]
- Impact scope: [Other file impacts]
### Skip Items (🟢 Suggestions)
3. [Issue name] - file:line (Manual fix recommended)
Ensure every item is numbered so the user can select them easily.
Item Selection (when select)
Enter item numbers to fix (comma-separated):
Example: 1,2,4
Fix Execution
Fix Validation Criteria
- Impact scope: Trace dependencies and identify side effects
- Correctness: Ensure expected behavior is preserved
- Testability: Ensure the fix can be verified by tests
- Mathematical verification (when algorithms change): Check complexity, concurrency safety, and invariants
Pre-fix Verification
- Confirm current file state
- Verify fix code fits context
- Consider impacts on other parts
Fix Application
- Minimal changes: Only changes needed to solve the issue
- Maintain consistency: Preserve existing code style, naming, indentation
- Check imports: Add new dependencies appropriately
- Type consistency: Ensure type integrity
- Backward compatibility: Clarify impact when behavior/API changes
- Naming conventions: Follow existing project rules
- Avoid magic numbers: Prefer named constants with intent
- Comments for complexity: Add concise comments only when needed
Quality Check
- Syntax errors: Ensure no syntax errors after fix
- Logical consistency: Ensure fix doesn't introduce new issues
- Edge cases: Ensure proper boundary and error handling
- Performance impact: Ensure no performance degradation
Test Implementation/Update
- Check existing tests: Identify tests related to fix location
- Update tests: Update tests that fail due to fix
- Add new tests: Add regression tests for bug fixes, cover normal/error cases for new features
- Test-first when feasible: Prefer writing a failing test before applying the fix
Fix Report
## ✅ Fix Complete Report
### Successful Fixes
- ✅ [Issue name] - file:line
- Changes: [Actual changes made]
### Failed Fixes
- ❌ [Issue name] - file:line
- Error: [Failure reason]
- Workaround: [Manual fix instructions]
### Next Steps
1. **Run tests (Required)**: Verify all tests pass
2. Run lint/format if defined
3. Run type checks if applicable
4. Provide manual test steps for uncovered flows
5. Confirm changes with `git diff`
6. Check test coverage report
7. Restore with `git checkout -- <file>` if needed
Error Handling
- Do not apply fixes that fail
- Partial success is acceptable; report clearly what was applied
- Report all errors with actionable guidance
Codex Review Integration
When mcp__codex-cli__codex tool is available, request secondary review:
Perform critical code review on the following code changes.
Focus on: security risks, data integrity, design quality, and maintainability.
Provide specific issues with file:line locations and fix suggestions.
[Include code diff or file content]
If the tool is unavailable but the Codex CLI is available, use:
codex exec -m gpt-codex-5.2 -c reasoning_effort=xhigh "Perform critical code review on the following code changes. [Include diff or file content]"
Integrate Codex findings with self review, removing duplicates and prioritizing by severity.
1---2name: critical-code-review3description: Perform critical code review with automated fix suggestions. Use when reviewing code changes, pull requests, specific files, or branch diffs. Triggers on requests like "review this code", "critical review", "code review for PR4---5
6# Critical Code Review
7
8Perform context-aware critical code review with integrated fix execution.
9
10## Review Targets
11
12- Specific file: `src/main.ts`
13- Branch diff: `main..feature/new-api`
14- Recent commit: `HEAD~1..HEAD`
15- Directory: `src/`
16- PR: `#123`
17- No argument: diff between current branch and base (main/master/develop)
18
19## Target Resolution
20
211. If argument provided: use as review target
222. If no argument:
23 - Get current branch: `git branch --show-current`
24 - Find base branch (priority: main, master, develop)
25 - Review diff: `git diff <base>...HEAD`
26 - Include unstaged changes
27
28## Review Context (Determine First)
29
30- **Project phase**: MVP/Development/Production/Refactoring
31- **Priority**: Performance/Maintainability/Extensibility
32- **Tech stack**: Languages/Frameworks/Paradigms
33- **File type**: Backend/Frontend/UI Component/Database/Infrastructure
34
35## Review Criteria
36
37### 🔴 High Priority (Critical)
38
391. **Security risks**: SQL/XSS injection, auth flaws, secret exposure
402. **Data corruption**: Transaction failures, race conditions, improper locking
413. **System failure**: Unhandled exceptions, resource leaks, infinite loops
42
43### 🟡 Medium Priority (Design Quality)
44
451. **Type safety & Domain Modeling**: Primitive obsession, invalid state representation, missing smart constructors
462. **Functional programming violations**: Side effects, missing Result types, mutability
473. **Design principle deviations**: SOLID violations, high coupling, low cohesion
484. **Domain model inconsistencies**: Misrepresented business rules, ambiguous boundaries
495. **Maintainability issues**: Untestable design, missing documentation, implicit assumptions
50
51### 🟢 Low Priority (Improvements)
52
531. **Efficiency**: N+1 queries, unnecessary computation, cache opportunities
542. **Code quality**: Duplication, naming, readability
55
56### 🎨 UI/Frontend Specific
57
581. **UI state management**: Invalid state combinations, missing loading/error states
592. **Accessibility**: Missing ARIA, keyboard navigation, color-dependent information
603. **Responsive design**: Hardcoded sizes, mobile support, breakpoint inconsistencies
614. **Component boundaries**: Props drilling, excessive responsibility
625. **UI performance**: Unnecessary re-renders, heavy components, missing virtualization
63
64## Review Process
65
66- Perform self review and Codex review in parallel when feasible to reduce latency.
67
681. **Self review**: Perform critical review based on criteria above
692. **Codex review (required when tool available)**: Request review via `mcp__codex-cli__codex` tool with context. If unavailable, explicitly note it.
703. **Integrate results**: Combine self review and Codex review into final issue list
714. **Present results**: Output in the format below only after Codex review is completed or confirmed unavailable
72
73## Heuristic Review Guidance
74
75- Understand context, intent, and constraints before judging
76- Imagine the code's evolution over the next year
77- Use domain knowledge to validate business logic
78- Look beyond the listed categories and report issues of equivalent severity
79
80## Output Format
81
82````markdown
83### 🔴/🟡/🟢 [Criterion Name]
84**Issue**:
85- Location (file:line)
86- Detailed description
87
88**Impact**:
89- Technical: Bug/Performance degradation/Maintainability
90- Business: User experience/Development velocity/Cost
91
92**Fix**:
93```[language]
94// Specific fix code
95```
96````
97
98## Output Constraints
99
100- **Issue count**: Max 5 by priority (guideline: 🔴2, 🟡2, 🟢1). If critical issues are numerous, adjust upward while keeping prioritization.
101- **Specificity**: Include file:line, provide code examples
102- **Conciseness**: Consider CLI display, be clear
103- **Practicality**: Provide realistic, implementable fixes
104
105## Post-Review Fix Flow
106
107After presenting review results, display:
108
109```
110## 🔧 Fix Options
111
112Execute fixes? (y/n/select)
113- y: Execute all
114- n: Exit without fixing
115- select: Choose items to fix
116
117Selection:
118```
119
120### Fix Item Organization
121
122```markdown
123## 🔧 Planned Fixes
124
125### Auto-fix Items (🔴 Critical)
1261. [Issue name] - file:line
127 - Issue: [Brief description]
128 - Fix: [What will be changed]
129
130### Items Requiring Confirmation (🟡 Design / 🔵 Other)
1312. [Issue name] - file:line
132 - Issue: [Brief description]
133 - Proposed fix: [Suggestion]
134 - Impact scope: [Other file impacts]
135
136### Skip Items (🟢 Suggestions)
1373. [Issue name] - file:line (Manual fix recommended)
138```
139
140Ensure every item is numbered so the user can select them easily.
141
142### Item Selection (when `select`)
143
144```
145Enter item numbers to fix (comma-separated):
146Example: 1,2,4
147```
148
149### Fix Execution
150
151#### Fix Validation Criteria
152
153- **Impact scope**: Trace dependencies and identify side effects
154- **Correctness**: Ensure expected behavior is preserved
155- **Testability**: Ensure the fix can be verified by tests
156- **Mathematical verification (when algorithms change)**: Check complexity, concurrency safety, and invariants
157
158#### Pre-fix Verification
159
160- Confirm current file state
161- Verify fix code fits context
162- Consider impacts on other parts
163
164#### Fix Application
165
166- **Minimal changes**: Only changes needed to solve the issue
167- **Maintain consistency**: Preserve existing code style, naming, indentation
168- **Check imports**: Add new dependencies appropriately
169- **Type consistency**: Ensure type integrity
170- **Backward compatibility**: Clarify impact when behavior/API changes
171- **Naming conventions**: Follow existing project rules
172- **Avoid magic numbers**: Prefer named constants with intent
173- **Comments for complexity**: Add concise comments only when needed
174
175#### Quality Check
176
177- **Syntax errors**: Ensure no syntax errors after fix
178- **Logical consistency**: Ensure fix doesn't introduce new issues
179- **Edge cases**: Ensure proper boundary and error handling
180- **Performance impact**: Ensure no performance degradation
181
182#### Test Implementation/Update
183
184- **Check existing tests**: Identify tests related to fix location
185- **Update tests**: Update tests that fail due to fix
186- **Add new tests**: Add regression tests for bug fixes, cover normal/error cases for new features
187- **Test-first when feasible**: Prefer writing a failing test before applying the fix
188
189### Fix Report
190
191```markdown
192## ✅ Fix Complete Report
193
194### Successful Fixes
195- ✅ [Issue name] - file:line
196 - Changes: [Actual changes made]
197
198### Failed Fixes
199- ❌ [Issue name] - file:line
200 - Error: [Failure reason]
201 - Workaround: [Manual fix instructions]
202
203### Next Steps
2041. **Run tests (Required)**: Verify all tests pass
2052. Run lint/format if defined
2063. Run type checks if applicable
2074. Provide manual test steps for uncovered flows
2085. Confirm changes with `git diff`
2096. Check test coverage report
2107. Restore with `git checkout -- <file>` if needed
211```
212
213### Error Handling
214
215- Do not apply fixes that fail
216- Partial success is acceptable; report clearly what was applied
217- Report all errors with actionable guidance
218
219## Codex Review Integration
220
221When `mcp__codex-cli__codex` tool is available, request secondary review:
222
223```
224Perform critical code review on the following code changes.
225Focus on: security risks, data integrity, design quality, and maintainability.
226Provide specific issues with file:line locations and fix suggestions.
227
228[Include code diff or file content]
229```
230
231If the tool is unavailable but the Codex CLI is available, use:
232
233```
234codex exec -m gpt-codex-5.2 -c reasoning_effort=xhigh "Perform critical code review on the following code changes. [Include diff or file content]"
235```
236
237Integrate Codex findings with self review, removing duplicates and prioritizing by severity.