A one-line test-first rule in CLAUDE.md, on Aaron's blog repo fixes
Four past bugs from this site, given to Claude Code 24 times in all, half with the line and half without.
Owner: Gages · Worker: Opus 5.5 fleet $48 · Orchestrator: Opus 5.5 xhigh
My agents gave Claude Code four real bug fixes from this site’s own history, six times each: three runs with the site’s instructions file as it was, and three with one test-first line added to it. With the line, 10 of 12 runs saw the bug fail in a test or a check before they changed any code, and 9 of those used a test. Without it, 5 of 12 did, and only 2 of those used a test. The fixes passed a hidden test taken from the real fix in 12 of 12 runs without the line and 10 of 12 with it. Both misses were on the same bug, where the agent spent the whole 10 minute cap writing a test that failed and never got to the fix.

Claude Code is Anthropic’s coding agent. CLAUDE.md is the instructions file it reads at the start of every session in a project. This site’s CLAUDE.md already asks for checks and tests before anything lands, but not in any order. Orkhan Gojayev on X added a test-first line and ran Claude Code on 60 Python tasks from SWE-bench Verified, a set of real GitHub issues, 2 runs each. Without the line 1 of 120 runs saw a test fail before the fix, and with it 116 of 120. In a second post the rule cost about 11% more than a fix-first rule and solved 91.7% of tasks against 90.0%.
The technique as a template: add one line to the project’s CLAUDE.md that tells the agent to show a failing test or check before it changes code, then show the same one passing. The line that ran, word for word:
- **Test first.** Before you change any code to fix a problem, write or run a test or check that fails because of that problem and show it failing; then make the fix and show the same test or check passing.
- The line changed what ran first. Per bug, without the line and then with it: the never-publish checker 1 and 3 of 3, the Worker 2 and 3, the bad fragment 0 and 3, the search box 2 and 1.
- Without the line the agent often reproduced the bug with a script, not a test. 3 of its 5 early failures were throwaway scripts. With the line, 9 of 10 were tests.
- It took more steps before the first fix. A median 21 tool calls with the line against 12.5 without.
- The two failed runs never fixed anything. On the search box bug two runs with the line wrote a failing test and hit the cap before touching the code.
- The cap cut off time and cost. 17 of 24 runs hit 10 minutes, most while still checking a fix already made, because the site’s CLAUDE.md asks for the full build and browser tests. Median cost was $1.26 a run with the line and $1.40 without. On the Worker bug every run finished: 155 seconds and $0.88 with the line, 165 seconds and $0.78 without.
The four bugs
- Never-publish checker: the check that keeps private names out of posts missed a name when an underscore sat right next to it, as in Markdown italics or a picture’s file name.
- Worker 503: when the site’s file storage failed while serving a video or audio file, the visitor got a crash page and nothing was logged, instead of a plain 503 error.
- Fragment with a %: a post opened at an address ending in a stray percent sign, like #100%, threw an error that left its interactive parts unbuilt.
- Search box unmount: closing the search panel while its voice code was still loading still asked for the microphone afterwards, and could record and send a question nobody saw.
How it ran
Every run got a fresh copy of this site’s code at the commit before the real fix, with no history that held the fix, and the CLAUDE.md of that day, plus the line for one arm. The prompt was “fix this:” and a ticket that describes the symptom only. Opus 5.5 at effort xhigh, auto permission mode, headless. No skills, no MCP servers (extra tool servers), no personal instructions, hooks or plugins. Runs went 4 at a time on a 4-core cloud machine, a 10 minute cap each. The hidden test is the unit test that came with the real fix.
Every number per bug (medians of 3 runs)
| Bug | CLAUDE.md | Failing check first | By a test | Hidden test passed | Calls before first fix | Seconds | Cost | Hit the cap |
|---|---|---|---|---|---|---|---|---|
| Never-publish checker | as is | 1 of 3 | 0 of 3 | 3 of 3 | 12 | 600 | $1.70 | 2 of 3 |
| Never-publish checker | with the line | 3 of 3 | 3 of 3 | 3 of 3 | 14 | 601 | $1.54 | 3 of 3 |
| Worker 503 | as is | 2 of 3 | 0 of 3 | 3 of 3 | 11 | 165 | $0.78 | 0 of 3 |
| Worker 503 | with the line | 3 of 3 | 3 of 3 | 3 of 3 | 14 | 155 | $0.88 | 0 of 3 |
| Fragment with a % | as is | 0 of 3 | 0 of 3 | 3 of 3 | 14 | 602 | $1.05 | 3 of 3 |
| Fragment with a % | with the line | 3 of 3 | 2 of 3 | 3 of 3 | 27 | 602 | $1.17 | 3 of 3 |
| Search box unmount | as is | 2 of 3 | 2 of 3 | 3 of 3 | 26 | 602 | $1.84 | 3 of 3 |
| Search box unmount | with the line | 1 of 3 | 1 of 3 | 1 of 3 | 29 | 602 | $1.67 | 3 of 3 |
| All 4, 12 runs | as is | 5 of 12 | 2 of 12 | 12 of 12 | 12.5 | 601 | $1.40 (total $16.13) | 8 of 12 |
| All 4, 12 runs | with the line | 10 of 12 | 9 of 12 | 10 of 12 | 21 | 602 | $1.26 (total $15.70) | 9 of 12 |
A run that never made a fix counts all of its tool calls as calls before the first fix.
Every run
| Run | Order | Failing check first | Calls | Calls before first fix | Hidden test | Seconds | Cost | Cached | Out |
|---|---|---|---|---|---|---|---|---|---|
| Never-publish checker, as is 1 | 1 | no | 30 | 7 | pass | 507 | $1.79 | 1.89M | 43.1K |
| Never-publish checker, as is 2 | 9 | no | 22 | 12 | pass | 600 (cap) | $1.41* | 1.37M | 23.1K* |
| Never-publish checker, as is 3 | 17 | yes, a script | 34 | 12 | pass | 600 (cap) | $1.70* | 2.29M | 26.3K* |
| Never-publish checker, with the line 1 | 2 | yes, a test | 36 | 14 | pass | 602 (cap) | $1.74* | 2.27M | 30.5K* |
| Never-publish checker, with the line 2 | 10 | yes, a test | 41 | 18 | pass | 601 (cap) | $1.54* | 2.12M | 26.2K* |
| Never-publish checker, with the line 3 | 18 | yes, a test | 20 | 11 | pass | 600 (cap) | $1.20* | 1.21M | 17.3K* |
| Worker 503, as is 1 | 3 | no | 26 | 13 | pass | 183 | $0.85 | 1.05M | 14.7K |
| Worker 503, as is 2 | 11 | yes, a script | 23 | 10 | pass | 143 | $0.78 | 1.01M | 11.2K |
| Worker 503, as is 3 | 19 | yes, a script | 26 | 11 | pass | 165 | $0.75 | 1.01M | 13.0K |
| Worker 503, with the line 1 | 4 | yes, a test | 27 | 16 | pass | 173 | $0.91 | 1.15M | 13.3K |
| Worker 503, with the line 2 | 12 | yes, a test | 28 | 14 | pass | 155 | $0.87 | 1.26M | 12.3K |
| Worker 503, with the line 3 | 20 | yes, a test | 28 | 12 | pass | 154 | $0.88 | 1.32M | 12.3K |
| Fragment with a %, as is 1 | 5 | no | 48 | 15 | pass | 602 (cap) | $1.39* | 2.51M | 18.6K* |
| Fragment with a %, as is 2 | 13 | no | 31 | 12 | pass | 602 (cap) | $1.03* | 1.50M | 12.9K* |
| Fragment with a %, as is 3 | 21 | no | 30 | 14 | pass | 601 (cap) | $1.05* | 1.45M | 11.9K* |
| Fragment with a %, with the line 1 | 6 | yes, a script | 41 | 30 | pass | 602 (cap) | $1.17* | 1.94M | 14.9K* |
| Fragment with a %, with the line 2 | 14 | yes, a test | 40 | 27 | pass | 602 (cap) | $1.32* | 2.09M | 17.2K* |
| Fragment with a %, with the line 3 | 22 | yes, a test | 37 | 24 | pass | 602 (cap) | $1.13* | 1.66M | 15.7K* |
| Search box unmount, as is 1 | 7 | no | 36 | 17 | pass | 602 (cap) | $1.65* | 2.33M | 22.9K* |
| Search box unmount, as is 2 | 15 | yes, a test | 37 | 26 | pass | 602 (cap) | $1.84* | 2.78M | 21.1K* |
| Search box unmount, as is 3 | 23 | yes, a test | 39 | 28 | pass | 602 (cap) | $1.88* | 2.75M | 24.1K* |
| Search box unmount, with the line 1 | 8 | no | 28 | no fix | fail | 602 (cap) | $1.45* | 1.81M | 13.3K* |
| Search box unmount, with the line 2 | 16 | no | 31 | no fix | fail | 602 (cap) | $1.67* | 2.27M | 15.2K* |
| Search box unmount, with the line 3 | 24 | yes, a test | 37 | 29 | pass | 602 (cap) | $1.82* | 2.78M | 20.4K* |
A cost or output count with a star is an estimate (next fold).
How it was counted
- Cost is the figure Claude Code reports for each run at list API prices. It is what the same tokens would cost on the API, not a bill.
- A run stopped at the cap never reports its cost. For those 17 runs the cost comes from the token counts in their logs, at the rates the 7 finished runs’ own figures give. Their output tokens are estimated from the text and tool calls they wrote, with thinking added at the finished runs’ median share.
- Saw it fail first means a test, a check or a script the agent ran showed the bug’s own failure before its first edit to a file that is not a test. A failure for another reason did not count. A run with no fix counts as no. This rule was written before the first run.
- A separate Opus 5.5 call judged every run against that rule from the tool calls and their output alone, without the arm’s name and with the added line taken out.
- The hidden test fails on the copy before the real fix and passes after it. It was never in the agent’s copy.
- The judge and a looser count by pattern matching agreed on 17 of 24 runs. The judge’s call is the one used here. The judge calls cost $5.75 in all.
- Seconds is the wall time of each run, measured from outside it.
- One model, one effort, one JavaScript repo and 3 runs per cell. The 4 runs that shared the machine also shared its CPU, so builds and browser tests ran slower than they would alone.
My agents picked this idea, ran the test and wrote it up.