Learn-skills.dev refactoring-specialist
Code refactoring expert. Use when restructuring code to improve readability, maintainability, or performance without changing behavior.
install
source · Clone the upstream repo
git clone https://github.com/NeverSight/learn-skills.dev
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/NeverSight/learn-skills.dev "$T" && mkdir -p ~/.claude/skills && cp -r "$T/data/skills-md/ai-engineer-agent/ai-engineer-skills/refactoring-specialist" ~/.claude/skills/neversight-learn-skills-dev-refactoring-specialist-cf8514 && rm -rf "$T"
manifest:
data/skills-md/ai-engineer-agent/ai-engineer-skills/refactoring-specialist/SKILL.mdsource content
Refactoring Specialist
Refactor $ARGUMENTS following safe refactoring practices:
Process
- Understand the code — read it fully before changing anything
- Identify existing tests — refactoring requires test coverage
- Apply refactoring patterns from the catalog below
- Verify behavior is preserved — tests must still pass
Refactoring Catalog
Extract & Compose
- Extract Method: Long function → smaller named functions
- Extract Variable: Complex expression → named intermediate
- Extract Class: Class doing too much → split responsibilities
- Inline: Unnecessary indirection → remove the wrapper
Simplify Conditionals
- Replace nested if/else with guard clauses (early return)
- Replace conditional with polymorphism (strategy pattern)
- Consolidate duplicate conditionals
- Decompose conditional into named boolean methods
Organize Data
- Replace magic numbers with named constants
- Replace primitive obsession with value objects
- Encapsulate collection (return unmodifiable view)
- Replace positional params with named/options object
Clean Interfaces
- Remove dead code — unused functions, imports, variables
- Reduce parameter count (max 3, then use object)
- Make dependencies explicit — no hidden globals
- Prefer composition over inheritance
Rules
- One refactoring pattern at a time
- Each step should compile and pass tests
- Don't mix refactoring with feature changes
- Preserve public API unless explicitly asked to change it
- Document any behavior changes in commit messages