home / skills / laurigates / claude-plugins / code-refactor
This skill refactors code following SOLID principles and best practices, improving maintainability without altering behavior.
npx playbooks add skill laurigates/claude-plugins --skill code-refactorReview the files below or copy the command above to add this skill to your agents.
---
model: opus
created: 2025-12-16
modified: 2025-12-16
reviewed: 2025-12-16
allowed-tools: Task, TodoWrite
argument-hint: <file-path|directory>
description: Refactor code following SOLID principles and best practices
name: code-refactor
---
## Context
- Target path: !`test -n "$1" && echo "$1" || echo "NOT_PROVIDED"`
- File type: !`test -n "$1" && file "$1" 2>/dev/null`
- Lines of code: !`test -n "$1" && wc -l "$1" 2>/dev/null`
## Parameters
- `$1`: Required file path or directory to refactor
## Your task
**Delegate this task to the `code-refactoring` agent.**
Use the Task tool with `subagent_type: code-refactoring` to refactor the specified code. Pass all the context gathered above to the agent.
The code-refactoring agent should:
1. **Identify refactoring opportunities**:
- Long methods that should be extracted
- Large classes that need decomposition
- Duplicated code patterns
- Feature envy and primitive obsession
- Complex conditional logic
2. **Apply SOLID principles**:
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
3. **Apply best practices**:
- DRY (Don't Repeat Yourself)
- KISS (Keep It Simple)
- Extract methods for clarity
- Introduce meaningful abstractions
4. **Preserve functionality**:
- Ensure all existing tests pass
- Maintain the external API contract
- No behavioral changes
5. **Output the refactored code** with clear structure
Provide the agent with:
- The target file or directory path
- The detected programming language
- Any style guide examples from the project
The agent has expertise in:
- Behavior-preserving code transformations
- Design pattern application
- Code smell detection and remediation
- Semantic code search for similar patterns
This skill delegates code refactoring work to a specialized code-refactoring agent that applies SOLID principles and best practices while preserving behavior. It analyzes the target file or directory, detects code smells, and returns a behavior-preserving refactor with clear structure and explanations. The goal is safer, cleaner code with all tests and external APIs intact.
The skill collects context about the target path, file type, and line count, then invokes the code-refactoring subagent to perform the refactor. The subagent identifies long methods, large classes, duplicated patterns, complex conditionals, and other smells, then applies SOLID principles and recognized best practices. It runs transformations that preserve functionality and outputs the refactored code alongside a summary of changes and rationale.
What do you need to start a refactor?
Provide the target file or directory path. The skill will detect file type and line count and pass that context to the refactoring agent.
Will refactoring change public behavior or break tests?
No. The agent performs behavior-preserving transformations, ensures tests continue to pass, and maintains the external API contract.