with one click
refactor
Safely refactor code with test-driven approach.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Safely refactor code with test-driven approach.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Write a structured handoff at session end. Preserves context so the next agent can resume without human briefing. Invoke before ending any feature session longer than 30 minutes.
Multi-perspective code review against project standards with P1/P2/P3 severity classification. Works in Claude Code (Agent + optional GitHub MCP) and Cursor (Task subagents + gh/git). Use when the user invokes /review, asks for a PR or diff review, or wants a standards-aligned review with severity tags.
Multi-perspective code review (P1/P2/P3) for Cursor: inline checklists plus three parallel Task subagents (perf-auditor, security-reviewer, simplicity-reviewer with combined data-integrity prompt). Use when the user invokes /review, asks for a PR review, or wants repo-standard findings with severity.
Create well-formatted git commits following conventional commit standards.
Red→green→refactor discipline for new behavior — forces a failing test before implementation and a passing test before any claim of done.
Create or manage a git worktree for isolated parallel development — lets multiple agents work in the repo simultaneously without branch collisions.
| name | refactor |
| description | Safely refactor code with test-driven approach. |
Safely refactor code with test-driven approach.
/refactor <target> [--scope <scope>] [--dry-run]
target: File, function, or pattern to refactor--scope: Limit refactoring scope (function, file, module)--dry-run: Show planned changes without executingWhen this skill is invoked:
Autonomy:
Safety:
Quality:
Verify tests exist:
{test_command} tests/ --collect-only
If tests don't exist for the target:
Run tests to establish baseline:
{test_coverage_command}
Record:
Plan the refactoring:
--dry-run, present plan and stopExecute refactoring in small steps: For each change:
Verify final state:
{test_coverage_command}
Ensure:
Present changes:
Extract Function/Method:
# Before
def process():
# 50 lines of code
# After
def process():
step1()
step2()
step3()
Remove Duplication:
# Before: Same code in 3 places
# After: Single shared function
Simplify Conditionals:
# Before
if x and y and z:
if a or b:
...
# After
if should_process(x, y, z, a, b):
...
Rename for Clarity:
# Before
def proc(d):
# After
def process_user_data(user_data):
$ /refactor src/{project}/services/user --scope module
🔄 Refactoring: src/{project}/services/user
📋 Pre-refactor state:
- Tests: 24 passing
- Coverage: 95%
- Duration: 1.2s
📝 Planned changes:
1. Extract duplicate validation logic → shared validator
2. Rename process() → process_user_request()
3. Simplify nested conditionals in update()
🔧 Executing refactoring...
Step 1: Extract validation logic
✅ Tests pass (24/24)
Step 2: Rename process()
✅ Tests pass (24/24)
Step 3: Simplify conditionals
✅ Tests pass (24/24)
📋 Post-refactor state:
- Tests: 24 passing
- Coverage: 96% (+1%)
- Duration: 1.1s (-0.1s)
✅ Refactoring complete!
Changes made:
- src/{project}/services/user: Simplified, renamed functions
- src/{project}/utils/validators: New shared validation module
- tests/unit/test_user: Updated imports
Commit suggestion:
git commit -m "refactor(user): extract validation, improve naming"