Agent skill
refactor-safe-workflow
Orchestrate safe refactoring with multi-step validation
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/refactor-safe-workflow
SKILL.md
Refactor Safe Workflow Skill
Overview
Run safe refactors with validation and behavior preservation.
Usage
/refactor-safe-workflow
Identity
Role: Senior Architect & Refactorer Objective: Restructure code to improve quality/maintainability without altering external behavior.
Core Rules
- Green-Red-Green: Tests must pass before you start. If they fail mid-change, revert to Green immediately.
- Steps, not Leaps: Break changes into atomic moves (Rename, Extract, Move).
- Preserve Behavior: Do not fix bugs or add features during refactoring (unless blocking).
Multi-Agent Pipeline
Stage 1: Assessment (Architect Agent)
- Input: Target file/module.
- Action: Identify code smells (Long Method, God Class, Duplication).
- Output: architectural refactoring plan (
refactor_plan.md).
Stage 2: Safety Check (Test Writer Agent)
- Action: Run existing tests.
- Gap Analysis: If coverage < 100% on target logic, create Characterization Tests.
- Goal: Lock in current behavior (even bugs) to ensure we don't accidentally "fix" or break things silently.
Stage 3: Execution (Refactorer Agent)
- Loop:
- Apply one refactoring move from plan.
- Run tests.
- If Pass: Commit (
refactor: ...). - If Fail: specific Undo changes, verify Assumption, Retry or Pivot.
Stage 4: Review (Code Reviewer Agent)
- Check: Is the code actually better? (Cyclomatic complexity reduced? Naming clearer?).
Usage Example
/refactor --target src/legacy/OrderManager.ts --goal "Extract Payment Logic"
Error Recovery
- Test Failure: Instant revert (
git reset --hard HEAD). Do not try to "debug" a refactoring. Logic should be preserved by definition. - Type Errors: Fix immediately. Do not use
ts-ignore.
Outputs
- Refactor plan and validation notes.
Related Skills
/verify-code- Post-refactor review
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?