Skip to content

fix

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: Error message, stack trace, bug description, or issue number

Analyze and fix the following issue: $ARGUMENTS

  1. Parse Error Information

    • Extract error type and message
    • Parse stack trace if available
    • Identify the failing location
  2. Gather Context

    • When does this error occur?
    • What triggers it?
    • Is it reproducible?
    • When did it start happening?
  3. Check for Known Patterns

    • Common error patterns
    • Similar issues in codebase
    • Recent changes that might have caused it
  1. Trace Execution

    • Follow the code path to the error
    • Identify state at each step
    • Find where expectations diverge
  2. Form Hypotheses

    • List possible causes ranked by likelihood
    • Identify minimal tests to validate each
  3. Validate Hypothesis

    • Test the most likely cause first
    • Confirm root cause before fixing
    • Don’t fix symptoms only
  1. Find Similar Code

    • Search for similar patterns
    • Check if same bug exists elsewhere
    • Identify shared code that might be affected
  2. Review Recent Changes

    Terminal window
    git log --oneline -20
    git blame [file]
  1. Develop Minimal Fix

    • Fix the root cause, not symptoms
    • Keep changes minimal and focused
    • Consider edge cases
  2. Add Defensive Code (if appropriate)

    • Input validation
    • Null checks
    • Error handling
  3. Update Related Code (if needed)

    • Fix same issue in similar code
    • Update shared utilities
  1. Test the Fix

    • Verify original error is resolved
    • Check related functionality
    • Run existing test suite
  2. Add Regression Test

    • Write test that would have caught this bug
    • Include edge cases discovered
    • Ensure test fails without fix
  3. Run Full Test Suite

    Terminal window
    # Python
    pytest -v
    # TypeScript
    pnpm test
  1. Document the Fix

    • What was the issue
    • What caused it
    • How it was fixed
  2. Update Comments (if needed)

    • Add clarifying comments
    • Document non-obvious behavior
## 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 code

After:

// Fixed code

[Why this fix resolves the issue]

path/to/test.ts - test_[scenario]

  • Original error no longer occurs
  • Existing tests pass
  • New regression test passes
  • No new issues introduced
  • path/to/similar.ts - No similar issue
Terminal window
pytest tests/test_file.py -v
# or
pnpm test path/to/file.test.ts
## Common Fix Patterns
### Null/Undefined Access
```typescript
// Before
const name = user.profile.name;
// After
const name = user?.profile?.name ?? 'Unknown';
# Before
data = json.loads(response.text)
# After
try:
data = json.loads(response.text)
except json.JSONDecodeError as e:
logger.error(f"Invalid JSON response: {e}")
raise InvalidResponseError("Failed to parse response")
// Before
const data = await fetchData();
setState(data); // May be unmounted
// After
useEffect(() => {
let cancelled = false;
fetchData().then(data => {
if (!cancelled) setState(data);
});
return () => { cancelled = true; };
}, []);
# Before
for i in range(len(items) + 1): # IndexError
process(items[i])
# After
for i in range(len(items)):
process(items[i])
# or
for item in items:
process(item)

Input: /fix TypeError: Cannot read property 'email' of undefined in UserService.ts:45

Output:

  1. Analysis: User object is undefined when accessed
  2. Root cause: async fetch didn’t await, user not loaded yet
  3. Fix: Add null check and proper async handling
  4. Regression test: Test for case when user is not loaded
FlagDescriptionExample
--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-regressionSkip regression test creation--skip-regression
--checkpointCreate checkpoint before fixing--checkpoint
Terminal window
/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"
PersonaFocus Area
securitySecurity vulnerabilities, OWASP
performanceSpeed, memory, efficiency
reliabilityError handling, edge cases

This command leverages MCP servers for enhanced debugging:

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 emerges
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 components
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 fix
When debugging library-related issues:
- Fetch current documentation for correct usage
- Check for known issues or breaking changes
- Find correct patterns and examples
For tracing bug across codebase:
- Use grep_search to find related code
- Use view_file to examine suspicious areas
- Track changes with file history

Modify behavior via CLAUDE.md:

  • Set required test coverage for fixes
  • Define severity levels for bugs
  • Configure error reporting format
  • Set required review process

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.