npx skills add ...
npx skills add curiositech/some_claude_skills --skill refactoring-surgeon
Expert code refactoring specialist for improving code quality without changing behavior. Activate on: refactor, code smell, technical debt, legacy code, cleanup, simplify, extract method,
npx skills add curiositech/some_claude_skills --skill refactoring-surgeon
Expert code refactoring specialist focused on improving code quality without changing behavior.
| Category | Techniques |
|---|---|
| Extraction | Extract Method, Extract Class, Extract Interface |
| Movement | Move Method, Move Field, Inline Method |
| Simplification | Replace Conditional with Polymorphism, Decompose Conditional |
| Organization | Introduce Parameter Object, Replace Magic Numbers |
| Legacy Migration | Strangler Fig, Branch by Abstraction, Parallel Change |
Complete refactoring examples in ./references/:
| File | Pattern | Use Case |
|---|---|---|
extract-method.ts | Extract Method | Long methods → focused functions |
replace-conditional-polymorphism.ts | Replace Conditional | switch/if → polymorphic classes |
introduce-parameter-object.ts | Parameter Object | Long params → structured objects |
strangler-fig-pattern.ts | Strangler Fig | Legacy code → gradual migration |
Symptom: Rewriting entire modules in one massive change Fix: Strangler fig pattern, small incremental changes with tests
Symptom: Changing structure without test coverage Fix: Write characterization tests first, add coverage for affected areas
Symptom: Creating generic frameworks "for future flexibility" Fix: Wait for three concrete examples before abstracting (Rule of Three)
Symptom: Find-and-replace that misses occurrences Fix: Use IDE refactoring tools, search for usages first
Symptom: Adding new functionality while restructuring Fix: Separate commits - refactor first, then add features
Symptom: Large refactoring PRs that are hard to review Fix: Small, focused PRs with clear commit messages
Symptom: Three layers of abstraction for a simple operation Fix: YAGNI - start concrete, abstract when patterns emerge
Symptom: Starting Extract Method but leaving partial duplication Fix: Complete the refactoring or revert - no half-measures
Symptom: "I'll just clean this up while I'm here..." Fix: Never refactor during incidents - fix the bug, create a ticket
Symptom: Refactoring without knowing if it helped Fix: Track metrics: complexity, test coverage, build time
Before Refactoring:
During Refactoring:
After Refactoring:
Run ./scripts/validate-refactoring.sh to check:
┌─────────────────────┐ ┌─────────────────────┐
│ Divergent Change │ │ Shotgun Surgery │
│ One class, many │ │ One change, many │
│ reasons to change? │ │ classes affected? │
│ → Extract Class │ │ → Move/Inline │
└─────────────────────┘ └─────────────────────┘