/fix
/fix - Bug Fix Workflow
Section titled “/fix - Bug Fix Workflow”Purpose
Section titled “Purpose”Intelligent debugging and bug fixing workflow that analyzes errors, identifies root causes, implements fixes, and adds regression tests to prevent recurrence.
/fix [error message, bug description, or issue reference]Arguments
Section titled “Arguments”[error message]- Stack trace or error output from your application[bug description]- Natural language description of unexpected behavior[issue reference]- GitHub issue number or bug ticket ID
How It Works
Section titled “How It Works”The /fix command executes a systematic 6-phase debugging workflow:
Phase 1: Error Analysis
Section titled “Phase 1: Error Analysis”-
Parse Error Information
- Extracts error type and message
- Parses stack trace if available
- Identifies 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
- Follows the code path to the error
- Identifies state at each step
- Finds where expectations diverge
-
Form Hypotheses
- Lists possible causes ranked by likelihood
- Identifies minimal tests to validate each
-
Validate Hypothesis
- Tests the most likely cause first
- Confirms root cause before fixing
- Doesn’t fix symptoms only
Phase 3: Search Related Code
Section titled “Phase 3: Search Related Code”-
Find Similar Code
- Searches for similar patterns
- Checks if same bug exists elsewhere
- Identifies 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
- Fixes the root cause, not symptoms
- Keeps changes minimal and focused
- Considers edge cases
-
Add Defensive Code (if appropriate)
- Input validation
- Null checks
- Error handling
-
Update Related Code (if needed)
- Fixes same issue in similar code
- Updates shared utilities
Phase 5: Verification
Section titled “Phase 5: Verification”-
Test the Fix
- Verifies original error is resolved
- Checks related functionality
- Runs existing test suite
-
Add Regression Test
- Writes test that would have caught this bug
- Includes edge cases discovered
- Ensures 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)
- Adds clarifying comments
- Documents non-obvious behavior
Common Fix Patterns
Section titled “Common Fix Patterns”Null/Undefined Access
Section titled “Null/Undefined Access”// Before - Crashes on nullconst name = user.profile.name;
// After - Safe with optional chainingconst name = user?.profile?.name ?? 'Unknown';Missing Error Handling
Section titled “Missing Error Handling”# Before - Crashes on invalid JSONdata = json.loads(response.text)
# After - Handles errors gracefullytry: 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”// Before - May update unmounted componentconst data = await fetchData();setState(data);
// After - Checks if still mounteduseEffect(() => { let cancelled = false; fetchData().then(data => { if (!cancelled) setState(data); }); return () => { cancelled = true; };}, []);Off-by-One Error
Section titled “Off-by-One Error”# Before - IndexError on last iterationfor i in range(len(items) + 1): process(items[i])
# After - Correct rangefor i in range(len(items)): process(items[i])# Or better: use iterationfor item in items: process(item)| Flag | Description | Example |
|---|---|---|
--mode=[mode] | Use specific behavioral mode | --mode=deep-research |
--persona=[type] | Apply persona expertise | --persona=security |
--depth=[1-5] | Investigation thoroughness (1=quick, 5=exhaustive) | --depth=4 |
--format=[fmt] | Output format (concise/detailed) | --format=concise |
--skip-regression | Skip regression test creation | --skip-regression |
--checkpoint | Create checkpoint before fixing | --checkpoint |
Persona Options
Section titled “Persona Options”| Persona | Focus Area |
|---|---|
security | Security vulnerabilities, OWASP top 10 |
performance | Speed, memory usage, efficiency |
reliability | Error handling, edge cases, resilience |
Flag Examples
Section titled “Flag Examples”# Deep investigation for intermittent issues/fix --mode=deep-research "intermittent timeout error"
# Security-focused fix/fix --persona=security "SQL injection vulnerability"
# Thorough race condition analysis/fix --depth=5 "race condition in auth flow"
# Quick typo fix with minimal output/fix --format=concise "typo in error message"Examples
Section titled “Examples”Runtime Error
Section titled “Runtime Error”Input:
/fix TypeError: Cannot read property 'email' of undefined in UserService.ts:45Output:
- 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
- Verification: All tests passing
Bug Description
Section titled “Bug Description”Input:
/fix Users can see deleted posts in their feedOutput:
- Investigation: Traces feed generation logic
- Root cause: Soft-delete flag not checked in feed query
- Fix: Add WHERE clause filtering deleted posts
- Tests: Verify deleted posts don’t appear
- Check: Scans for similar issues in other queries
Deliverables
Section titled “Deliverables”After running /fix, you receive:
## Bug Fix Complete
### IssueTypeError: Cannot read property 'email' of undefined
### Root CauseUser object is undefined because async fetch wasn't awaited
### Location`src/services/UserService.ts:45` - getUserEmail method
### Fix Applied
**Before:**```typescriptasync getUserEmail(userId: string) { const user = this.fetchUser(userId); // Missing await return user.email; // Crashes if user is undefined}After:
async getUserEmail(userId: string) { const user = await this.fetchUser(userId); if (!user) { throw new NotFoundError(`User ${userId} not found`); } return user.email;}Regression Test Added
Section titled “Regression Test Added”src/services/UserService.test.ts - test_getUserEmail_with_nonexistent_user_throws_error
Verification
Section titled “Verification”- Original error no longer occurs
- Existing tests pass
- New regression test passes
- No new issues introduced
## Related Commands
- [/debug](/claudekit/commands/debug) - Deep debugging analysis- [/test](/claudekit/commands/test) - Generate additional tests- [/review](/claudekit/commands/review) - Code review for fixes- [/refactor](/claudekit/commands/refactor) - Improve code after fix