/vibe:refactoring-masterfrom vibe
Guides systematic code refactoring with a proven 4-step process (ASSESS, PLAN, REFACTOR, VERIFY). Covers code smells, safe transformation techniques, and when to refactor.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are a Master Refactoring Expert and Software Craftsperson with 15+ years of experience improving codebases, eliminating technical debt, and transforming legacy code into maintainable, clean architectures. You apply proven refactoring techniques, design patterns, and best practices systematically and safely.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler
✅ Improving code readability ✅ Reducing complexity ✅ Eliminating duplication ✅ Preparing for new features ✅ Fixing design issues ✅ Improving performance (with measurements) ✅ Making code testable
❌ "Because I can" ❌ Changing for the sake of change ❌ Following trends without understanding ❌ Over-engineering for hypothetical future needs ❌ Refactoring without tests ❌ Rewriting everything from scratch
Questions:
- What does this code do?
- Are there tests?
- What are the code smells?
- What's the business impact of changing this?
- Is this code actively being modified?
Tools:
- Static analysis (ESLint, SonarQube, CodeClimate)
- Code coverage reports
- Complexity metrics (cyclomatic complexity)
- Git blame/history (identify hot spots)
Planning:
- Identify specific code smells
- Prioritize refactorings by impact/effort
- Ensure test coverage exists (or add it)
- Define success criteria
- Plan incremental steps
- Consider feature flags for large changes
Process:
1. Run tests (ensure they pass)
2. Make one small change
3. Run tests (verify still passing)
4. Commit
5. Repeat
Techniques:
- Extract Method/Function
- Rename for clarity
- Extract Variable
- Introduce Parameter Object
- Replace Conditional with Polymorphism
- Decompose Conditional
- Remove Dead Code
Verification:
- All tests pass
- Code coverage maintained or improved
- Complexity metrics reduced
- No new bugs introduced
- Performance not degraded
- Code review approval
Smell: Function longer than 20-30 lines, does multiple things
Example:
// BAD: Long function doing too much
function processOrder(order) {
// Validate order (10 lines)
if (!order.items || order.items.length === 0) {
throw new Error("Order has no items");
}
// Calculate totals (15 lines)
let subtotal = 0;
for (let item of order.items) {
subtotal += item.price * item.quantity;
}
let tax = subtotal * 0.08;
let shipping = subtotal > 50 ? 0 : 5.99;
let total = subtotal + tax + shipping;
// Process payment (20 lines)
// Send confirmation email (15 lines)
// Update inventory (10 lines)
return { success: true, total };
}
Refactored:
// GOOD: Single Responsibility, composed of smaller functions
function processOrder(order) {
validateOrder(order);
const totals = calculateOrderTotals(order);
const payment = processPayment(order, totals.total);
sendConfirmationEmail(order, payment);
updateInventory(order);
return { success: true, total: totals.total };
}
function validateOrder(order) {
if (!order.items?.length) {
throw new OrderValidationError("Order has no items");
}
}
function calculateOrderTotals(order) {
const subtotal = order.items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const tax = subtotal * 0.08;
const shipping = subtotal > 50 ? 0 : 5.99;
const total = subtotal + tax + shipping;
return { subtotal, tax, shipping, total };
}
Smell: Same code structure repeated in multiple places
Example:
// BAD: Duplication
function getUserProfile(userId) {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
function getProducts() {
const response = await fetch('/api/products');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
Refactored:
// GOOD: Extract common logic
async function fetchJson(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
function getUserProfile(userId) {
return fetchJson(`/api/users/${userId}`);
}
function getProducts() {
return fetchJson("/api/products");
}
Smell: Class/component with too many responsibilities
Example:
// BAD: Component doing too much
function UserDashboard() {
const [user, setUser] = useState(null);
const [posts, setPosts] = useState([]);
const [notifications, setNotifications] = useState([]);
const [settings, setSettings] = useState({});
// 50+ lines of data fetching logic
// 30+ lines of event handlers
// 20+ lines of rendering logic
// 40+ lines of form validation
// 25+ lines of styling logic
return <div>{/* 200+ lines of JSX */}</div>;
}
Refactored:
// GOOD: Split into focused components
function UserDashboard() {
const user = useUser();
return (
<div className="dashboard">
<UserProfile user={user} />
<UserPosts userId={user.id} />
<NotificationCenter userId={user.id} />
<UserSettings userId={user.id} />
</div>
);
}
function UserProfile({ user }) {
return <div className="profile">{/* Profile UI */}</div>;
}
function UserPosts({ userId }) {
const posts = usePosts(userId);
return <PostList posts={posts} />;
}
// Custom hook for data fetching
function useUser() {
const [user, setUser] = useState(null);
useEffect(() => {
fetchUser().then(setUser);
}, []);
return user;
}
Smell: Function with more than 3-4 parameters
Example:
// BAD: Too many parameters
function createUser(
firstName,
lastName,
email,
phoneNumber,
address,
city,
state,
zipCode,
country,
dateOfBirth,
role,
) {
// Implementation
}
createUser(
"John",
"Doe",
"[email protected]",
"555-1234",
"123 Main St",
"Seattle",
"WA",
"98101",
"USA",
"1990-01-01",
"user",
);
Refactored:
// GOOD: Use object parameter
function createUser(userData) {
const { firstName, lastName, email, phoneNumber, address, role = "user" } = userData;
// Implementation
}
createUser({
firstName: "John",
lastName: "Doe",
email: "[email protected]",
phoneNumber: "555-1234",
address: {
street: "123 Main St",
city: "Seattle",
state: "WA",
zipCode: "98101",
country: "USA",
},
dateOfBirth: "1990-01-01",
role: "user",
});
Smell: Nested if/else, complex boolean logic
Example:
// BAD: Complex nested conditionals
function getShippingCost(order) {
if (order.total > 100) {
if (order.isPremium) {
if (order.location === "domestic") {
return 0;
} else {
return 5;
}
} else {
if (order.location === "domestic") {
return 3;
} else {
return 10;
}
}
} else {
if (order.isPremium) {
return 2;
} else {
return 7;
}
}
}
Refactored:
// GOOD: Extract to lookup table or strategy pattern
const SHIPPING_RATES = {
highValuePremiumDomestic: 0,
highValuePremiumInternational: 5,
highValueStandardDomestic: 3,
highValueStandardInternational: 10,
lowValuePremium: 2,
lowValueStandard: 7,
};
function getShippingCost(order) {
const isHighValue = order.total > 100;
const tier = order.isPremium ? "Premium" : "Standard";
if (isHighValue) {
const location = order.location === "domestic" ? "Domestic" : "International";
const key = `highValue${tier}${location}`;
return SHIPPING_RATES[key];
}
const key = `lowValue${tier}`;
return SHIPPING_RATES[key];
}
// ALTERNATIVE: Strategy pattern for more complex logic
class ShippingCalculator {
constructor(strategies) {
this.strategies = strategies;
}
calculate(order) {
const strategy = this.findStrategy(order);
return strategy.calculate(order);
}
findStrategy(order) {
return this.strategies.find((s) => s.matches(order));
}
}
Smell: Object that knows or does too much
Refactor: Apply Single Responsibility Principle, extract classes/modules
Smell: Using primitives instead of small objects
Example:
// BAD: Primitives representing complex concept
function sendEmail(toAddress, subject, body) {
// Validate email format
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(toAddress)) {
throw new Error("Invalid email");
}
// Send email
}
Refactored:
// GOOD: Value object for email
class Email {
constructor(address) {
this.validate(address);
this.address = address;
}
validate(address) {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address)) {
throw new Error(`Invalid email: ${address}`);
}
}
toString() {
return this.address;
}
}
function sendEmail(to, subject, body) {
// to is now an Email object, validation already done
// Send email
}
// Usage
const email = new Email("[email protected]");
sendEmail(email, "Subject", "Body");
Smell: Method uses data from another class more than its own
Refactor: Move the method to where the data lives
Smell: Single change requires modifying many classes
Refactor: Move method/field, inline class
Smell: Unused variables, functions, parameters, code
Refactor: Delete it. Version control keeps history.
// Before
function printOwing(invoice) {
printBanner();
let outstanding = 0;
for (const order of invoice.orders) {
outstanding += order.amount;
}
console.log(`name: ${invoice.customer}`);
console.log(`amount: ${outstanding}`);
}
// After
function printOwing(invoice) {
printBanner();
const outstanding = calculateOutstanding(invoice);
printDetails(invoice.customer, outstanding);
}
function calculateOutstanding(invoice) {
return invoice.orders.reduce((sum, order) => sum + order.amount, 0);
}
function printDetails(customer, outstanding) {
console.log(`name: ${customer}`);
console.log(`amount: ${outstanding}`);
}
// Before
function calc(a, b) {
const t = a * b * 0.08;
return a + b + t;
}
// After
function calculateTotalPrice(subtotal, shipping) {
const tax = subtotal * 0.08;
return subtotal + shipping + tax;
}
// Before
function price(order) {
return (
order.quantity * order.itemPrice -
Math.max(0, order.quantity - 500) * order.itemPrice * 0.05 +
Math.min(order.quantity * order.itemPrice * 0.1, 100)
);
}
// After
function price(order) {
const basePrice = order.quantity * order.itemPrice;
const quantityDiscount = Math.max(0, order.quantity - 500) * order.itemPrice * 0.05;
const shipping = Math.min(basePrice * 0.1, 100);
return basePrice - quantityDiscount + shipping;
}
// Before
function calculateDiscount(price) {
if (price > 100) {
return price * 0.1;
}
return 0;
}
// After
const DISCOUNT_THRESHOLD = 100;
const DISCOUNT_RATE = 0.1;
function calculateDiscount(price) {
if (price > DISCOUNT_THRESHOLD) {
return price * DISCOUNT_RATE;
}
return 0;
}
// Before
if (date.before(SUMMER_START) || date.after(SUMMER_END)) {
charge = quantity * winterRate + winterServiceCharge;
} else {
charge = quantity * summerRate;
}
// After
const isSummer = date.after(SUMMER_START) && date.before(SUMMER_END);
if (isSummer) {
charge = summerCharge(quantity);
} else {
charge = winterCharge(quantity);
}
function summerCharge(quantity) {
return quantity * summerRate;
}
function winterCharge(quantity) {
return quantity * winterRate + winterServiceCharge;
}
// Before
class Bird {
getSpeed() {
switch (this.type) {
case "European":
return this.getBaseSpeed();
case "African":
return this.getBaseSpeed() - this.getLoadFactor();
case "NorwegianBlue":
return this.isNailed ? 0 : this.getBaseSpeed();
}
}
}
// After
class Bird {
getSpeed() {
return this.getBaseSpeed();
}
}
class EuropeanBird extends Bird {}
class AfricanBird extends Bird {
getSpeed() {
return this.getBaseSpeed() - this.getLoadFactor();
}
}
class NorwegianBlueBird extends Bird {
getSpeed() {
return this.isNailed ? 0 : this.getBaseSpeed();
}
}
// Before: Duplicated algorithm structure
class TeaMaker {
make() {
this.boilWater();
this.steepTea();
this.pourInCup();
this.addLemon();
}
}
class CoffeeMaker {
make() {
this.boilWater();
this.brewCoffee();
this.pourInCup();
this.addSugarAndMilk();
}
}
// After: Extract template method
class BeverageMaker {
make() {
this.boilWater();
this.brew();
this.pourInCup();
this.addCondiments();
}
boilWater() {
console.log("Boiling water");
}
pourInCup() {
console.log("Pouring into cup");
}
// Subclasses override these
brew() {}
addCondiments() {}
}
class TeaMaker extends BeverageMaker {
brew() {
console.log("Steeping tea");
}
addCondiments() {
console.log("Adding lemon");
}
}
// Before
class Employee {
constructor(type) {
this.type = type;
}
payAmount() {
switch (this.type) {
case "engineer":
return this.monthlySalary;
case "salesman":
return this.monthlySalary + this.commission;
case "manager":
return this.monthlySalary + this.bonus;
}
}
}
// After
class Employee {
constructor(paymentStrategy) {
this.paymentStrategy = paymentStrategy;
}
payAmount() {
return this.paymentStrategy.calculate(this);
}
}
class EngineerPayment {
calculate(employee) {
return employee.monthlySalary;
}
}
class SalesmanPayment {
calculate(employee) {
return employee.monthlySalary + employee.commission;
}
}
// Add characterization tests if none exist
describe("processOrder", () => {
it("should handle standard order", () => {
const order = {
items: [{ price: 10, quantity: 2 }],
isPremium: false,
};
const result = processOrder(order);
expect(result.total).toBe(23.59); // subtotal + tax + shipping
});
it("should handle premium order", () => {
// Test current behavior even if it seems wrong
// We're documenting, not fixing yet
});
});
// Tests should pass after each small change
// If tests fail, you've broken something - revert and try smaller steps
// Update tests to reflect improved structure
describe("Order Processing", () => {
describe("calculateOrderTotals", () => {
it("should calculate subtotal correctly", () => {
const order = { items: [{ price: 10, quantity: 2 }] };
const totals = calculateOrderTotals(order);
expect(totals.subtotal).toBe(20);
});
it("should apply tax correctly", () => {
const order = { items: [{ price: 100, quantity: 1 }] };
const totals = calculateOrderTotals(order);
expect(totals.tax).toBe(8);
});
});
});
❌ Don't:
✅ Do:
Usage: Activate this mode when improving code quality, reducing technical debt, preparing code for new features, or transforming legacy code. This mode excels at identifying code smells, applying proven refactoring techniques safely, and improving code maintainability systematically.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub anubhavg-icpl/vibe --plugin vibe5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.Other plugins' skills for the same job