The explain-back technique: catch bugs without reading every line
I build Settl, an expense-splitting app, solo with Claude, which means nobody reviews my code unless I make the machine do it. The cheapest review I know is a single question: paste the code and ask what it actually does. If any part of the answer surprises you, you just found a bug.
The principle
Code does what it says, not what you meant. Every bug lives in the gap between those two, and you cannot see the gap from inside your own head, because you read your intentions into your own code. A model has no access to your intentions. It reads only the text. That makes its explanation a clean mirror: wherever the mirror disagrees with your memory, either the code is wrong or your understanding is, and both are worth discovering before you ship.
The three prompts
Plain explain, for any code you are about to change:
Explain what this code actually does, step by step. Do not describe what it
is probably meant to do. Describe only what it does, including edge cases:
empty inputs, boundaries, failures, concurrent calls.
The on-call framing, for modules with state and side effects:
Explain this module as if I am the on-call engineer and it just paged me at
3am. What state does it touch, what can fail, and what does each failure
look like in the logs?
The surprise hunt, the sharpest of the three:
Read this function and tell me what would surprise the person who wrote it.
List behaviors that are true but probably unintended.
A worked example
A daily-summary feature in a generic Node app groups records by day:
// src/reports/daily.ts
export function groupByDay(items: Item[]) {
const days: Record<string, Item[]> = {};
for (const item of items) {
const key = new Date(item.createdAt).toISOString().slice(0, 10);
(days[key] ??= []).push(item);
}
return days;
}
The explanation came back: "Groups items by UTC calendar day. An item created at 7am on March 2 in Singapore lands in the March 1 bucket, because toISOString always uses UTC."
Surprise. I meant local days. Every user east of London would see some of yesterday's entries filed under the wrong day, and it would look random to them. Nothing here is broken in the crash sense, no test on a UTC configured CI box would ever flag it, and I found it without reading the loop, because the explanation said "UTC calendar day" and my head said "day."
That is the pattern for a whole class of quiet bugs: timezones, off-by-one boundaries, inclusive versus exclusive ranges, "sorted" data that is sorted by the wrong key.
Where this pays off
- Your own old code. Six months later you are a stranger to it. Perfect conditions for the mirror to disagree with you.
- Inherited code. Explanation first, changes second. You also get documentation for free: save the good explanations next to the module.
- AI's own fresh output. Ask the model to explain back the code it just wrote, in a new message. It reads its own output like any other text, and it will happily report a bug in code it produced ten seconds ago. This is the cheapest code review that exists.
- Before every refactor. The explanation is your behavior spec. Refactor, explain again, and diff the two explanations. If the second one says anything new, the refactor changed behavior, whether the tests noticed or not.
Function, module, or diff
Match the prompt to the size of the target:
- Single function: use the surprise hunt. It is precise at small scale and it names concrete behaviors instead of summarizing.
- Whole module: use the on-call framing, and add one line: "what invariants does this module assume the rest of the codebase upholds?" Unstated invariants are where modules rot.
- A diff or PR: ask "explain what behavior changes if this diff merges, including behavior the author probably did not intend to change." Run it on your own pull requests before you merge them.
One honest limitation: the mirror only works if you had an expectation to compare against. Read the explanation slowly and ask, at each step, "is that what I thought?" The technique fails only when you skim.
Run this on your codebase
Paste this into a Claude session in your repo and read the answers carefully:
Pick the three functions in this repo most likely to contain a surprise:
prioritize anything touching time, money, pagination, caching, or
permissions.
For each one:
1. Explain what it actually does, step by step, including edge cases.
Describe only real behavior, not intent.
2. List anything that would surprise the person who wrote it.
3. Flag every place where a name, comment, or docstring disagrees with the
actual behavior.
Do not change any code yet. Surprises first.