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.
A capable engineer with zero context on your codebase needs different explanations than a junior: conventions, vocabulary, and where everything connects — not syntax.
Onboarding explanations routinely miscalibrate: they either explain programming (insulting a strong hire) or assume tribal knowledge (losing them). This prompt uses the new-team-member audience profile, which gets the calibration right: assume strong general engineering, assume zero knowledge of this system's conventions, vocabulary, and history. Codebase-specific names and domain terms get explained the way an onboarding buddy would, and every part gets connected to the bigger system — where it is called from, what depends on it. Paired with the high-level overview mode, the result is the explanation that turns week-one confusion into a working map.
Calibrate to the real reader
Strong engineer, zero codebase context — neither syntax lessons nor assumed tribal knowledge.
Decode the vocabulary
Codebase-specific names and domain terms explained like an onboarding buddy would.
Connect every part to the system
Where it is called from and what depends on it — the map that makes the code navigable.
It shouldn't — the AUDIENCE PROFILE assumes strong general engineering and zero knowledge of this system's conventions, vocabulary, or history, so it explains codebase-specific names and domain terms the way an onboarding buddy would, not the language. The code-explanation-prompt generates this as a prompt you run; the explanation's accuracy is still yours to verify against the real code.
It won't — the NON-GOALS section bars reviewing quality (no findings, severities, or verdicts), debugging failures, refactoring, and generating tests; if something looks defective it's noted as a question for the team. It's built for understanding via the high-level overview mode. The output is an explanation prompt, so decisions about fixing anything stay with your team.
The ASSUMPTIONS section forces it to separate what the code DOES from why, label any claim about intent or rationale as an INFERENCE unless a comment, test, or telling name evidences it, and say "cannot be determined from this code" instead of filling gaps with a plausible story. It's a prompt that instructs the model; you still confirm the output holds to that discipline.
"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.
The full path to taming an inherited codebase — understand it, document its architecture, pin its behavior with tests, then refactor, modernize, review, speed up, and ship it without breaking what works.
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.
Ask AI to "explain this codebase" and you get generic architecture and "read the controllers" — no reading order, no flow, nothing to act on. Here's how to explain a codebase for onboarding: a map of folders and flow, a reading path, safe first tasks, and the unknowns to confirm.