Explain Diff
Turn a code change into a guided explanation that helps a reader build a mental
model, understand the implementation, and test their comprehension.
Default to a single local HTML artifact. Do not modify the reviewed repository.
Resolve the change
- Identify the repository and exact change boundary.
- For a pull request, record the repository, PR number, base SHA, and head SHA.
- For a branch or commit range, resolve both endpoints and their merge base.
- With no explicit target, inspect
git status --short, git diff HEAD, and
relevant untracked files as the current working-tree change.
- Read the complete changed-file list and diff summary before selecting details.
- Explore enough surrounding code and documentation to explain the system that
existed before the change. Follow call sites, data shapes, workflow edges,
configuration, and tests that define the behavior.
- Separate facts observed in code from inferred intent. Label uncertainty.
Build the explanation
Create these sections in order:
- Overview: Name the change boundary, summarize the result in two or three
sentences, and provide a table of contents.
- Background:
- Start with a skippable beginner-oriented model of the relevant system.
- Narrow to the exact components, contracts, and failure modes the change
touches.
- Intuition: Explain the central idea before implementation details. Use a
small concrete example with toy values and one or two reusable visual models.
- Code walkthrough: Group changes by behavior or execution order rather
than filename order. For each group, explain what changed, why it matters,
and how tests or evidence support it. Link relationships between files.
- Operational impact: Call out compatibility, rollout, failure, security,
and observability implications when relevant. Omit this section when the
change has none.
- Quiz: Include exactly five medium-difficulty multiple-choice questions.
Each question must have one correct answer, plausible distractors, and
feedback explaining every choice. Reveal feedback only after interaction.
Write with lucid, precise prose. Prefer concrete examples and smooth transitions
over exhaustiveness. Explain terminology when first introduced.
Render the artifact
Write one self-contained HTML file with inline CSS and JavaScript.
- Default path:
/tmp/YYYY-MM-DD-explanation-<short-slug>.html.
- Use the user-provided output directory when specified.
- Keep the artifact outside the reviewed repository unless the user explicitly
requests a repo-owned file.
- Build one responsive scrolling page with clear section headers and anchored
table-of-contents links. Do not use tabs for top-level navigation.
- Use a small, consistent family of HTML/CSS diagrams. Good choices include a
component/data-flow diagram, a simplified UI, or a before/after state model.
Include example data in diagrams. Do not use ASCII diagrams.
- Render code in
<pre><code> blocks and escape HTML metacharacters.
- Make quiz controls keyboard-accessible and provide visible correct/incorrect
feedback plus the explanation after a choice.
- Avoid external scripts, stylesheets, fonts, images, and network requests.
Validate before handoff
- Confirm the file starts with the current date and exists outside the reviewed
repository unless explicitly requested otherwise.
- Confirm every code block preserves whitespace through
white-space: pre or
white-space: pre-wrap.
- Confirm the HTML has no external asset or network dependency.
- Confirm all five quiz questions respond to clicks and keyboard activation,
reveal feedback, and identify the correct answer.
- Confirm every material claim maps to inspected code, tests, documentation, or
clearly labeled inference.
- Open or render the artifact when browser tooling is available and fix visual
overflow, unreadable diagrams, broken anchors, and script errors.
Return a clickable absolute path to the HTML artifact and a one-sentence summary
of the reviewed change.
Adapted from Geoffrey Litt's
explain-diff gist.
1---2name: explain-diff3description: Create a self-contained interactive HTML explanation of a code diff, branch, commit, or pull request.4---56# Explain Diff78Turn a code change into a guided explanation that helps a reader build a mental9model, understand the implementation, and test their comprehension.1011Default to a single local HTML artifact. Do not modify the reviewed repository.1213## Resolve the change14151. Identify the repository and exact change boundary.16 - For a pull request, record the repository, PR number, base SHA, and head SHA.17 - For a branch or commit range, resolve both endpoints and their merge base.18 - With no explicit target, inspect `git status --short`, `git diff HEAD`, and19 relevant untracked files as the current working-tree change.202. Read the complete changed-file list and diff summary before selecting details.213. Explore enough surrounding code and documentation to explain the system that22 existed before the change. Follow call sites, data shapes, workflow edges,23 configuration, and tests that define the behavior.244. Separate facts observed in code from inferred intent. Label uncertainty.2526## Build the explanation2728Create these sections in order:29301. **Overview**: Name the change boundary, summarize the result in two or three31 sentences, and provide a table of contents.322. **Background**:33 - Start with a skippable beginner-oriented model of the relevant system.34 - Narrow to the exact components, contracts, and failure modes the change35 touches.363. **Intuition**: Explain the central idea before implementation details. Use a37 small concrete example with toy values and one or two reusable visual models.384. **Code walkthrough**: Group changes by behavior or execution order rather39 than filename order. For each group, explain what changed, why it matters,40 and how tests or evidence support it. Link relationships between files.415. **Operational impact**: Call out compatibility, rollout, failure, security,42 and observability implications when relevant. Omit this section when the43 change has none.446. **Quiz**: Include exactly five medium-difficulty multiple-choice questions.45 Each question must have one correct answer, plausible distractors, and46 feedback explaining every choice. Reveal feedback only after interaction.4748Write with lucid, precise prose. Prefer concrete examples and smooth transitions49over exhaustiveness. Explain terminology when first introduced.5051## Render the artifact5253Write one self-contained HTML file with inline CSS and JavaScript.5455- Default path: `/tmp/YYYY-MM-DD-explanation-<short-slug>.html`.56- Use the user-provided output directory when specified.57- Keep the artifact outside the reviewed repository unless the user explicitly58 requests a repo-owned file.59- Build one responsive scrolling page with clear section headers and anchored60 table-of-contents links. Do not use tabs for top-level navigation.61- Use a small, consistent family of HTML/CSS diagrams. Good choices include a62 component/data-flow diagram, a simplified UI, or a before/after state model.63 Include example data in diagrams. Do not use ASCII diagrams.64- Render code in `<pre><code>` blocks and escape HTML metacharacters.65- Make quiz controls keyboard-accessible and provide visible correct/incorrect66 feedback plus the explanation after a choice.67- Avoid external scripts, stylesheets, fonts, images, and network requests.6869## Validate before handoff70711. Confirm the file starts with the current date and exists outside the reviewed72 repository unless explicitly requested otherwise.732. Confirm every code block preserves whitespace through `white-space: pre` or74 `white-space: pre-wrap`.753. Confirm the HTML has no external asset or network dependency.764. Confirm all five quiz questions respond to clicks and keyboard activation,77 reveal feedback, and identify the correct answer.785. Confirm every material claim maps to inspected code, tests, documentation, or79 clearly labeled inference.806. Open or render the artifact when browser tooling is available and fix visual81 overflow, unreadable diagrams, broken anchors, and script errors.8283Return a clickable absolute path to the HTML artifact and a one-sentence summary84of the reviewed change.8586Adapted from Geoffrey Litt's87[explain-diff gist](https://gist.github.com/geoffreylitt/a29df1b5f9865506e8952488eac3d524).