/refactor-check-fix [target]
Systematically refactor code. ALL identified issues must be fixed.
First: Activate Workflow
mkdir -p .claude && echo '{"skill":"refactor-check","started":"'$(date -Iseconds)'"}' > .claude/active-workflow.json
Craft Standards (MANDATORY)
Refactor toward code a master craftsperson would be proud of.
The goal is code that looks like it was written by a skilled human engineer, not generated by AI.
AI Antipatterns to ELIMINATE
In addition to standard refactoring, actively hunt and remove:
- •Over-abstraction (factories/wrappers used only once → inline them)
- •Defensive paranoia (null checks where null is impossible → remove them)
- •Comment spam (
// increment counter→ delete it) - •Speculative features (config options nobody uses → remove them)
- •Wrapper classes that add no value → unwrap them
- •Enterprise patterns in simple code → simplify ruthlessly
Human Craft to ACHIEVE
After refactoring, code should have:
- •Functions that do exactly one thing
- •Names so clear they don't need comments
- •No code a senior engineer would delete
- •Every abstraction justified by actual use
Test: Would someone reviewing this PR say "why is this here?" If yes, remove it.
⚠️ STRICT REQUIREMENTS - NO JUDGMENT CALLS
You MUST check for and FIX all of these issues. Not "consider" - FIX:
- •FUNCTIONS > 30 LINES - Split them. No exceptions.
- •FILES > 300 LINES - Split into focused modules. Create thin re-export index if needed.
- •COMPLEXITY > 10 - Cyclomatic complexity too high. Flatten with early returns, extract helpers.
- •VAGUE NAMES - Rename data/result/temp/item/info to meaningful names.
- •DUPLICATE CODE - Extract to shared function. Run
lens dedupeto find cross-file duplications. - •CROSS-FILE DUPLICATION - Same function in multiple files → extract to utils/.
- •DEEP NESTING - Flatten with early returns.
- •MAGIC NUMBERS/STRINGS - Extract to named constants.
- •MISSING ERROR HANDLING - Add it.
- •GOD FILES - Split files with multiple concerns.
FORBIDDEN (Phase will FAIL if detected):
- •Saying "could be improved" without fixing
- •Skipping issues because they're "minor"
- •Suggesting future refactorings instead of doing them
- •Leaving any identified issue unfixed
- •Tests failing after refactoring
Process
Step 0: Load Expert Guidance
Before starting, read these canon skills and apply their principles throughout:
Always load:
- •
.claude/skills/clarity/SKILL.md - •
.claude/skills/simplicity/SKILL.md - •
.claude/skills/design-patterns/SKILL.md - •
.claude/skills/refactoring/SKILL.md
Load if applicable to target code:
- •Duplication patterns detected → also read
.claude/skills/composition/SKILL.md
If a skill file doesn't exist (not installed in this project), skip it and continue. Reference loaded experts in your APPLIED output.
Step 0b: Learn From Past Mistakes
Read both lessons files if they exist:
- •
workflow-skills/phase-loop-lessons.md— universal patterns (ships with skills, applies to all projects) - •
.claude/phase-loop-lessons.md— project-specific patterns (accumulated from this project's runs)
Add relevant lessons to your checklist of things to look for:
- •CODE_QUALITY entries → actively hunt for these patterns (e.g., dead exports, unused imports, redundant verification reads)
- •LOGIC entries → check for these bug patterns during refactoring (e.g., TOCTOU, missing validation)
- •AI_SMELL entries → look for single-use helpers to inline, JSDoc restating function names, impossible null checks, empty catch blocks
If a file doesn't exist, skip it and continue.
Step 1: Identify Issues
- •Identify Issues - Find all code quality problems
- •Fix Each One - Use Edit tool to fix
- •Run Tests - Verify behavior preserved
- •Report - Document what was fixed
REQUIRED Output Format
## Refactoring: [target] ISSUES_IDENTIFIED: - [file:line] [issue type] [description] - [file:line] [issue type] [description] REFACTORED: - [file:line] [issue type] - FIXED: [what was done] - [file:line] [issue type] - FIXED: [what was done] ISSUES_REMAINING: 0 (must be zero) REFACTOR_COUNT: N TESTS_PASS: yes APPLIED: - [expert]: [decision] REFACTOR_COMPLETE
Validation (Phase will FAIL if violated)
- •ISSUES_REMAINING > 0
- •TESTS_PASS: no
- •Issues identified but not in REFACTORED section
- •Any file > 300 lines after refactoring
- •Any function with cyclomatic complexity > 10 after refactoring
🛑 MANDATORY STOP
After refactoring:
- •DO NOT proceed to next phase
- •DO NOT continue with "let me also..."
Your turn ends here. Output REFACTOR_COMPLETE and STOP.