Autonomous workflow for systematic code refactoring with test coverage verification and rollback safety. Handles code smell detection, refactoring planning, incremental execution with test verification, and rollback on failure.
- Phase 1: Assessment — Detect code smells (long functions, deep nesting, duplication, god classes, etc.), measure baseline metrics
- Phase 2: Safety setup — Ensure tests pass, create branch, define rollback criteria
- Phase 3: Planning — Prioritize refactoring targets, plan incremental steps
- Phase 4: Incremental execution — Apply one refactor at a time, run tests after each step
- Phase 5: Verification — Before/after metrics, confirm behavior unchanged
clean-code— Clean code principles, anti-patterns, refactoring catalogcode-review— Code review patterns and checklists
- "refactor this module"
- "clean up this code"
- "improve code quality in [path]"
- "restructure [module/component]"
- "reduce complexity in [path]"
- "this code has too many smells, fix it"
From your project root:
mkdir -p .cursor/agents
cp -r ~/.ai-skills/agents/refactoring .cursor/agents/refactoringmkdir -p ~/.cursor/agents
cp -r ~/.ai-skills/agents/refactoring ~/.cursor/agents/refactoringFrom your project root:
mkdir -p .claude/agents
cp -r ~/.ai-skills/agents/refactoring .claude/agents/refactoringmkdir -p ~/.claude/agents
cp -r ~/.ai-skills/agents/refactoring ~/.claude/agents/refactoringFor best results, also install the skills this agent references (see Skills Used above). Requires a clean git tree and passing tests before starting.
Part of the Agents directory.