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.
Before touching a shared module: what it depends on, what depends on it, and which of those dependencies are risky — direction mapped, cycles flagged.
The cost of changing shared code is set by its dependencies — and dependency knowledge is usually tribal. This prompt uses the architecture mode focused on one module's position: what it depends on (and how hard), what depends on it (and how visibly), dependency direction made explicit with cycles and inversions flagged, and the risk assessment a senior audience actually wants: which of these dependencies are fragile, version-locked, or carrying contracts that mostly exist by convention. The strategy's data-flow lens shows what information crosses each dependency edge — which is where breaking changes actually break.
Map both directions
Dependencies and dependents — the module's real position, not its folder.
Follow the data across edges
What information crosses each dependency line — where breaking changes actually break.
Rank the risk
Fragile, version-locked, convention-only contracts named — the dependencies to fear, ordered.
It maps and flags them but stops there — the strategy step "Map dependency direction explicitly — and flag any cycles or inversions" is explanation, and NON-GOALS bars refactoring or rewrites. The notFor line points cycle-breaking to the Refactor Prompt Builder's Architecture Cleanup goal. This generates an explanation prompt you run in your assistant; acting on the findings is a separate tool.
It quarantines them under ASSUMPTIONS, labeled as INFERENCE. The prompt separates "what the code DOES (verifiable from the source)" from why, and where behavior is unclear it must say "cannot be determined from this code" rather than fill the gap with a plausible story. For the pricing module consumed by checkout, invoicing, and the partner API, that keeps blast-radius claims evidenced.
"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.