refactor-code
Restructure code for improved clarity and maintainability. Use when addressing code smells or technical debt.
When & Why to Use This Skill
The Refactor Code skill is designed to systematically improve the internal structure of existing source code without changing its external behavior. It focuses on enhancing code readability, reducing cyclomatic complexity, and eliminating technical debt by applying industry-standard design patterns and SOLID principles, making the codebase more maintainable and scalable.
Use Cases
- Technical Debt Mitigation: Use this skill to address code smells identified during development, such as long methods, large classes, or deeply nested conditional logic.
- Legacy Code Modernization: Restructure older modules to align with modern coding standards and architectural patterns, ensuring long-term project sustainability.
- Code Review Implementation: Quickly apply structural improvements suggested during peer reviews, such as extracting logic into reusable methods or improving naming conventions.
- Complexity Reduction: Simplify overly complex functions to improve testability and reduce the likelihood of future bugs during maintenance.
| name | refactor-code |
|---|---|
| description | "Restructure code for improved clarity and maintainability. Use when addressing code smells or technical debt." |
| mcp_fallback | none |
| category | generation |
| tier | 2 |
| user-invocable | false |
Refactor Code
Apply systematic refactoring techniques to improve code clarity, maintainability, and performance without changing functionality.
When to Use
- Addressing code smells identified in reviews
- Reducing cyclomatic complexity
- Extracting methods and classes
- Improving naming and organization
Quick Reference
# Common refactoring patterns
# Extract method
# BEFORE: Long function with multiple responsibilities
def process_data(data):
result = validate(data)
formatted = format_data(result)
return save(formatted)
# AFTER: Clear single responsibility
def process_data(data):
validated = _validate_and_format(data)
return save(validated)
def _validate_and_format(data):
return format_data(validate(data))
Workflow
- Identify refactoring targets: From code review or analysis tools
- Plan changes: Document what will change and why
- Apply refactoring: Use IDE refactoring tools or manual changes
- Run tests: Verify all tests still pass
- Verify performance: Check no performance regression
Output Format
Refactoring report:
- Issues addressed
- Refactoring techniques applied
- Metrics before/after (complexity, lines of code)
- Test coverage status
- Performance impact
References
- See
detect-code-smellsskill for identifying issues - See CLAUDE.md > SOLID principles for refactoring goals
- See
run-testsskill for verification