fix
/fix - Bug Fix Workflow
Section titled “/fix - Bug Fix Workflow”Purpose
Section titled “Purpose”Smart debugging and bug fixing workflow that analyzes errors, identifies root causes, implements fixes, and adds regression tests.
/fix [error message, bug description, or issue reference]Arguments
Section titled “Arguments”$ARGUMENTS: Error message, stack trace, bug description, or issue number
Analyze and fix the following issue: $ARGUMENTS
Workflow
Section titled “Workflow”Phase 1: Error Analysis
Section titled “Phase 1: Error Analysis”-
Parse Error Information
- Extract error type and message
- Parse stack trace if available
- Identify the failing location
-
Gather Context
- When does this error occur?
- What triggers it?
- Is it reproducible?
- When did it start happening?
-
Check for Known Patterns
- Common error patterns
- Similar issues in codebase
- Recent changes that might have caused it
Phase 2: Root Cause Investigation
Section titled “Phase 2: Root Cause Investigation”-
Trace Execution
- Follow the code path to the error
- Identify state at each step
- Find where expectations diverge
-
Form Hypotheses
- List possible causes ranked by likelihood
- Identify minimal tests to validate each
-
Validate Hypothesis
- Test the most likely cause first
- Confirm root cause before fixing
- Don’t fix symptoms only
Phase 3: Search Related Code
Section titled “Phase 3: Search Related Code”-
Find Similar Code
- Search for similar patterns
- Check if same bug exists elsewhere
- Identify shared code that might be affected
-
Review Recent Changes
Terminal window git log --oneline -20git blame [file]
Phase 4: Implement Fix
Section titled “Phase 4: Implement Fix”-
Develop Minimal Fix
- Fix the root cause, not symptoms
- Keep changes minimal and focused
- Consider edge cases
-
Add Defensive Code (if appropriate)
- Input validation
- Null checks
- Error handling
-
Update Related Code (if needed)
- Fix same issue in similar code
- Update shared utilities
Phase 5: Verification
Section titled “Phase 5: Verification”-
Test the Fix
- Verify original error is resolved
- Check related functionality
- Run existing test suite
-
Add Regression Test
- Write test that would have caught this bug
- Include edge cases discovered
- Ensure test fails without fix
-
Run Full Test Suite
Terminal window # Pythonpytest -v# TypeScriptpnpm test
Phase 6: Documentation
Section titled “Phase 6: Documentation”-
Document the Fix
- What was the issue
- What caused it
- How it was fixed
-
Update Comments (if needed)
- Add clarifying comments
- Document non-obvious behavior
Output
Section titled “Output”Bug Fix Summary
Section titled “Bug Fix Summary”## Bug Fix Complete
### Issue[Original error/bug description]
### Root Cause[Explanation of what caused the bug]
### Location`path/to/file.ts:42` - [function/method name]
### Fix Applied
**Before:**```typescript// Problematic codeAfter:
// Fixed codeExplanation
Section titled “Explanation”[Why this fix resolves the issue]
Regression Test Added
Section titled “Regression Test Added”path/to/test.ts - test_[scenario]
Verification
Section titled “Verification”- Original error no longer occurs
- Existing tests pass
- New regression test passes
- No new issues introduced
Related Areas Checked
Section titled “Related Areas Checked”-
path/to/similar.ts- No similar issue
Commands to Verify
Section titled “Commands to Verify”pytest tests/test_file.py -v# orpnpm test path/to/file.test.ts## Common Fix Patterns
### Null/Undefined Access
```typescript// Beforeconst name = user.profile.name;
// Afterconst name = user?.profile?.name ?? 'Unknown';Missing Error Handling
Section titled “Missing Error Handling”# Beforedata = json.loads(response.text)
# Aftertry: data = json.loads(response.text)except json.JSONDecodeError as e: logger.error(f"Invalid JSON response: {e}") raise InvalidResponseError("Failed to parse response")Race Condition
Section titled “Race Condition”// Beforeconst data = await fetchData();setState(data); // May be unmounted
// AfteruseEffect(() => { let cancelled = false; fetchData().then(data => { if (!cancelled) setState(data); }); return () => { cancelled = true; };}, []);Off-by-One Error
Section titled “Off-by-One Error”# Beforefor i in range(len(items) + 1): # IndexError process(items[i])
# Afterfor i in range(len(items)): process(items[i])# orfor item in items: process(item)Example
Section titled “Example”Input: /fix TypeError: Cannot read property 'email' of undefined in UserService.ts:45
Output:
- Analysis: User object is undefined when accessed
- Root cause: async fetch didn’t await, user not loaded yet
- Fix: Add null check and proper async handling
- Regression test: Test for case when user is not loaded
| Flag | Description | Example |
|---|---|---|
--mode=[mode] | Use specific behavioral mode | --mode=deep-research |
--persona=[type] | Apply persona expertise | --persona=security |
--depth=[1-5] | Investigation thoroughness | --depth=4 |
--format=[fmt] | Output format (concise/detailed) | --format=concise |
--skip-regression | Skip regression test creation | --skip-regression |
--checkpoint | Create checkpoint before fixing | --checkpoint |
Flag Usage Examples
Section titled “Flag Usage Examples”/fix --mode=deep-research "intermittent timeout error"/fix --persona=security "SQL injection vulnerability"/fix --depth=5 "race condition in auth flow"/fix --format=concise "typo in error message"Persona Options
Section titled “Persona Options”| Persona | Focus Area |
|---|---|
security | Security vulnerabilities, OWASP |
performance | Speed, memory, efficiency |
reliability | Error handling, edge cases |
MCP Integration
Section titled “MCP Integration”This command leverages MCP servers for enhanced debugging:
Reasoning - Root Cause Analysis (Primary)
Section titled “Reasoning - Root Cause Analysis (Primary)”ALWAYS use Reasoning for debugging:- Trace execution path step-by-step- Form and test hypotheses systematically- Track confidence in each potential cause- Revise understanding as evidence emergesMemory - Bug Context
Section titled “Memory - Bug Context”Store and recall debugging context:- Remember similar bugs from previous sessions- Recall fix patterns that worked before- Store root cause analysis for future reference- Create relations between bugs and affected componentsBrowser tools - Browser Testing
Section titled “Browser tools - Browser Testing”For UI/frontend bugs:- Reproduce the bug in browser environment- Test fix across different browsers- Verify visual regressions are resolved- Automate regression test for the fixWeb Search - Library Issues
Section titled “Web Search - Library Issues”When debugging library-related issues:- Fetch current documentation for correct usage- Check for known issues or breaking changes- Find correct patterns and examplesFilesystem - Code Search
Section titled “Filesystem - Code Search”For tracing bug across codebase:- Use grep_search to find related code- Use view_file to examine suspicious areas- Track changes with file historyVariations
Section titled “Variations”Modify behavior via CLAUDE.md:
- Set required test coverage for fixes
- Define severity levels for bugs
- Configure error reporting format
- Set required review process
Gap Analysis Rule
Section titled “Gap Analysis Rule”Always identify gaps and suggest next steps to users. In case there is no gaps anymore, then AI should clearly state that there is no gap left.