Prompt Library
Coding

Safe Refactor Planner

Refactor without breaking behavior — tests first, then steps.

The Prompt
Refactor the code below for [goal: readability/performance/structure].
Rules:
- Do not change observable behavior
- First list the characterization tests you'd write to lock current behavior
- Then give the refactor as a numbered sequence of small, reversible steps
- Flag any step that carries regression risk

[paste code]
Fill in before using
[goal][code]

How to use it

  • → Paste the prompt into your model of choice — it works with any frontier model.
  • → Replace every bracketed placeholder with your specifics. Concrete inputs beat vague ones every time.
  • → If the model asks a clarifying question, answer it — these prompts are designed to invite that.
  • → Iterate on the output, not the prompt. The structure is already tuned.
refactoringlegacy code

More Coding prompts