원클릭으로
refactor
Safely refactor existing code with tests as the contract. Trigger: refactor, tech debt, code smell, clean up, restructure, reorganize
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Safely refactor existing code with tests as the contract. Trigger: refactor, tech debt, code smell, clean up, restructure, reorganize
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Create a new feature using TDD and tracer bullets. Trigger: new feature, add feature, implement feature, build feature
Break features into tracer bullet stories and tasks. Trigger: decompose, break down, split feature, tracer bullet, stories, tasks, decompose feature
Deploy to staging or production with safety checks. Trigger: deploy, ship, release, push to staging, push to production
Build or update .context.md for a module. Trigger: explore module, explore, understand module, what does this module do, context file, update context
Fix a bug with root cause analysis and regression testing. Trigger: fix bug, broken, regression, error, crash, not working, failing
Run linters, formatters, and static analysis. Trigger: lint, format, standards, style check, code quality, lint setup
| name | refactor |
| description | Safely refactor existing code with tests as the contract. Trigger: refactor, tech debt, code smell, clean up, restructure, reorganize |
Refactoring changes HOW code works without changing WHAT it does. The test suite is the contract -- if tests pass before and after, the refactoring is correct. For code without tests, write characterization tests first (see characterization-tests.md). Break refactoring into tiny commits, each leaving the codebase in a working state. Never mix refactoring with feature additions or bug fixes -- they are separate concerns with separate commits.
WRONG (big bang): RIGHT (incremental):
1. Rewrite entire module 1. Add test for current behavior
2. Update all callers 2. Make one small change
3. Fix cascading failures 3. Run tests -- still green?
4. Debug for hours 4. Commit
5. Give up and revert 5. Repeat (each commit is a safe checkpoint)
Big bang refactoring fails because you lose your safety net. When everything changes at once, a test failure could be caused by any of dozens of changes. Incremental refactoring means each commit is one change, so a failure points to exactly one cause -- and you can revert just that one step.
Step 0: WORKTREE
|__ EnterWorktree(name="refactor-[scope]")
Step 0.5: READ CONTEXT
|__ Read .context.md for the module being refactored
(If missing, run /explore-module first)
Step 1: GATHER DESCRIPTION
|__ What smells? (god function, duplication, tight coupling, etc.)
|__ What's the goal? (smaller functions, better names, extract module, etc.)
|__ Checklist:
[ ] Specific code identified
[ ] Goal is structural, not behavioral
Step 2: VERIFY CURRENT STATE
|__ Read .context.md for module context
|__ Run make check -- must be GREEN before starting
|__ Checklist:
[ ] Baseline is green
[ ] .context.md is current (explore only if missing)
Step 3: CONSIDER ALTERNATIVES
|__ Is this the right refactoring? Are there simpler options?
|__ What's the risk? What could break?
|__ Present alternatives if non-obvious
Step 4: DETAILED INTERVIEW
|__ Scope: what's IN the refactoring?
|__ Out of scope: what are we NOT changing?
|__ Save plan to working/plans/YYYY-MM-DD_refactor-description.md
|__ Wait for approval
Step 5: CHECK TEST COVERAGE
|__ Run coverage for target code
|__ Decision point:
| Coverage >= 80% --> proceed to Step 6
| Coverage < 80% --> write characterization tests first
| (see characterization-tests.md)
|__ Checklist:
[ ] Tests exist for behaviors being refactored
[ ] Tests pass before changes
Step 6: BREAK INTO TINY COMMITS
|__ List each refactoring move as a separate step
|__ Each step is independently committable
|__ Each step leaves codebase working
|__ Common moves: see catalog.md
Step 7: EXECUTE (one commit at a time)
For each step:
|__ Make the change
|__ Run make check
|__ Decision point:
| GREEN --> commit with descriptive message
| RED --> fix or revert this step
|__ Checklist:
[ ] Tests pass
[ ] No behavior change
[ ] Committed
Step 8: FINALIZE
|__ Update .context.md with structural changes
|__ Spawn review subagents:
| - architecture-reviewer (structural assessment)
| - code-reviewer (quality and principles)
|__ Score and present summary
|__ Checklist:
[ ] All tests pass
[ ] No behavior changes
[ ] .context.md updated
/refactor [file or module] -- targeted refactoring/refactor -- interactive, asks what to improve