From tdd-workflows
Refactors code incrementally while maintaining passing tests, applying design patterns and SOLID principles for improved code quality.
How this command is triggered — by the user, by Claude, or both
Slash command
/tdd-workflows:tdd-refactorThe summary Claude sees in its command listing — used to decide when to auto-load this command
Refactor code with confidence using comprehensive test safety net: [Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.] ## Usage Use Task tool with subagent_type="tdd-orchestrator" to perform safe refactoring. Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase: ## Core Process **1. Pre-Assessment** - Run tests to establish green b...
Refactor code with confidence using comprehensive test safety net:
[Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.]
Use Task tool with subagent_type="tdd-orchestrator" to perform safe refactoring.
Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase:
1. Pre-Assessment
2. Code Smell Detection
3. Design Patterns
4. SOLID Principles
5. Refactoring Techniques
6. Performance Optimization
7. Incremental Steps
8. Architecture Evolution
9. Safety Verification
10. Advanced Patterns
Before committing:
If tests fail:
Before:
class OrderProcessor {
processOrder(order: Order): ProcessResult {
// Validation
if (!order.customerId || order.items.length === 0) {
return { success: false, error: "Invalid order" };
}
// Calculate totals
let subtotal = 0;
for (const item of order.items) {
subtotal += item.price * item.quantity;
}
let total = subtotal + subtotal * 0.08 + (subtotal > 100 ? 0 : 15);
// Process payment...
// Update inventory...
// Send confirmation...
}
}
After:
class OrderProcessor {
async processOrder(order: Order): Promise<ProcessResult> {
const validation = this.validateOrder(order);
if (!validation.isValid) return ProcessResult.failure(validation.error);
const orderTotal = OrderTotal.calculate(order);
const inventoryCheck = await this.inventoryService.checkAvailability(
order.items,
);
if (!inventoryCheck.available)
return ProcessResult.failure(inventoryCheck.reason);
await this.paymentService.processPayment(
order.paymentMethod,
orderTotal.total,
);
await this.inventoryService.reserveItems(order.items);
await this.notificationService.sendOrderConfirmation(order, orderTotal);
return ProcessResult.success(order.id, orderTotal.total);
}
private validateOrder(order: Order): ValidationResult {
if (!order.customerId)
return ValidationResult.invalid("Customer ID required");
if (order.items.length === 0)
return ValidationResult.invalid("Order must contain items");
return ValidationResult.valid();
}
}
Applied: Extract Method, Value Objects, Dependency Injection, Async patterns
Code to refactor: $ARGUMENTS"
42plugins reuse this command
First indexed Jan 22, 2026
Showing the 6 earliest of 42 plugins
npx claudepluginhub digi4care/agents --plugin tdd-workflows/tdd-refactorSafely refactors code by running tests first, then applying incremental design patterns, code smell removal, and performance optimization while keeping all tests green.
/refactorSystematically refactors code by detecting smells, applying behavior-preserving transformations, and enforcing a safety net of passing tests.
/refactorPerforms systematic code refactoring by identifying smells, adding tests, and applying atomic changes one step at a time.
/refactor-codeGuides a systematic, test-driven code refactoring process — from pre-analysis and coverage verification through incremental changes, quality improvements, performance optimization, and documentation updates.
/refactor-cleanAnalyzes code for smells and SOLID violations, then applies refactoring strategies to improve maintainability, performance, and readability.
/refactorExecutes a three-phase code refactoring workflow: analyze code smells and complexity, apply design patterns and improve naming, then validate with tests and static analysis while preserving behavior.