Agent skill
refactor-whatifwedigdeeper-claude-template
Refactor code while preserving behavior and tests
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/refactor-whatifwedigdeeper-claude-template
SKILL.md
Refactor: $ARGUMENTS
Safely refactor code while ensuring tests continue to pass.
Process
1. Understand Current State
- Read the target file(s)
- Identify existing tests
- Run tests to confirm they pass before changes:
bash
npm test -- --testPathPattern="[target]"
2. Plan Refactoring
Common refactoring types:
- Extract: Pull code into separate function/component
- Rename: Change names for clarity
- Simplify: Reduce complexity, remove duplication
- Restructure: Change file/folder organization
Document what will change and why.
3. Apply Changes Incrementally
Make small, focused changes:
- One logical change at a time
- Run tests after each change
- If tests fail, fix immediately before continuing
4. Update Tests if Needed
If refactoring changes the API:
- Update test imports
- Update test assertions
- Add tests for new extracted functions
5. Validate
npm run build
npm run lint
npm test
6. Report Changes
Summarize:
- Files modified
- What was refactored and why
- Any API changes
- Test status
Refactoring Patterns
Extract Component:
// Before: Large component with embedded logic
// After: Smaller component + extracted sub-component
Extract Hook:
// Before: useState + useEffect logic in component
// After: Custom hook encapsulating the logic
Extract Utility:
// Before: Inline data transformation
// After: Pure function in lib/utils.ts
Safety Rules
- Never change behavior, only structure
- Tests must pass before AND after
- If unsure, add tests first
- Preserve public API unless explicitly requested
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?