Legacy Code Explainer and Refactor Plan
Explains an unfamiliar legacy file and produces a safe, step-by-step refactor plan with tests first.
ClaudeCode & Tech
114 words · free to use
I inherited this code and need to understand it before I change it. Language/framework: [e.g. PHP 7 / jQuery / Python 2] What the app does: [ONE SENTENCE] Code: [PASTE FILE] 1. Explain what this file does, top to bottom, in plain language. 2. Map the important functions: inputs, outputs, side effects (database writes, network calls, globals). 3. List hidden risks: duplicated logic, magic numbers, error handling gaps, security issues. 4. Write characterization tests that lock in current behavior before any change. 5. Give a refactor plan in small, safe steps (each step shippable on its own), with what to test after each. 6. Show the refactored version of the single most valuable function.
How to use this prompt
- Copy the prompt with the button above.
- Replace the parts in brackets with your own details: [ONE SENTENCE], [PASTE FILE].
- Paste it into Claude and send it. It also works in other AI chat tools.
- Not quite right? Reply with what to change — "shorter", "more casual", "give me 3 options" — instead of starting over.