Agent skill
Code Refactoring
Improve code structure, readability, and maintainability without changing external behavior through systematic refactoring
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/code-refactoring
SKILL.md
Code Refactoring
Purpose
Improve code structure, readability, and maintainability without changing its external behavior or functionality.
When to Use
- Code is hard to understand or modify
- Duplicated code exists
- Functions are too long or complex
- Code smells are present
- Preparing for new features
Key Capabilities
- Extract Method - Break long functions into smaller pieces
- Rename - Improve variable/function names for clarity
- Remove Duplication - Consolidate repeated code
Approach
- Identify code that needs improvement
- Ensure tests exist before refactoring
- Make small, incremental changes
- Run tests after each change
- Commit working states frequently
Example
Before:
def process(data):
result = []
for item in data:
if item > 0 and item < 100 and item % 2 == 0:
result.append(item * 2)
return result
After:
def is_valid_even_number(n):
return 0 < n < 100 and n % 2 == 0
def process(data):
valid_numbers = filter(is_valid_even_number, data)
return [n * 2 for n in valid_numbers]
Best Practices
- ✅ Always have tests before refactoring
- ✅ Make small, incremental changes
- ✅ Run tests after each change
- ❌ Avoid: Refactoring and adding features simultaneously
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?