Refactor

Refactor code to improve quality, apply SOLID principles, remove code smells, and suggest better patterns. Use when improving code structure or modernizing legacy code.

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add thechandanbhagat/claude-skills --skill refactor
Manual install
git clone --depth 1 https://github.com/thechandanbhagat/claude-skills.git /tmp/claude-skills
mkdir -p ~/.claude/skills
cp -r /tmp/claude-skills/skills/refactor ~/.claude/skills/refactor

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Code Refactoring Skill

Improve code quality through systematic refactoring.

## 1. Extract Method/Function

**Before:**
```python
def process_order(order):
    # Calculate total
    total = 0
    for item in order.items:
        total += item.price * item.quantity
    tax = total * 0.08
    total += tax

    # Send email
    subject = f"Order #{order.id} Confirmation"
    body = f"Your order total is ${total}"
    send_email(order.customer.email, subject, body)
```

**After:**
```python
def process_order(order):
    total = calculate_total_with_tax(order.items)
    send_order_confirmation_email(order, total)

def calculate_total_with_tax(items, tax_rate=0.08):
    subtotal = sum(item.price * item.quantity for item in items)
    return subtotal * (1 + tax_rate)

def send_order_confirmation_email(order, total):
    subject = f"Order #{order.id} Confirmation"
    body = f"Your order total is ${total:.2f}"
    send_email(order.customer.email, subject, body)
```

## 2. Replace Magic Numbers

**Before:**
```javascript
function calculateDiscount(price) {
    if (price > 100) {
        return price * 0.15;
    }
    return price * 0.05;
}
```

**After:**
```javascript
const DISCOUNT_THRESHOLD = 100;
const REGULAR_DISCOUNT_RATE = 0.05;
const PREMIUM_DISCOUNT_RATE = 0.15;

function calculateDiscount(price) {
    const rate = price > DISCOUNT_THRESHOLD
        ? PREMIUM_DISCOUNT_RATE
        : REGULAR_DISCOUNT_RATE;
    return price * rate;
}
```

## 3. Simplify Conditional Logic
Read the full skill on GitHub

Details

Skill name
refactor
Path
skills/refactor/SKILL.md
Repo updated
22 January 2026

FAQ

What does the Refactor skill do?

Refactor code to improve quality, apply SOLID principles, remove code smells, and suggest better patterns. Use when improving code structure or modernizing legacy code.

How do I install the Refactor skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add thechandanbhagat/claude-skills --skill refactor. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Refactor popular?

It lives in thechandanbhagat/claude-skills, which has 9 GitHub stars and 0 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.