| name | refactor-safe |
| description | Use for safe refactors that preserve behavior. Keep diffs small and verification strong. |
| allowed-tools | Read, Grep, Glob, Bash, Edit, Write |
| when_to_use | Use automatically only when the change must leave behavior identical. |
| argument-hint | [file or module to refactor] |
refactor-safe
Behavior must be identical before and after. If tests don't exist: write them FIRST, then refactor.
-
One concern per diff: rename | move | extract | restructure — never combine two.
-
Run tests before edit, record baseline. Apply ONE mechanical transformation only. Run same tests after — must be identical pass/fail.
-
Diffs >150 lines → split into sequential mini-refactors. No features/bugfixes in same diff.
-
Read budget: refactored file + grep for symbol importers + existing test file. Imports updated across independent files → apply in one parallel batch.
-
Refactor that moves a module boundary (extract, restructure): run /arch-check before and after. The point of a boundary refactor is that violations go down — unmeasured, "cleaner" is an opinion.
Deep reference: agent_docs/testing-strategy.md (baseline coverage before refactor) · agent_docs/architecture.md (module boundary rules).
Output
CONCERN: [rename | move | extract | restructure]
· [files changed — count]
TEST BEFORE: [N passed] → TEST AFTER: [N passed — ✓ identical]
RISK: low