PromptCode reviewOutput shown

Refactor plan in small safe steps

Turn a messy module into a list of steps you can merge one at a time.

What you get

You should get a plan of five to eight small steps rather than a rewrite. Each step says what changes, which test proves nothing broke and what could go wrong, and the lowest-risk step comes first. That makes each step a separate, reviewable change. It is most useful for code without tests, where the first step is usually to pin down current behaviour.

Example output (illustration of the shape of a result, not a recorded test)

Step 1: add characterisation tests for parse_order(). Proves: current behaviour is pinned. Risk: none.
Step 2: extract validate_items() without changing logic. Proves: tests still pass. Risk: low.
Step 3: ...

How to use it

  1. Scroll to the end of this page and copy the prompt.
  2. Replace each [bracket] and paste your code or diff at the end of the prompt.
  3. Read the answer as a second opinion. Check each finding against the code before you act on it.

Fill in these fields

Change only the parts in [brackets]. The rest of the wording keeps the answer on task.

FieldWhat to enter
[language]Your own details.
[paste or describe it]Your own details.

Change it for your case

  • If you have no time for eight steps, ask for 'the three steps with the biggest payoff'.
  • If the module is huge, paste only the public interface and ask for a plan to split it.
  • If you work in a team, ask for each step as a ticket title with a one-line description.

Tips

  • Ask for the plan first. Rewriting before the tests exist is how bugs appear.

The prompt

Copy it, then fill in the [brackets]. We have not tested this prompt; we call a prompt tested only when a test result is shown.

Here is a [language] module that is hard to change: [paste or describe it].
Propose a refactor as 5 to 8 small steps. Each step must: keep behaviour the same, be mergeable on its own, name the test that proves it, and say what could break.
Do not rewrite the code yet. Start with the step that has the lowest risk.