Fix Command
$ARGUMENTS
Attempts to fix code errors autonomously.
Usage
/fix <file_or_scope>
# Example: /fix src/utils.ts
Automated Error Classification
Before entering the fix loop, classify errors to prioritize auto-fixable ones:
# Pipe lint or test output
ruff check . 2>&1 | python3 ${CLAUDE_SKILL_DIR}/scripts/error-classifier.py
mypy src/ 2>&1 | python3 ${CLAUDE_SKILL_DIR}/scripts/error-classifier.py
npx eslint . 2>&1 | python3 ${CLAUDE_SKILL_DIR}/scripts/error-classifier.py
The script outputs JSON with:
- total_errors: count of all parsed errors
- auto_fixable_count: errors that tools can fix automatically (e.g., F401 unused imports, formatting)
- manual_count: errors requiring human/agent intervention
- tools_detected: which linters produced the output (ruff, mypy, eslint, tsc, phpstan)
- errors[]: each error with file, line, code, message, and auto_fixable flag
- suggested_order: files to fix, auto-fixable first
- fix_strategy: recommended approach (auto-fix first, then manual)
Use this to run auto-fixers (e.g., ruff check --fix .) before spending time on manual fixes.
Protocol (The "Fix Loop")
Analyze: Run validation to get the exact error message.
# Get error
npm test src/utils.ts 2>&1 | tee error.log
Diagnose: Analyze error.log.
- Use
debugging-tactics skill.
- Trace the error to the source line.
Patch: Apply a fix.
Verify: Run validation again.
- If PASS: Stop.
- If FAIL: Repeat (Max 3 retries).
Safety Limits
- Max Retries: 3
- Scope: Only modify the specified files.
- Stop Condition: If new errors appear that are totally different, STOP and ask user.
Example Flow
User: /fix app.py
Agent: Running tests... FAIL (NameError)
Agent: Fixing app.py (Import missing module)
Agent: Running tests... PASS
Agent: Fixed NameError in app.py
Rules
- MUST know the exact symptom (error message, failing test, lint code) before editing — guessing is not fixing
- MUST verify the fix by rerunning the same command that exposed the problem, not a different validator
- NEVER modify tests to make them pass — fixing the test is not fixing the bug
- NEVER touch files outside the declared scope — scope creep hides regressions
- CRITICAL: hard-stop after 3 iterations. If the fix loop has not converged, the problem is deeper than
/fix handles — escalate to /debug.
- MANDATORY: if new, unrelated errors appear during a fix attempt, stop and ask the user — do not chase them
Gotchas
ruff check --fix reorders imports and rewrites them. On files with circular imports or conditional-imports-under-TYPE_CHECKING, the "fix" can break things silently. Run --check first, inspect the diff, then apply.
eslint --fix --cache skips already-cached files even if their content changed (cache invalidation by mtime). On first-run misses, clear the cache with --no-cache to force a complete pass.
mypy --install-types auto-installs stub packages, adding dependencies to the environment the user did not request. Reserve it for explicit opt-in; in CI, pass --non-interactive to prevent surprise installs.
npm test -- path/to/test in a workspace repo runs the root workspace's test runner, not the leaf package's. Use npm test --workspace=<name> or the per-package cd packages/foo && npm test form.
- Fix loops occasionally produce cycle diffs — iteration 1 fixes A which triggers B, iteration 2 fixes B which re-breaks A. After every iteration compare the diff to the previous; identical or inverse diffs mean a cycle — stop.
When NOT to Use
- When the root cause is unknown — use
/debug first, then /fix with a clear target
- For systemic refactoring across modules — use
/refactor or /refactor-plan
- For writing new features test-first — use
/tdd
- For CI failures spanning many files — use
/workflow debugging (coordinated)
- When the failing validation is itself broken — repair the validator separately, do not patch code to satisfy it
1---2name: fix3description: "Applies targeted fix to known bug/lint error, verifies with same command that surfaced it. Triggers: fix, apply fix, fix bug, fix lint, targeted fix."4effort: low5disable-model-invocation: true6argument-hint: "[test or lint target]"7allowed-tools: Bash, Read, Edit, Grep8---910# Fix Command1112$ARGUMENTS1314Attempts to fix code errors autonomously.1516## Usage1718```bash19/fix <file_or_scope>20# Example: /fix src/utils.ts21```2223## Automated Error Classification2425Before entering the fix loop, classify errors to prioritize auto-fixable ones:2627```bash28# Pipe lint or test output29ruff check . 2>&1 | python3 ${CLAUDE_SKILL_DIR}/scripts/error-classifier.py30mypy src/ 2>&1 | python3 ${CLAUDE_SKILL_DIR}/scripts/error-classifier.py31npx eslint . 2>&1 | python3 ${CLAUDE_SKILL_DIR}/scripts/error-classifier.py32```3334The script outputs JSON with:35- **total_errors**: count of all parsed errors36- **auto_fixable_count**: errors that tools can fix automatically (e.g., F401 unused imports, formatting)37- **manual_count**: errors requiring human/agent intervention38- **tools_detected**: which linters produced the output (ruff, mypy, eslint, tsc, phpstan)39- **errors[]**: each error with file, line, code, message, and auto_fixable flag40- **suggested_order**: files to fix, auto-fixable first41- **fix_strategy**: recommended approach (auto-fix first, then manual)4243Use this to run auto-fixers (e.g., `ruff check --fix .`) before spending time on manual fixes.4445---4647## Protocol (The "Fix Loop")48491. **Analyze**: Run validation to get the exact error message.50 ```bash51 # Get error52 npm test src/utils.ts 2>&1 | tee error.log53 ```54552. **Diagnose**: Analyze `error.log`.56 - Use `debugging-tactics` skill.57 - Trace the error to the source line.58593. **Patch**: Apply a fix.60 - Use `sed` or `write_file`.61624. **Verify**: Run validation again.63 - If PASS: Stop.64 - If FAIL: Repeat (Max 3 retries).6566## Safety Limits67- **Max Retries**: 368- **Scope**: Only modify the specified files.69- **Stop Condition**: If new errors appear that are totally different, STOP and ask user.7071## Example Flow72```73User: /fix app.py74Agent: Running tests... FAIL (NameError)75Agent: Fixing app.py (Import missing module)76Agent: Running tests... PASS77Agent: Fixed NameError in app.py78```7980## Rules8182- **MUST** know the exact symptom (error message, failing test, lint code) before editing — guessing is not fixing83- **MUST** verify the fix by rerunning **the same command** that exposed the problem, not a different validator84- **NEVER** modify tests to make them pass — fixing the test is not fixing the bug85- **NEVER** touch files outside the declared scope — scope creep hides regressions86- **CRITICAL**: hard-stop after 3 iterations. If the fix loop has not converged, the problem is deeper than `/fix` handles — escalate to `/debug`.87- **MANDATORY**: if new, unrelated errors appear during a fix attempt, stop and ask the user — do not chase them8889## Gotchas9091- `ruff check --fix` reorders imports and rewrites them. On files with circular imports or conditional-imports-under-TYPE_CHECKING, the "fix" can break things silently. Run `--check` first, inspect the diff, then apply.92- `eslint --fix --cache` skips already-cached files even if their content changed (cache invalidation by mtime). On first-run misses, clear the cache with `--no-cache` to force a complete pass.93- `mypy --install-types` auto-installs stub packages, adding dependencies to the environment the user did not request. Reserve it for explicit opt-in; in CI, pass `--non-interactive` to prevent surprise installs.94- `npm test -- path/to/test` in a workspace repo runs the **root** workspace's test runner, not the leaf package's. Use `npm test --workspace=<name>` or the per-package `cd packages/foo && npm test` form.95- Fix loops occasionally produce **cycle diffs** — iteration 1 fixes A which triggers B, iteration 2 fixes B which re-breaks A. After every iteration compare the diff to the previous; identical or inverse diffs mean a cycle — stop.9697## When NOT to Use9899- When the root cause is unknown — use `/debug` first, then `/fix` with a clear target100- For systemic refactoring across modules — use `/refactor` or `/refactor-plan`101- For writing new features test-first — use `/tdd`102- For CI failures spanning many files — use `/workflow debugging` (coordinated)103- When the failing validation is itself broken — repair the validator separately, do not patch code to satisfy it