Plan or update structured refactoring work when the user asks to refactor, split a refactor into phases, preserve behavior while changing structure, introduce intentional semantic cleanup with explicit scope, or create a reusable refactoring tracking document. Use when a codebase needs a clear phased refactor plan, invariants, validation gates, and merge-ready checkpoints.
Use this skill when the task is to plan refactoring work, not to immediately implement the full refactor blindly.
This skill is general-purpose. It should travel well across repositories, stacks, and languages.
Gather planning context before proposing steps.
Classify the refactor before designing phases.
Structural, Behavioral, or Semantic.Decide whether to extend or create a tracking document.
./docs/plans/refactoring/.Build the plan in bounded slices.
Use architecture boundaries deliberately when planning semantic refactors.
Make the output immediately usable.
./docs/plans/refactoring/ as the default location for refactor schemes, plans, and handoff notes../docs/plans/refactoring/logs/ as the default location for refactor logs.If the project already has a numbered scheme such as REFACTOR-0001, reuse that style. If not, adapt the same structure to the local naming convention.
Unless the repository already has a stronger mandatory format, generate plans in this exact section order:
PurposeRefactor TypeScopeNon-GoalsInvariantsPlanned WorkValidation GatesIntentional DeltasRisks / Open QuestionsExit GoalFor every step inside Planned Work, include these exact fields:
GoalWhy this groupingGuardrailsTargetsValidationExit gateWhen work moves to a later track, add a final handoff section:
Handoff to Next TrackUse this stricter structure by default. Do not omit sections just because the answers are incomplete; mark them as provisional if needed.
Write refactor logs as durable execution records, not casual notes.
./docs/plans/refactoring/logs/ as the default log folder unless the project already uses a different established location.Unless the project already has a stronger mandatory format, generate logs in one of these canonical shapes:
Use the shared template and adapt the optional sections to the log type instead of inventing a new structure each time. For merge or parity judgment logs, prefer the dedicated merge-check template instead of the general log form. When baseline or parity expectations are not obvious from the project context, ask for the missing comparison target if needed; otherwise proceed with an explicit provisional assumption and record it in the merge check.
Every refactor plan should make these items explicit:
If any of those are unknown, mark them as provisional instead of pretending they are settled.
When the user prioritizes behavioral parity, this mode is mandatory.
Activation boundary:
Required behavior:
Claim rules:
Unknown/Provisional.Behavioral parity = Preserved is valid only when strict audit coverage is complete, including side-effect and failure-mode coverage.