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 class everyone avoids: its actual responsibilities, its key methods, its side effects, and the paths through it — understood before anyone proposes splitting it.
Giant classes resist understanding precisely because narration fails at their scale — 900 lines of "then it does this" teaches nothing. This prompt uses the function-walkthrough mode at class scope: the contract of the class (what it is given, what it produces, what else changes), the responsibilities it actually performs — usually more than its name admits — its key methods walked with decision points and both branches, and every side effect surfaced with its timing. The honesty discipline matters at this scale: claims about why the class grew this way are inferences, labeled as such; the open questions list what reading alone cannot settle.
State the class contract
What it is given, what it produces, what else changes — the class as one unit first.
Find the real responsibilities
The jobs it actually performs, usually more than the name admits — each mapped to its methods.
Walk the load-bearing methods
Decision points with both branches, side effects with timing — depth where the behavior lives.
Replace the OrderManager name and '900-line' figure in the EXPLANATION OBJECTIVE line with your class, and paste your source into the [Paste the code to explain here] block under CODE CONTEXT. The code-explanation-prompt tool assembles this into a prompt you copy and run in your own ChatGPT or Claude; NewPrompt does not read your class itself.
Its NON-GOALS section explicitly bars reviewing code quality, proposing refactors, and generating tests, so the output stays understanding-only. Judging the class as over-grown belongs to the Code Review Prompt Generator, and decomposing it belongs to the Refactor Prompt Builder. This prompt maps responsibilities so a future split is informed, without proposing the split.
The ASSUMPTIONS section forces every claim about intent, history, or rationale to be labeled INFERENCE unless a comment, test, or telling name evidences it, and requires 'cannot be determined from this code' where reading alone can't settle it. It ends with open questions naming what to ask the team, so growth stories stay marked as guesses.
You copy the assembled prompt and run it in your own assistant, where the model produces the walkthrough: the contract, the real responsibilities, load-bearing methods with both branches, and side effects surfaced with timing. NewPrompt doesn't run the model or verify the output, so you confirm the side-effect timing and open questions against the actual class yourself.
"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.
Get up to speed on an unfamiliar codebase in an afternoon — ground the AI in the project, have it explain the hard parts, and keep what you learn.