
Refactoring Specialist
Improve messy functions and classes with small, test-backed refactor steps while preserving behavior.
Overview
Refactoring Specialist is an agent skill most often used in Ship (also Build) that refactors code in small, test-verified steps while preserving external behavior.
Install
npx skills add https://github.com/charon-fan/agent-playbook --skill refactoring-specialistWhat is this skill?
- Behavior preservation, incremental steps, tests green before/after, and commit-after-each-change
- Smell-to-technique map: long method, duplication, large class, long params, switches
- Checklist gates: behavior preserved, tests pass, complexity reduced, naming improved
- Triggered by natural phrases: refactor, clean up, messy code
- Techniques: extract function/class, inline variable, polymorphism over conditionals
- 4-item refactoring checklist: behavior, tests, complexity, naming
- 5 mapped code smells to refactorings in the quick-reference table
Adoption & trust: 595 installs on skills.sh; 58 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your feature works but the code is hard to read, duplicated, or overloaded, and you fear breaking behavior with a big-bang rewrite.
Who is it for?
Solo builders with existing tests who want extract-method style improvements on demand.
Skip if: Greenfield scaffolding with no tests, or cases where you intentionally need behavior changes rather than structure-only edits.
When should I use this skill?
User asks to refactor, clean up code, or improve messy functions and classes.
What do I get? / Deliverables
You get simpler structure, clearer names, and passing tests with commits after each safe refactoring step.
- Refactored modules with unchanged external behavior
- Passing test run and improved naming/structure per checklist
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Ship/review is the canonical shelf because the skill emphasizes pre-release cleanup, checklist verification, and safe structural changes after features exist. Review covers readability and maintainability passes that do not change external behavior—classic refactor discipline before merge or release.
Where it fits
Split an oversized React component after a feature ships locally.
Run the four-item checklist before opening a PR on a tangled service module.
Reduce duplication in a hotfix path you touch again during incident follow-up.
How it compares
Use this focused refactor playbook instead of vague “make it cleaner” chat without smell-to-technique mapping.
Common Questions / FAQ
Who is refactoring-specialist for?
Developers using Claude Code or similar agents who want Martin Fowler–style refactor steps with explicit behavior preservation.
When should I use refactoring-specialist?
During build while touching legacy modules, and in ship/review before merging when complexity, duplication, or naming hurts maintainability.
Is refactoring-specialist safe to install?
It only guides local edits; review the Security Audits panel on this Prism page and rely on your own test suite before trusting automated refactors.
SKILL.md
READMESKILL.md - Refactoring Specialist
# Refactoring Specialist > A Claude Code skill for code refactoring and technical debt reduction. ## Installation This skill is part of the [agent-playbook](../../README.md) collection. ## Usage ``` You: Refactor this code You: Clean up this function You: This code is messy, help me improve it ``` ## Common Refactorings | Code Smell | Refactoring | |------------|-------------| | Long Method | Extract Method | | Duplicate Code | Extract Method | | Large Class | Extract Class | | Long Parameter List | Introduce Parameter Object | | Switch Statement | Replace with Polymorphism | ## Principles 1. **Behavior Preservation**: Refactoring must not change external behavior 2. **Small Steps**: Make incremental changes 3. **Test Coverage**: Ensure tests pass before and after 4. **Commit Often**: Commit after each successful refactoring ## Resources - [Refactoring.com](https://refactoring.com/) - [Clean Code](https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882) # Refactoring Checklist - [ ] Behavior preserved - [ ] Tests pass - [ ] Complexity reduced - [ ] Naming improved # Code Smells - Long methods - Large classes - Duplicate logic - Feature envy # Refactoring Techniques - Extract function - Extract class - Inline variable - Replace conditional with polymorphism --- name: refactoring-specialist description: Code refactoring expert for improving code structure, readability, and maintainability. Use when user asks to refactor, clean up, or improve code quality. allowed-tools: Read, Write, Edit, Bash, Grep, Glob metadata: hooks: after_complete: - trigger: self-improving-agent mode: background reason: "Learn from refactoring patterns" - trigger: session-logger mode: auto reason: "Log refactoring activity" --- # Refactoring Specialist Expert guidance on refactoring code to improve structure, readability, and maintainability while preserving functionality. ## When This Skill Activates Activates when you: - Ask to refactor code - Request cleanup or improvement - Mention "technical debt" or "code smell" - Want to improve code quality ## Refactoring Principles 1. **Preserve Behavior**: Refactoring must not change external behavior 2. **Small Steps**: Make small, incremental changes 3. **Test Coverage**: Ensure tests pass before and after 4. **Commit Often**: Commit after each successful refactoring ## Code Smells to Address ### 1. Long Method **Symptom:** Function > 20-30 lines **Refactoring:** Extract Method ```typescript // Before: function processOrder(order) { // 50 lines of code } // After: function processOrder(order) { validateOrder(order); calculateTotals(order); saveOrder(order); sendConfirmation(order); } ``` ### 2. Duplicate Code **Symptom:** Similar code in multiple places **Refactoring:** Extract Method / Template Method ```typescript // Before: class UserService { async validateEmail(email) { if (!email || !email.includes('@')) return false; const domain = email.split('@')[1]; return domain.length > 0; } } class AdminService { async validateEmail(email) { if (!email || !email.includes('@')) return false; const domain = email.split('@')[1]; return domain.length > 0; } } // After: class EmailValidator { async validate(email) { if (!email || !email.includes('@')) return false; return email.split('@')[1].length > 0; } } ``` ### 3. Large Class **Symptom:** Class doing too many things **Refactoring:** Extract Class ```typescript // Before: class User { // Authentication // Profile management // Notifications // Reporting } // After: class User { /* Core user data */ } class UserAuth { /* Authentication */ } class UserProfile { /* Profile management */ } class UserNotifier { /* Notifications */ } ``` ### 4. Long Parameter List **Symptom:** Function with 4+ parameters **Refactoring:** Introduce Parameter Object ```typescript // Before: function createUser(name, e