Guides safe, incremental code refactoring with AI assistance. Helps characterize behavior with tests, identify code smells, extract functions, and reduce complexity while preserving behavior.
Ships in developer. 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.
Safely refactor code with AI assistance while preserving behavior.
┌─────────────────────────────────────────┐
│ 1. CHARACTERIZE - Understand current │
│ behavior with tests │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ 2. IDENTIFY - Find specific smells │
│ and improvement opportunities │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ 3. REFACTOR - Small, incremental │
│ changes with AI assistance │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ 4. VERIFY - Tests still pass, │
│ behavior unchanged │
└─────────────────────────────────────────┘
Before ANY refactoring, ensure behavior is captured.
// If no tests exist, create characterization tests
describe('OrderProcessor (characterization)', () => {
it('processes valid order', () => {
const result = processor.process(validOrder);
// Capture current behavior, even if not ideal
expect(result).toMatchSnapshot();
});
it('handles edge cases', () => {
expect(processor.process(null)).toBeNull();
expect(processor.process(emptyOrder)).toEqual({ status: 'empty' });
});
});
| Smell | Sign | Refactoring |
|---|---|---|
| Long Method | >20 lines | Extract Method |
| Long Parameter List | >3 params | Introduce Parameter Object |
| Duplicate Code | Copy-paste | Extract and reuse |
| Nested Conditionals | >3 levels deep | Guard clauses, early return |
| Feature Envy | Uses other class's data | Move method |
| Data Clumps | Same params together | Create class/type |
| Primitive Obsession | Strings for everything | Value objects |
| Switch Statements | Type checking | Polymorphism |
Analyze this code for refactoring opportunities. List:
1. Code smells present
2. Complexity hotspots
3. Potential extractions
4. Modernization opportunities
```[paste code]```
Focus on actionable improvements, not stylistic preferences.
Before:
function processOrder(order: Order) {
// 50 lines of validation
if (!order.items) return { error: 'No items' };
if (order.items.length === 0) return { error: 'Empty order' };
if (!order.customer) return { error: 'No customer' };
// ... more validation
// 30 lines of calculation
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
if (item.discount) {
total -= item.discount;
}
}
// ... more calculation
// 20 lines of persistence
// ...
}
AI Prompt:
Extract the validation logic from this function into a separate
`validateOrder` function. Keep the same behavior.
```[paste function]```
After:
function validateOrder(order: Order): ValidationResult {
if (!order.items) return { valid: false, error: 'No items' };
if (order.items.length === 0) return { valid: false, error: 'Empty order' };
if (!order.customer) return { valid: false, error: 'No customer' };
return { valid: true };
}
function calculateTotal(items: OrderItem[]): number {
return items.reduce((total, item) => {
const itemTotal = item.price * item.quantity;
return total + itemTotal - (item.discount || 0);
}, 0);
}
function processOrder(order: Order) {
const validation = validateOrder(order);
if (!validation.valid) return { error: validation.error };
const total = calculateTotal(order.items);
// persistence...
}
Before:
function getPaymentStatus(payment: Payment) {
if (payment) {
if (payment.status) {
if (payment.status === 'completed') {
if (payment.amount > 0) {
return 'success';
} else {
return 'zero-amount';
}
} else {
return payment.status;
}
} else {
return 'unknown';
}
} else {
return 'no-payment';
}
}
AI Prompt:
Refactor this function using guard clauses and early returns
to reduce nesting. Keep exact same behavior.
```[paste function]```
After:
function getPaymentStatus(payment: Payment) {
if (!payment) return 'no-payment';
if (!payment.status) return 'unknown';
if (payment.status !== 'completed') return payment.status;
if (payment.amount <= 0) return 'zero-amount';
return 'success';
}
Before:
function createUser(
firstName: string,
lastName: string,
email: string,
phone: string,
address: string,
city: string,
country: string,
role: string
) {
// ...
}
AI Prompt:
Refactor this function to use a parameter object instead of
individual parameters. Create appropriate TypeScript interface.
```[paste function]```
After:
interface CreateUserParams {
name: {
first: string;
last: string;
};
contact: {
email: string;
phone: string;
};
address: {
street: string;
city: string;
country: string;
};
role: string;
}
function createUser(params: CreateUserParams) {
// ...
}
After each refactoring step:
# Run existing tests
npm test
# Run type checking
npx tsc --noEmit
# Run linting
npm run lint
# If available, run mutation testing
npx stryker run
Simplify this code while preserving exact behavior.
Focus on readability and reducing complexity.
Modernize this code to use current JavaScript/TypeScript patterns:
- async/await instead of callbacks/promises
- Optional chaining and nullish coalescing
- Array methods instead of loops where appropriate
Preserve all existing behavior.
Extract the [specific part] into a separate reusable component.
- Keep the same props interface visible
- Maintain all existing behavior
- Follow the project's component patterns
Refactor this code to use the [Strategy/Factory/Observer] pattern.
Current code: ```[paste]```
Goal: Make it easier to [add new types/extend behavior/etc]
What SKILL.md sets; muted values are Claude Code's defaults
/developer:refactor-with-aifrom developer
npx claudepluginhub latestaiagents/agent-skills --plugin developer19 skills in this plugin
/ai-code-reviewerUse this skill when reviewing AI-generated code. Activate when the user has code generated by an AI
assistant and wants to review it, validate AI output, check for common AI mistakes, ensure code quality
of generated code, or verify that AI-generated code follows best practices before merging.
/branch-strategy-advisorUse this skill when discussing Git branching strategies. Activate when the user asks about branch naming,
GitFlow, trunk-based development, feature branches, release branches, how to organize branches,
branch protection, or setting up a branching workflow for their team.
/codebase-context-builder4 plugins in one repository ship this exact skill · first indexed Aug 19, 2026
Other plugins' skills for the same job