Agent skill
refactor
Use when the user wants to refactor, clean up, restructure, or reorganize existing code without changing behavior.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/refactor-huzaifa525-claude-code-optimize
SKILL.md
Refactor: $ARGUMENTS
Rules
- NEVER change behavior — only improve structure
- ALWAYS run tests before AND after
- Make small, incremental changes
- Each change should be independently verifiable
Steps
-
Run tests first — establish baseline
[test command]If tests fail BEFORE refactoring, STOP and tell the user.
-
Read the code to refactor and understand it fully
-
Read the tests for this code — understand what behavior is expected
-
Identify refactoring opportunities:
- Extract method (function too long)
- Extract variable (complex expression)
- Rename for clarity
- Remove duplication (DRY)
- Simplify conditionals
- Replace magic numbers with constants
- Reduce nesting depth
- Split large files
- Improve type safety
-
Apply changes incrementally
- One refactoring at a time
- Run tests after each change
- If tests fail, revert immediately
-
Run full test suite
[test command] -
Report
## Refactoring Summary ### Changes - [what was refactored and why] ### Before → After - [specific improvements] ### Tests - All [X] tests passing - No behavior changes
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?