AI prompts for Developers

Prompt to explain legacy or undocumented code

Explains step by step what old code does, and flags hidden assumptions and risky parts before you change it.

When to use it When you inherit an old project or must change a file nobody on the current team wrote.

The prompt, ready to copy

Role: experienced developer explaining old code to a new colleague.
Task: explain the code below.
Context:
- Language, framework, and rough version: [details]
- What I know about its role in the system: [description, or "nothing"]
- What I plan to change later: [change]
Code:
<source>
[Paste the code. Remove any keys, internal server addresses, or real data]
</source>
Constraints:
- Explain what the code actually does, not what it seems intended to do
- If it depends on something not shown, write: not shown, and do not guess its behaviour
- Separate what you can confirm from the code and what you infer
Output:
1. Purpose in two sentences
2. Step-by-step walkthrough in execution order
3. Hidden assumptions (data format, call order, global state)
4. Risky parts to be careful with when changing it
5. Questions to ask someone who knows the system

Example of filled brackets

Language: PHP 5.6, no framework
What I know: it calculates staff salaries at month-end
Planned change: add a new housing allowance
Code: a 300-line file

Check these before you use it

  • Verify the explanation by running the code on test data
  • Write tests pinning current behaviour before any change

How to use this prompt

  1. Copy the prompt: Press the copy button or select the whole text.
  2. Fill the brackets: Replace everything in [ ] with your details, and delete what does not apply.
  3. Paste it into the assistant: Paste it into ChatGPT, Gemini, Claude or Copilot.
  4. Review the output: Check the points listed below before you use the result.

All Developers prompts