| name | code-refactorer |
| description | Refactor code with safety checks and pattern application. Use when user says "refactor this code", "clean up this function", "simplify this logic", "extract this into a separate function", "apply the strategy pattern here", "reduce the complexity of this module", or "reorganize this file structure". |
| allowed-tools | Read, Grep, Bash(git diff:*), Bash(git show:*), Task(subagent_type:refactorer), Task(subagent_type:style-enforcer), Task(subagent_type:code-explainer), Task(subagent_type:test-writer), Task(subagent_type:agent-orchestrator) |
Code Refactorer
Orchestrate sophisticated refactoring through multi-agent coordination with safety checks.
When to Activate
- User wants to refactor code
- Code complexity needs reduction
- Design patterns should be applied
- Technical debt cleanup needed
- Code structure improvements requested
- User mentions "clean up", "simplify", or "improve"
Refactoring Strategies
| Strategy | Risk | Use When |
|---|---|---|
| Safe (default) | Low | Production code, critical paths |
| Aggressive | Medium | Comprehensive restructuring with tests |
| Architectural | High | System-wide pattern application |
Quick Process
- Analyze: Understand current structure and issues
- Identify: Detect applicable design patterns
- Plan: Create incremental, safe transformations
- Validate: Ensure behavior preservation
- Test: Generate tests for refactored code
Goals
readability: Extract expressions, rename for clarityperformance: Algorithm improvements, cachingmaintainability: SOLID principles, reduce couplingtestability: Dependency injection, pure functionsall: Comprehensive improvement
Output Format
Provides:
- Summary with metrics and risk assessment
- Analysis of current issues and patterns
- Incremental patches with diffs
- Migration plan for architectural changes
- Validation results
Safety
- Small, reviewable patches
- Dependency ordering
- Rollback procedures
- Validation checkpoints