When to use it

Use this prompt when you join a new team, open a legacy file for the first time, review a pull request in a part of the codebase you do not know, or evaluate an open-source library. It is also useful for learners who want to read real code rather than tutorial examples. The goal is understanding, not changes, so it pairs well with a later refactoring or debugging prompt.

How to customize it

  • [YOUR LEVEL] changes the depth of the explanation. An experienced developer new to a language needs different help from a beginner.
  • [WHERE THIS CODE COMES FROM] gives useful context: billing code and a throwaway script deserve different levels of caution.
  • [WHAT I NEED TO DO] focuses the explanation on the parts that matter for your task.
  • [EXAMPLE INPUT] makes the walkthrough concrete. A real request, file or record from your system works best (with private data removed).
  • [PASTE CODE] should include imports and the definitions of helper functions if they are short.

Why it works

A layered structure, from overview to map to trace, matches how experienced developers read code: first the purpose, then the shape, then the details. Tracing one concrete input is the most effective step because it turns abstract logic into a sequence of events you can check against the code yourself.

The rule about functions that are not shown is important. Models tend to fill gaps with plausible guesses, which is a form of hallucination. Asking the model to label inferences, and to list open questions, tells you exactly where to look next instead of giving you false confidence.

Tips and variations

  • Verify key claims by running the code with the example input or stepping through it in a debugger.
  • For large codebases, start with the entry point and ask follow-up questions file by file.
  • Ask “Draw the call flow as a text diagram” for code with many interacting functions.
  • Add “Then give me 3 quiz questions to check my understanding” if you are learning.
  • Do not paste proprietary code into tools your company has not approved; check your policy first.