Explain Code Prompt — the Understanding Contract
"Explain this code" gets line-by-line narration. The understanding contract gets strategy, audience-fit, design decisions, and inference labeled as inference.
Build a prompt that walks through a function line by line — what each line does and why — calibrated for a developer still learning the codebase.
Sometimes "what does this function do" is not enough — you need to follow it line by line. This builds a prompt that walks a function top to bottom, explaining what each line does and why it is there, in order, for a newer developer. The example loads a debounce utility. Open it in the Code Explanation Prompt and paste the function you are trying to follow; adjust the audience and depth to match how much you already know.
Open the example in the tool
It loads with realistic inputs already filled in.
Swap in your own details
Adjust the inputs and options to match your case.
Generate and copy
Produce the output and paste it where you need it.
It won't diagnose or fix them. The NON-GOALS section bars code-quality findings, severities, and debugging outright; if something looks defective the walkthrough only "notes it as a question for the team." For actual issue-hunting, the resource points you to the Code Review Prompt Generator instead. The generated prompt runs in your assistant.
The ASSUMPTIONS section forces it to label any claim about intent, history, or rationale as an INFERENCE unless a comment, test, or telling name evidences it. Where behavior can't be read from the source, it must say "cannot be determined from this code" rather than fill the gap with a plausible story, keeping fact and guess separated throughout.
Yes. The debounce utility loads only as a filled-in example; step two of the workflow is swapping your own function in under CODE CONTEXT. You can also retune the AUDIENCE PROFILE away from junior developer and switch the depth to overview, since the prompt calibrates every section to whoever you say is reading.
"Explain this code" gets line-by-line narration. The understanding contract gets strategy, audience-fit, design decisions, and inference labeled as inference.
For code whose authors are gone: reconstruct likely intent as labeled inference, hunt undocumented assumptions, and end with a maintenance brief — what's safe to touch.
Explain the idea before the implementation: numbered steps with their contribution, honest best/worst-case complexity, and the alternatives each decision point rejected.
"Review this code" gets shallow comments. The review contract gets findings with severities, a checklist, and a verdict.
"Refactor this code" invites silent behavior changes. The refactoring contract preserves business rules, outputs, and side effects — and flags uncertainty instead of deciding it.
"Fix this error" gets guesses. The investigation contract gets a ten-stage diagnosis: facts separated from assumptions, alternatives weighed, fixes justified.
Build code explanation prompts — mode, audience, and depth turn into an understanding contract that teaches, not narrates.