Prompt library
Explain legacy code before touching it
Chesterton's fence, operationalized: the archaeology section explains the weirdness before you delete it, and characterization tests pin actual behavior (bugs included) so your change diffs cleanly against reality. The trap list focuses attention where your specific change meets their specific landmines.
Last reviewed July 17, 2026
The prompt
Explain the legacy code below so I can change it without breaking it.
{{code}}
What I need to change: {{change}}
Produce:
1. What it does: observable behavior first (inputs, outputs, side effects), then the mechanism. Plain sentences.
2. The invariants: conditions the code maintains that callers might rely on, including accidental ones (ordering, timing, error shapes).
3. Archaeology: for each strange-looking part, the most plausible reason it is that way (bug workaround, performance fix, dead requirement). Label each as evident or speculation.
4. The trap list: the 3 places my intended change is most likely to break something, and what to check at each.
5. A characterization test plan: the minimal tests to pin current behavior, including current weird behavior, before I modify anything.
Where behavior depends on code I have not shown you, name exactly what you would need to see.Run in idaptOpens a new chat with the prompt prefilled. Nothing sends until you press send.
Fill in the variables
| Variable | What it is | Example |
|---|---|---|
| {{code}} | The legacy code | [paste the function or module] |
| {{change}} | What you intend to do to it | add a second currency without touching rounding behavior |