
Refactoring Specialist
- 686 installs
- 68 repo stars
- Updated June 21, 2026
- charon-fan/agent-playbook
refactoring-specialist is a Claude Code skill from agent-playbook that systematically improves messy code, reduces technical debt, and raises quality using cataloged refactorings while preserving external behavior.
About
refactoring-specialist is a Claude Code skill in charon-fan/agent-playbook for behavior-preserving code cleanup and technical debt reduction. It maps common code smells—Long Method, Duplicate Code, Large Class, Long Parameter List, and Switch Statement—to named refactorings such as Extract Method, Extract Class, Introduce Parameter Object, and Replace with Polymorphism. Developers invoke it with prompts like refactor this code, clean up this function, or this code is messy when they want guided small-step improvements instead of risky rewrites. The skill enforces behavior preservation and incremental changes as core principles for safe refactors across languages.
- Applies 9 common refactorings including Extract Method, Extract Class, and Replace Conditional with Polymorphism
- Enforces 4 core principles: behavior preservation, small steps, test coverage, and frequent commits
- Delivers a 5-item refactoring checklist that must pass before completion
- Identifies and resolves 4 primary code smells: long methods, large classes, duplicate logic, feature envy
- Hard-gate: tests must pass and behavior must be preserved before any commit
Refactoring Specialist by the numbers
- 686 all-time installs (skills.sh)
- Ranked #193 of 1,352 Code Review & Quality skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Aug 1, 2026 (Skillselion catalog sync)
npx skills add https://github.com/charon-fan/agent-playbook --skill refactoring-specialistAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 686 |
|---|---|
| repo stars | ★ 68 |
| Security audit | 2 / 3 scanners passed |
| Last updated | June 21, 2026 |
| Repository | charon-fan/agent-playbook ↗ |
How do you refactor code without changing behavior?
Systematically improve messy code, reduce technical debt, and raise code quality without altering behavior.
Who is it for?
Developers cleaning legacy or messy modules who want catalog-driven, incremental refactors with explicit behavior preservation rules.
Skip if: Greenfield feature builds, intentional API breaking changes, or teams that need automated test generation instead of manual refactor guidance.
When should I use this skill?
User says refactor this code, clean up this function, reduce technical debt, or asks to fix code smells like long methods or duplicate logic.
What you get
Cleaner methods and classes, reduced duplication, simplified parameter lists, and polynorphic replacements with unchanged external behavior.
- refactored modules
- reduced code smells
- documented refactoring steps
Files
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
// 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
// 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
// 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
// Before:
function createUser(name, email, age, address, phone, role) { ... }
// After:
function createUser(user: UserData) { ... }
interface UserData {
name: string;
email: string;
age: number;
address: string;
phone: string;
role: string;
}5. Feature Envy
Symptom: Method uses more data from other classes
Refactoring: Move Method
// Before:
class Report {
formatSummary(formatter) {
const options = formatter.getFormattingOptions();
// ...
}
}
// After:
class Formatter {
formatReport(report) {
const discount = this.discountLevel;
// ...
}
}6. Data Clumps
Symptom: Same data appearing together
Refactoring: Extract Value Object
// Before:
function drawShape(x, y, width, height) { ... }
function moveShape(x, y, width, height, dx, dy) { ... }
// After:
class Rectangle {
constructor(x, y, width, height) { ... }
}
function drawShape(rect: Rectangle) { ... }7. Primitive Obsession
Symptom: Using primitives instead of small objects
Refactoring: Replace Primitive with Object
// Before:
function createUser(name, email, phone) { ... }
// After:
class Email {
constructor(value) {
if (!this.isValid(value)) throw new Error('Invalid email');
this.value = value;
}
// ...
}8. Switch Statements
Symptom: Large switch on type
Refactoring: Replace Conditional with Polymorphism
// Before:
function calculatePay(employee) {
switch (employee.type) {
case 'engineer': return employee.salary * 1.2;
case 'manager': return employee.salary * 1.5;
case 'sales': return employee.salary * 1.1;
}
}
// After:
interface Employee {
calculatePay(): number;
}
class Engineer implements Employee {
calculatePay() { return this.salary * 1.2; }
}9. Temporary Field
Symptom: Variables only used in certain scenarios
Refactoring: Extract Class
// Before:
class User {
calculateRefund() {
this.tempRefundAmount = 0;
// complex calculation
return this.tempRefundAmount;
}
}
// After:
class RefundCalculator {
calculate(user) {
// ...
}
}10. Comments
Symptom: Code needs extensive comments
Refactoring: Extract Method with clear name
// Before:
// Calculate the total price including discounts
// and tax based on user location
function calc(u, i) {
let t = 0;
// discount logic
if (u.vip) t *= 0.9;
// tax logic
if (u.state === 'CA') t *= 1.08;
return t;
}
// After:
function calculateTotalPrice(user: User, items: Item[]): number {
let total = items.sum(i => i.price);
if (user.isVIP) {
total = applyVIPDiscount(total);
}
return applyTax(total, user.state);
}Refactoring Steps
1. Identify the smell - What makes this code hard to work with? 2. Determine the refactoring - Which technique applies? 3. Ensure tests pass - Green before starting 4. Apply the refactoring - Make the change 5. Run tests - Verify behavior unchanged 6. Commit - Small, atomic commits
Safe Refactoring Practices
- Use your IDE's refactoring tools (Rename, Extract, Move)
- Run tests frequently (after each change)
- Keep commits small and focused
- Write a descriptive commit message
- Consider code reviews for complex refactorings
Before Refactoring
- [ ] Tests are passing
- [ ] I understand what the code does
- [ ] I have identified the specific code smell
- [ ] I know which refactoring to apply
- [ ] I have a rollback plan
After Refactoring
- [ ] Tests still pass
- [ ] Code is more readable
- [ ] Code is easier to maintain
- [ ] No new code smells introduced
- [ ] Documentation updated if needed
References
references/smells.md- Complete code smell catalogreferences/techniques.md- Refactoring techniquesreferences/checklist.md- Refactoring checklist
Refactoring Specialist
A Claude Code skill for code refactoring and technical debt reduction.
Installation
This skill is part of the agent-playbook collection.
Usage
You: Refactor this code
You: Clean up this function
You: This code is messy, help me improve itCommon 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 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
Related skills
How it compares
Use refactoring-specialist for guided smell-to-technique cleanup when you already know the code works and only structure needs improvement.
FAQ
Which refactorings does refactoring-specialist cover?
refactoring-specialist catalogs refactorings for Long Method, Duplicate Code, Large Class, Long Parameter List, and Switch Statement smells. Techniques include Extract Method, Extract Class, Introduce Parameter Object, and Replace with Polymorphism.
Does refactoring-specialist change program behavior?
refactoring-specialist requires behavior preservation on every change. The skill mandates small incremental steps so external behavior stays identical while internal structure and readability improve.
Is Refactoring Specialist safe to install?
skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.