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.
The discount rules live in code; the questions come from sales. This prompt explains implemented business logic to a technical manager — behavior and risk, minimal code.
Some explanations are not for the people who will edit the code — they are for the people who own the rules the code implements. This prompt pairs the function-walkthrough mode with the technical-manager audience: technically literate, not working in this code. The contract explains in terms of behavior, responsibilities, risks, and effort — not implementation mechanics — keeps code references minimal, and translates any cited code into a business statement. A quick-summary depth keeps it to what a decision-maker absorbs in two minutes: what the rules actually are, where they surprise, and which tradeoffs matter.
Declare the real audience
Technically literate, not in this code — the assumptions change everything downstream.
Translate code to statements
Every cited condition becomes a business sentence: who qualifies, when, and why not.
Keep it two minutes deep
The rules, the surprises, and the risks — the quick-summary depth cuts everything else.
The AUDIENCE PROFILE fixes the reader as a technical manager and instructs the explanation to stay in behavior, responsibilities, and risks, keeping code references minimal and translating any cited condition into a business statement. Code Explanation Prompt outputs that prompt; you run it in your own assistant, and it explains rather than judges.
It won't. The NON-GOALS bar reviewing code quality, debugging failures, and refactoring; anything that looks defective is noted as a question for the team, out of scope. The ASSUMPTIONS section also forces intent to be labeled INFERENCE and uses "cannot be determined from this code" rather than filling gaps with a plausible story.
Short by design. The depth is set to quick summary, calibrated to a few paragraphs a reader absorbs in two minutes, covering only the purpose, the main flow, and the one or two things most likely to surprise. Implementation detail is skipped unless omitting it would mislead, keeping the output readable outside engineering.
"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.
Build a test suite that fails for real reasons, not green decoration — coverage across unit, integration, and edge cases, then a review for the gaps.
Speed up code that works but drags — find the actual hot path instead of guessing, understand why it's slow, optimize it, and prove with tests that you changed the speed and nothing else.
Type "refactor this" on code you don't fully understand and the AI — which understands it no better — rewrites a load-bearing line. Here's how to run an explanation pass first: what the code does, what it assumes, and which lines are risky to touch, before you change anything.