Skip to content
RefactoringIntermediateVersion 1.0Works with any capable model

Refactoring Plan in Small Safe Steps

Turn a refactoring goal into an ordered series of small, individually verifiable steps with a safety net for each.

When to use it

Use it before a refactoring that touches more than one function: restructuring a module, replacing a dependency or splitting a class. The prompt breaks the goal into steps that each leave the code working, says how to check each step, and identifies what tests must exist before you begin.

When not to use it: Do not use it to change behaviour: a refactoring keeps behaviour the same. If you also need new features or bug fixes, plan those separately. It is not worth running for a rename or a change you can finish in minutes.

Required inputs

PlaceholderWhat to provideExample
{{refactoring_goal}}What you want the code to look like or achieve, and why.Move all pricing rules out of the OrderController into a separate pricing module so they can be tested and reused by the report job.
{{code_overview}}The relevant code or a description of its structure, size and main dependencies.OrderController is about 900 lines; pricing logic is spread across three methods and uses controller fields for discount state.
{{test_situation}}The tests that exist, how long they take and how much you trust them.Few unit tests. A slow end-to-end suite of about forty scenarios covers checkout.
{{constraints}}Other work in the same area, release timing, and what must not change.Two other developers edit the controller weekly. The public API responses must not change.

The prompt

Fill in each {{placeholder}} before you send it.

You are a senior engineer planning a behaviour-preserving refactoring. Produce a plan made of small steps, each of which leaves the system working.

<refactoring_goal>
{{refactoring_goal}}
</refactoring_goal>

<code_overview>
{{code_overview}}
</code_overview>

<test_situation>
{{test_situation}}
</test_situation>

<constraints>
{{constraints}}
</constraints>

Produce:
1. The behaviour that must be preserved, stated as observable facts, and the risk if the existing tests do not cover it.
2. Safety net: the tests or checks that should exist before the first change, and the cheapest way to add them. If the safety net is inadequate, make building it step zero.
3. An ordered list of steps. Each step has: what changes, why it is safe, how to verify it (which tests or checks, and what to compare), and how to undo it. Each step should be small enough to review in one sitting and should leave the code releasable.
4. Where it helps, use patterns that keep old and new code side by side, such as extracting then redirecting calls, so each step is reversible.
5. Coordination: how to reduce conflicts with the other work in the area.
6. What not to do in this refactoring.

Rules:
- Use only the code and facts provided. If the plan depends on a detail you have not been shown, state your assumption and mark it "Confirm".
- Do not change behaviour, fix bugs or add features in any step. List bugs you notice separately under "Noticed, out of scope".
- Do not propose a large rewrite. If a step seems larger than a day's work, split it.
- Do not claim that any step is safe without naming the check that shows it.

Output format:
Behaviour to preserve
Safety net
Steps (numbered; each with Change | Why safe | Verify | Undo)
Coordination
Noticed, out of scope
Confirm before starting

Expected output

A statement of the behaviour to preserve, a safety net section that treats missing tests as step zero, and a numbered list of small steps each with its change, reason it is safe, verification and undo. For the example it would extract the pricing methods unchanged, redirect callers one at a time, move discount state out of the controller last, and record noticed bugs without fixing them.

Sample response (excerpt)Illustrative — your output will differ
Safety net
Step 0: add characterisation tests for the three pricing methods, using about ten representative baskets, before changing structure.

Steps (excerpt)
1. Change: copy calculateBasketTotal into a new PricingService unchanged, with the controller field it reads passed in as an argument.
   Why safe: nothing calls the new code yet.
   Verify: the new tests run against both the old and the new function and give equal results.
   Undo: delete the new file.
2. Change: make the controller call PricingService for the total, leaving the old method in place but unused.
   Verify: end-to-end checkout scenarios unchanged.
   Undo: revert the one-line call.

Noticed, out of scope
- Discount is applied before tax in one path and after in another (Confirm whether intentional).

Limitations

  • The assistant cannot see which tests really cover the code, so its safety net is a proposal rather than an assessment.
  • Plans from a partial view of the code can miss hidden dependencies such as reflection, configuration or other services that call the code.
  • It may propose more steps than the work justifies. Merge steps that are trivially safe, but keep verification between risky ones.
  • It cannot judge team conventions or review capacity. Adjust step size to how your team works.

How to validate the output

Do these before relying on anything the model returns.

Written by
PromptFable Editorial
Last updated 13 Nov 2026
Review
Not yet reviewed

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.