refactoring-safety
Refactoring Safety
Plan and run refactors as behavior-preserving, step-checked, reversible work. Keep behavior changes separate from restructuring.
When to Use
Use when restructuring existing code is planned or underway and behavior must not change: extracting modules, renaming, inverting dependencies, replacing internals behind a stable surface. Out of scope: deciding whether the new structure is the right design, behavior changes and feature work (including "while we're in there" fixes), splitting an already-written mixed diff for review, and performance optimization that intentionally changes observable timing or output.
Required Inputs
- The code or surface to refactor and the goal of the restructuring.
- Test coverage signals for the touched surface: which behaviors are exercised by existing tests, when known.
- Known consumers of the touched surface (callers, other services, serialized data), when supplied.
If no refactoring target is provided, emit the BLOCK template; do not invent the codebase.
Select the mode in this order: if the user requests planning or analysis, use plan even when implementation is also authorized; do not execute transformations. Otherwise, use execute only when the user requests implementation now and authorizes it. Conditional future authorization, authorization alone, and unclear requests use plan.