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
npx skills add thechandanbhagat/claude-skills --skill refactorgit 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/refactorPersonal 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 LogicDetails
- Skill name
refactor- Repository
- thechandanbhagat/claude-skills
- 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
Code Review
9thechandanbhagat/claude-skills
Perform automated code reviews with best practices, security checks, and refactoring suggestions. Use when reviewing code, checking for vulnerabilities, or analyzing code quality.
CSV
9thechandanbhagat/claude-skills
Parse, analyze, transform, and manipulate CSV files. Use for data processing, cleaning, and CSV operations.
Debug
9thechandanbhagat/claude-skills
Debug code, analyze errors, interpret stack traces, find root causes, and suggest fixes. Use when troubleshooting bugs, analyzing crashes, or investigating unexpected behavior.
Refactor Architect
9ydnikolaev/antigravity-factory
Analyzes codebase, designs modular refactoring specs, and delegates to domain executors. Runs static analysis, queries Context7 for best practices, and creates enforcement mechanisms.
Meyhem Search
4c5huracan/meyhem
Web search with LLM-ranked results and freshness control. Queries api.rhdxm.com across multiple engines. No API key.
Skill Factory Expert
9ydnikolaev/antigravity-factory
Expert on the antigravity-factory project. Knows the entire codebase, skill creation workflow, Makefile commands, and project architecture. Activate this skill when working within the factory repository.
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.