refactoring-advisor

Provides refactoring recommendations and step-by-step improvement plans. Use when planning refactoring, improving code structure, or reducing technical debt.

⭐19stars🔀4forks📁View on GitHub🕐Updated Dec 2, 2025

When & Why to Use This Skill

The Refactoring Advisor is a specialized Claude skill designed to enhance code maintainability and reduce technical debt. It provides developers with systematic analysis of 'code smells,' recommends industry-standard refactoring patterns, and generates detailed, step-by-step execution plans. By focusing on incremental changes and safety checklists, it helps engineering teams improve code structure and readability without compromising system stability.

Use Cases

  • Legacy Code Modernization: Identifying and decomposing complex 'God Classes' or long methods into modular, testable components to improve long-term maintainability.
  • Technical Debt Reduction: Systematically addressing duplicated code and rigid switch statements by applying patterns like 'Extract Method' or 'Replace with Polymorphism'.
  • Refactoring Planning: Generating structured, low-risk implementation roadmaps for structural changes, complete with prerequisites and validation steps.
  • Code Quality Mentoring: Assisting developers in identifying architectural weaknesses and learning best practices for clean code through guided, pattern-based recommendations.
namerefactoring-advisor
descriptionProvides refactoring recommendations and step-by-step improvement plans. Use when planning refactoring, improving code structure, or reducing technical debt.

Refactoring Advisor

Quick Start

Plan refactoring based on identified issues:

  1. Identify the problem (code smell, complexity)
  2. Select appropriate refactoring pattern
  3. Create step-by-step plan
  4. Ensure tests exist
  5. Refactor incrementally

Instructions

Step 1: Assess Current State

Analyze the code:

  • What is the problem? (long method, god class, etc.)
  • What is the impact? (maintainability, testability)
  • What is the risk? (how much code depends on it)

Step 2: Select Refactoring Strategy

Problem Strategy Risk
Long Method Extract Method Low
God Class Extract Class Medium
Duplicated Code Extract Method Low
Switch Statement Replace with Polymorphism High
Long Parameter List Introduce Parameter Object Medium

Step 3: Create Refactoring Plan

Template:

## Refactoring: [Name]

**Problem:** [Description]
**Goal:** [Desired outcome]
**Risk Level:** [Low/Medium/High]

### Prerequisites
- [ ] Tests exist and pass
- [ ] Code is committed
- [ ] Dependencies identified

### Steps
1. [First small change]
2. [Run tests]
3. [Next small change]
4. [Run tests]
...

### Validation
- [ ] All tests pass
- [ ] No functionality changed
- [ ] Code is cleaner

Step 4: Execute Incrementally

Golden Rule: Make the change easy, then make the easy change

  1. Make one small change
  2. Run tests
  3. Commit
  4. Repeat

Refactoring Examples

Extract Method

Before:

function printOwing(invoice) {
  let outstanding = 0;
  
  console.log("***********************");
  console.log("**** Customer Owes ****");
  console.log("***********************");
  
  for (const o of invoice.orders) {
    outstanding += o.amount;
  }
  
  console.log(`name: ${invoice.customer}`);
  console.log(`amount: ${outstanding}`);
}

Plan:

  1. Extract banner printing
  2. Run tests
  3. Extract outstanding calculation
  4. Run tests
  5. Extract details printing
  6. Run tests

After:

function printOwing(invoice) {
  printBanner();
  const outstanding = calculateOutstanding(invoice);
  printDetails(invoice, outstanding);
}

function printBanner() {
  console.log("***********************");
  console.log("**** Customer Owes ****");
  console.log("***********************");
}

function calculateOutstanding(invoice) {
  return invoice.orders.reduce((sum, o) => sum + o.amount, 0);
}

function printDetails(invoice, outstanding) {
  console.log(`name: ${invoice.customer}`);
  console.log(`amount: ${outstanding}`);
}

Extract Class

Before:

class Person {
  name;
  officeAreaCode;
  officeNumber;
  
  getTelephoneNumber() {
    return `(${this.officeAreaCode}) ${this.officeNumber}`;
  }
}

Plan:

  1. Create TelephoneNumber class
  2. Move areaCode field
  3. Run tests
  4. Move number field
  5. Run tests
  6. Move getTelephoneNumber method
  7. Run tests
  8. Update Person to use TelephoneNumber
  9. Run tests

After:

class TelephoneNumber {
  areaCode;
  number;
  
  toString() {
    return `(${this.areaCode}) ${this.number}`;
  }
}

class Person {
  name;
  telephoneNumber;
  
  getTelephoneNumber() {
    return this.telephoneNumber.toString();
  }
}

Safety Checklist

Before refactoring:

  • Tests exist and pass
  • Code is in version control
  • You understand what the code does
  • You have time to complete the refactoring

During refactoring:

  • Make small changes
  • Run tests after each change
  • Commit working states
  • Don't add features while refactoring

After refactoring:

  • All tests pass
  • Code review completed
  • Documentation updated
  • No functionality changed