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.
For developers in their first year: one concept at a time, every term defined before use, real values traced through every step — and "simplified" said when simplifying.
Explanations for beginners fail by skipping levels: they use the vocabulary they were supposed to teach. This prompt pairs the beginner-friendly mode with the junior-developer audience: teach, don't narrate — every explanation answers "why", one concept introduced at a time, no term used before its one-line plain-words definition, and every abstraction anchored in a concrete example with real values. The flow walks the code with a chosen scenario, showing what each step does to the actual values. Its most underrated rule protects trust: simplify the reasoning without falsifying it — say "simplified" when simplifying, and note what the full story adds.
One concept at a time
No term used before its plain-words definition — the glossary builds as the explanation goes.
Trace real values
A concrete scenario walks every step, showing what each line does to actual values.
Simplify honestly
"Simplified" is said out loud, with a note on what the full story adds — trust survives the teaching.
Its EXPLANATION STRATEGY carries a specific rule: simplify the reasoning without falsifying it, say 'simplified' out loud when simplifying, and note what the full story adds. So the generated explanation flags shortcuts instead of hiding them. It shapes the prompt you run in ChatGPT, Claude, or Gemini; the assistant writes the wording, and you confirm the simplification is fair.
The ASSUMPTIONS section forces a split: what the code DOES stays verifiable, while any claim about intent, history, or rationale is labeled an INFERENCE unless a comment, test, or telling name evidences it. Where behavior can't be read from the code, it says 'cannot be determined from this code' rather than fill the gap. It's only as reliable as the assistant running it, so spot-check the labels.
KEY CONCEPTS orders terms by how load-bearing they are for understanding the code, not by where they appear in the file, and maintains a running glossary giving each new term a one-line plain-language definition on first use. For the built-in JWT middleware example, that means the JWT-validate-then-load-user idea leads, not line one. You run the finished prompt in your assistant of choice; it produces the ordering and glossary.
"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.