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.
Build a prompt that breaks a regular expression down piece by piece in plain language — what it matches, what each part does, and what it rejects.
A regex is the code people most often paste and least often understand. This builds a prompt that explains one the way a patient teacher would: what it matches overall, then each token broken down, with concrete examples of strings it accepts and rejects — terminology defined on first use for a developer still building their pattern vocabulary. The example loads an email-validation regex. Open it in the Code Explanation Prompt and paste your own pattern.
Open the example in the tool
It loads with realistic inputs already filled in.
Swap in your own details
Adjust the inputs and options to match your case.
Generate and copy
Produce the output and paste it where you need it.
Open the preset in the Code Explanation Prompt and replace the loaded pattern ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ inside the CODE CONTEXT block with your own regex, then edit the 'System context' line so it names where your pattern actually runs. The tool rebuilds the prompt around your pattern; you copy it and run it in your assistant.
It will not diagnose runtime failures. The NON-GOALS section states 'Do not debug failures — explain the behavior that exists without diagnosing it,' so the generated prompt explains what the pattern accepts and rejects rather than troubleshooting a bug. For failing matches, the notFor list redirects you to the Debugging Prompt Generator instead.
They are not automatically verified. The EXECUTION FLOW section tells the assistant to pick example values and follow them through every step, but NewPrompt does not run the regex or check those examples. Run the generated prompt in your assistant and confirm the accept and reject cases against a real regex tester before trusting them.
"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.