dev-loop-refactor-guide
Use when the user asks to refactor a long function or class safely, remove code smells, extract methods, untangle legacy code, or improve structure without…
от j4flmao★ 47 звёзд на GitHub
Установить dev-loop-refactor-guide в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Refactoring Guide
Purpose
Systematically improve code structure, readability, maintainability, and extensibility without changing external behavior — applying proven refactoring techniques, identifying code smells, and establishing refactoring workflows that reduce technical debt safely.
Agent Protocol
Trigger
Exact user phrases: "refactor", "code smell", "technical debt", "improve code", "clean up code", "extract method", "restructure", "modernize", "legacy code", "refactoring strategy", "decouple", "extract class".
Input Context
- Codebase size and age (new project → legacy codebase)
- Language and framework (affects available refactoring tools)
- Current pain points (duplication, long methods, tight coupling, slow tests)
- Test coverage (% and quality)
- Refactoring goal (improve readability, enable new feature, reduce bugs, pay down debt)
- Risk tolerance (safety-critical, high-traffic, low-risk internal tool)
Output Artifact
Refactoring plan with prioritized code smells, technique application, and verification strategy.
Response Format
Target: {module/files}
Smells: {smell -> location}
Safety net: {existing tests | characterization tests to add}
Steps (each behavior-preserving, committed separately): {technique -> change}
Verification: {tests/commands}
Risk: {low|med|high} — rollback {plan}
Completion Criteria
- Code smells identified and cataloged
- Refactoring techniques selected for each smell
- Refactoring order prioritized (high value, low risk first)
- Test coverage verified for code being refactored
- Refactoring applied incrementally (one change at a time)
- Behavior preserved (tests pass before/after)
- Code review completed for refactoring PRs
- Documentation updated if API changed
Max Response Length
200 lines.
Framework/Methodology
Refactoring Decision Tree
What is the primary code quality issue?
├── Duplicated code → Extract method / Extract class
├── Long method (>20 lines) → Extract method / Replace temp with query
├── Large class (>300 lines) → Extract class / Extract interface
├── Too many parameters (>3) → Introduce parameter object
├── Feature envy → Move method / Extract class
├── Switch/if-else chain → Replace with strategy / polymorphism
├── Data clump → Introduce parameter object / Extract class
├── Shotgun surgery (one change = many files) → Move method / Inline class
├── Divergent change (file changes for multiple reasons) → Extract class per concern
├── Speculative generality → Inline class / Collapse hierarchy
├── Message chain (a.b().c().d()) → Hide delegate / Extract method
└── Primitive obsession → Replace primitive with value object
Refactoring Rule of Three
First time: Do it (get it working)
Second time: Duplicate it (get it working again)
Third time: Refactor it (eliminate duplication)
Don't refactor on first occurrence — you don't understand the pattern yet.
The Cambrian Explosion Trap
When refactoring, resist the urge to create the "perfect" abstraction immediately. Instead, make the simplest change that improves the code, then iterate.
Strategy:
1. Identify the smell
2. Apply the minimal refactoring technique
3. Run tests (verify behavior preserved)
4. Commit
5. Repeat
Workflow
Step 1: Identify Code Smells
// SMELL: Long method (>20 lines)
// SMELL: Deep nesting (arrow code)
function processOrder(order: Order, user: User, config: Config): Promise<Result> {
if (order && order.items && order.items.length > 0) {
if (user && user.isActive) {
if (config && config.enabled) {
let total = 0;
for (const item of order.items) {
if (item.price && item.quantity) {
total += item.price * item.quantity;
if (item.discount) {
total -= item.discount;
}
}
}
if (total > 0) {
if (user.balance >= total) {
user.balance -= total;
return saveOrder(order, user, total);
} else {
throw new Error('Insufficient balance');
}
} else {
throw new Error('Invalid total');
}
} else {
throw new Error('Config not enabled');
}
} else {
throw new Error('User not active');
}
} else {
throw new Error('Invalid order');
}
}
// SMELL: Primitive obsession (using string for concept)
function sendEmail(to: string, from: string, subject: string, body: string, cc?: string, bcc?: string, replyTo?: string) {
// ...
}
// SMELL: Feature envy (method uses more from other class)
class OrderService {
generateInvoice(order: Order): Invoice {
const invoice = new Invoice();
invoice.customerName = order.customer.name;
invoice.customerEmail = order.customer.email; // Uses Customer fields
invoice.customerAddress = order.customer.shippingAddress; // More Customer
invoice.items = order.items;
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/migration-strategies.md
- references/refactor-guide-advanced.md
- references/refactor-guide-fundamentals.md
- references/refactor-patterns.md
- references/refactoring-patterns.md
- references/refactoring-techniques.md
FAQ
Что делает скилл dev-loop-refactor-guide?
Use when the user asks to refactor a long function or class safely, remove code smells, extract methods, untangle legacy code, or improve structure without changing behavior. Produces a step-by-step refactoring plan with characterization tests. Not for tracking debt backlogs (use dev-loop-tech-debt-tracker) or system migrations (use enterprise-legacy-migration).
Как установить скилл dev-loop-refactor-guide?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dev-loop-refactor-guide запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…