Refactor code to improve maintainability, performance, and scalability through systematic analysis and incremental improvements
/plugin marketplace add claudeforge/marketplace/plugin install code-refactorer@claudeforge-marketplaceRefactor existing code to improve quality, maintainability, and performance while preserving functionality.
/refractor <file_or_directory>
Examples:
/refractor src/components/UserManager.js
/refractor src/services/
/refractor app/models/payment_processor.py
This command analyzes code and performs systematic refactoring to:
Improve Code Structure
Enhance Performance
Increase Maintainability
First, analyze the target code:
Rank refactoring opportunities by:
Apply refactoring techniques incrementally:
Extract Method: Break down complex functions
// Before
function processOrder(order) {
// 50 lines of mixed responsibilities
}
// After
function processOrder(order) {
validateOrder(order);
calculateTotal(order);
applyDiscounts(order);
processPayment(order);
sendConfirmation(order);
}
Remove Duplication: Apply DRY principle
# Before
def calculate_price_with_tax_us(price):
return price * 1.08
def calculate_price_with_tax_uk(price):
return price * 1.20
# After
def calculate_price_with_tax(price, tax_rate):
return price * (1 + tax_rate)
Improve Naming: Use descriptive names
// Before
function calc(a: number, b: number): number {
return a * b * 0.15;
}
// After
function calculateCommissionAmount(
salesPrice: number,
quantity: number
): number {
const COMMISSION_RATE = 0.15;
return salesPrice * quantity * COMMISSION_RATE;
}
Validate refactoring:
Update relevant documentation:
# Before
def get_speed(vehicle_type):
if vehicle_type == "car":
return 100
elif vehicle_type == "bike":
return 50
elif vehicle_type == "plane":
return 900
# After
class Vehicle:
def get_speed(self):
raise NotImplementedError
class Car(Vehicle):
def get_speed(self):
return 100
class Bike(Vehicle):
def get_speed(self):
return 50
// Before
public void createUser(String name, String email, String phone, String address, String city) {
// ...
}
// After
public void createUser(UserDetails details) {
// ...
}
// Before
if (user.age > 18 && user.accountBalance > 1000) {
approveCredit();
}
// After
const MINIMUM_AGE = 18;
const MINIMUM_BALANCE = 1000;
if (user.age > MINIMUM_AGE && user.accountBalance > MINIMUM_BALANCE) {
approveCredit();
}
Track these metrics before and after refactoring:
This command follows industry best practices: