Guides
How Do You Get Claude to Write Better Code? Give It a Check It Can Run: Anthropic's Advice, the Five Ways to Do It, and What Our Own Test Found
By the Top5Apps editorial team · Published November 17, 2026 · Updated November 17, 2026 · 14 min read
Short answer: give Claude something it can run that comes back pass or fail, tell it to keep going until it passes, and ask to see the output. That one habit is the center of Anthropic's own advice, and it works in a plain prompt with no setup. Claude stops when the work looks done. A test, a build, a linter or a screenshot next to a mockup tells it whether the work is done, and gives you evidence to read in place of a claim.
(Disclosure, per The Receipts Standard: this site is produced with Claude-family tools, including Claude Code, the product this post covers. The test below ran on Claude Sonnet 5.5 inside the same setup we use to produce the site.)
Anthropic's developer account made the point on November 16 in a post that passed a million views in under a day. We read the article it links to and the documentation behind it, read more than 100 replies, and ran a small experiment of our own. The experiment didn't show better code. It showed something narrower, and we report it as we found it.
The short version
- The advice is one sentence. Anthropic's documentation: 'Give Claude something it can run that comes back pass or fail.'
- Ask for evidence. Have Claude show the command it ran and the output, or the screenshot. A bare 'all tests pass' tells you little.
- Anthropic ranks three tests highest. End-to-end tests come first, then property tests, then differential tests. It says unit tests can pass while the feature is broken.
- There are five levels of strictness. A line in the prompt, a line in CLAUDE.md, a /goal, a Stop hook, and a second checker that didn't write the code.
- The 90% figure is narrower than it sounds. Anthropic says Claude writes and reviews about 90% of the Claude Code team's own code. It isn't a claim about coding in general.
- Our test found no quality gain on an easy task. Twelve runs all scored 400 out of 400. The checks raised the agents' confidence from about 72% to about 93% and caught one problem outside our own test set.
- The weak spot is a test that shares the code's mistake. Checks the author didn't write are worth more.
What Anthropic said
The post came from @ClaudeDevs, Anthropic's official account for developers, at 2:31 pm Pacific time on November 16, 2026. It reads: 'Claude writes better code when it can verify its work. Checks that used to be expensive, like tests, benchmarks, and end-to-end runs, are now cheap.' It had 1.05 million views and 16,000 bookmarks when we checked the next morning.
The post links to an article on Anthropic's developer blog by Addy Osmani, a member of the company's technical staff. The article makes four claims worth knowing.
- Claude writes most of Claude Code. The first sentence says that on the Claude Code team 'the vast majority of our code (~90%) is written and reviewed by Claude.' The figure describes that one team's code. It isn't a statistic about software in general.
- A second checker raised success by up to 10 points. The article says that in internal testing, 'having a separate grader check Claude's work against a rubric' improved task success by that much, 'with the largest gains on the hardest problems.' The figure comes from an April announcement of a different product, and the test was on generating structured files. Anthropic hasn't published the data.
- Checks got cheap to make. Claude can write tests, benchmarks and specs as fast as it writes code. Once written, they run as ordinary software and use few tokens.
- Checks decide how much you can hand over. Without them, the article says, 'you can really only run one or two Claudes at a time,' because you have to check everything yourself.
Anthropic's documentation gives the reason in one line: 'Claude stops when the work looks done.' If nothing tells Claude whether the work is done, you become the test suite, and each mistake waits until you notice it.
The three kinds of test Anthropic says to invest in
The article names three test types and ranks them. Each one is hard for an agent to satisfy by accident.
| Test | What it does | Why it's hard to fool | Use it for |
|---|---|---|---|
| End-to-end | Drives the real app through a user's steps, such as adding an item to a cart and checking out | The whole feature works or it doesn't, and a failure can come with a screenshot and the step that broke | Anything a person clicks through. Anthropic says to pick this one if you can only pick one. |
| Property | States a rule that must always hold, then generates thousands of inputs that try to break it | The inputs don't share the blind spots of whoever wrote the code | Parsers, converters, money, retries. The article names fast-check for JavaScript and Hypothesis for Python. |
| Differential | Feeds the same inputs to the old system and the new one and compares the answers | The old system is the answer key, so nobody has to write expected results | Migrations and rewrites, where behavior is supposed to stay the same |
The article is blunt about unit tests. They're faster and less flaky, and 'it's possible to pass them and still break the feature.' It also warns about two properties of any test. A flaky test teaches the agent to run it again in place of fixing the code. A slow test gets run less often, and that makes failures harder to trace.
Five ways to give Claude a check, from lightest to strictest
Anthropic's documentation lists these in order of how much they depend on Claude's own judgment. The first works today in any Claude product. The rest are features of Claude Code, which we cover in our ranking of AI coding tools.
1. Put the check in the prompt
Name the command and tell Claude to keep going until it passes. Claude decides for itself when it's satisfied, and no setup is needed.
In the prompt
Fix the date bug in the invoice export. Run npm test after each change and keep going until it passes. When you're done, show me the command you ran and its output.The last sentence matters. The documentation says to ask for evidence, meaning 'the command it ran and its output, or the screenshot.' A bare statement that all tests pass tells you very little.
2. Put the command in CLAUDE.md
CLAUDE.md is the instructions file Claude Code reads at the start of every session. The documentation calls the command that runs your check 'the single most useful line' in it. One line saves you from repeating step 1 in every prompt.
CLAUDE.md
Before you report a task as done, run: npm run lint && npm test
Paste the output. If a check still fails after three attempts, stop and tell me what you tried.3. Set a goal
The /goal command sets a finish condition for the session. After every turn, a separate model checks whether the condition holds, and Claude keeps working until it does. The checking model reads the conversation and doesn't run anything itself, so the condition has to be something Claude's own output can show.
In Claude Code
/goal all tests in test/auth pass and the lint step is clean4. Enforce it with a Stop hook
A hook is a command Claude Code runs at a fixed point, whatever the model decides. A Stop hook runs when Claude tries to end its turn. If your script exits with code 2, Claude Code sends the error output back to Claude and the turn continues. This is the first option on the list that the program enforces. The others rely on Claude remembering.
.claude/settings.json (adapted from Anthropic's documentation)
{
"hooks": {
"Stop": [
{
"hooks": [
{ "type": "command", "command": "npm test 1>&2 || exit 2" }
]
}
]
}
}The documentation notes one safety valve. If the hook blocks eight stops in a row with no tool call in between, Claude Code lets the turn end.
5. Have someone else check
Two built-in commands bring in a checker that didn't write the code. /code-review reviews the change in a fresh subagent that never saw your conversation. /verify builds and runs your app and looks at the result, which catches problems that tests and type checks miss. If your project has its own skill named verify, Claude Code version 2.1.286 or later tells Claude to run it before each commit. Anthropic's July article on verification loops shows how to turn a check you do by hand into a skill.
How Anthropic's own team keeps its checks honest
The second half of the article describes rules the Claude Code team uses on its own code. They're aimed at teams, and three of them apply to anyone.
- Three failed rounds bring in a person. Claude runs the checks and tries to fix what fails. If a check still fails after three rounds, Claude stops and a person takes over.
- A change can't edit the check that judges it. The team keeps its review rules on a branch the change can't touch. The article's words: 'If a change can modify the check that judges it, the check is broken.'
- Cheap checks run first. Claude runs the tests, the build and the linter before it opens a pull request, so shared review time isn't spent on bugs it could have caught alone.
- Checks start in observe mode. A new gate logs what it would have blocked before it's allowed to block anything. The team reviews the false alarms first.
- Flaky tests get fixed or deleted. Claude 'can't skip them, add sleeps or retry until they pass.' If it can't find the cause, it deletes the test and writes down why.
- Misses become rules, and rules get pruned. A bug that slipped through becomes a written rule. The team also tidies its test suites and instruction files on a routine, because they only grow otherwise.
Anthropic gave numbers for the result in an October article on code review. From June to September 2026, merged pull requests to Claude Code more than doubled, and the share that had to be reverted fell by more than 40%. Those are the company's own figures about its own team.
We tested it: twelve runs, two rounds
We wanted to see the effect ourselves, so we ran a small experiment on November 17. Each run was a fresh Claude Sonnet 5.5 agent inside Claude Code, given the same job: write a Python function that decides whether a software version number satisfies a version range, following the rules of a widely used JavaScript library. The job has many edge cases. We scored every result against 400 hidden cases whose correct answers came from the library itself.
- Round 1 used a full written specification. Three agents were forbidden to run any code. Three were told to write their own tests, run them and fix failures.
- Round 2 used a one-sentence task. The agents were told only to match the library's behavior. Three couldn't run anything. Three got a black-box copy of the library to compare against, which is the differential test from Anthropic's article.
| Round | Could it check its work? | Score on 400 hidden cases | What the checks found | Agent's own confidence |
|---|---|---|---|---|
| 1 · full spec | No | 400, 400, 400 | No checks were run | 72%, 72%, 72% |
| 1 · full spec | Yes, with tests it wrote | 400, 400, 400 | All three test files passed on the first run | 72%, 80%, 72% |
| 2 · one-line task | No | 400, 400, 400 | No checks were run | 72%, 72%, 80% |
| 2 · one-line task | Yes, against the real library | 400, 400, 400 | Two runs: 0 mismatches in 6,000 random comparisons. One run: 83 mismatches in 6,001, fixed, then 0 in 30,001. | 93%, 92%, 93% |
The headline result is a null. All twelve functions scored 400 out of 400, with checks or without. On a small, well-known problem, this model wrote correct code the first time, and running checks didn't make the code better.
The checks changed two other things.
- They changed what anyone could know. The agents that couldn't run code put their own odds of being fully correct at 72% to 80%. They were right, and neither they nor we could tell until something ran. The agents that compared 6,000 or more random inputs against the real library reported 92% to 93%, and they had the numbers to show for it.
- They found a problem on inputs we hadn't thought of. One agent generated stranger inputs than we did, including malformed ranges that our task said would never occur. Its first comparison found 83 disagreements in 6,001. It worked out the rule, which is that the library rejects a whole range when any part of it is malformed, fixed the code and re-ran until 30,001 comparisons agreed. Our hidden cases contain no inputs of that kind.
- Self-written tests added the least. In round 1 the agents tested their code against their own reading of the specification. Every test passed immediately, and their confidence barely moved. A test written from the same understanding as the code can only confirm that understanding.
The limits of this test are large. It's one task, one model and three runs per condition. The task was too easy to show the quality gain Anthropic describes, and Anthropic's own figure says the gains are largest 'on the hardest problems.' A fair test of that claim needs a messier job, such as a feature spread across many files in a real app. We haven't run one.
What the checks look like on a real project: ours
This site is built with Claude Code, and every post passes a set of checks before it goes live. They're ordinary scripts that return pass or fail, and the agent has to show their output. Here is what they caught on the post we published yesterday.
- A link check fetched all 60 outside links. Two came back blocked, and we confirmed both by opening them in a browser.
- A style check flagged two sentence fragments that broke our writing rules. Both were rewritten before publishing.
- A render check on the preview caught a diagram subtitle that was too long for its box.
- A second look at an automatic count changed a number in the post. Software detected the cuts in a video. Checking every cut against still frames showed it had missed three and had counted two flashes of light as cuts.
- A check on the live page ran after the deploy. It confirmed the page, its five images and its sitemap entry all loaded.
None of those checks is clever. Each one exists because a mistake of that kind once reached the page. That matches the article's advice to turn each miss into a rule.
For visual work, the check is a screenshot
A test suite can't tell you a page looks wrong. Anthropic's documentation lists 'a browser screenshot next to the mockup' as a valid check, and the article says to give Claude 'hands and eyes on the real running system' through a browser extension, a phone simulator or a tool that drives the app.
A prompt for design work (ours)
Build the pricing section to match mockup.png.
When it renders, take a screenshot at 1440 pixels wide and at 390 pixels wide.
Put each screenshot next to the mockup and list every difference in spacing, type size, color and alignment.
Fix the differences and repeat. Stop after three rounds.
Show me the final screenshots and the list of differences that remain.People replying to Anthropic's post described the same habit in other media. One developer wrote that the quality of their video renders rose 'once Claude had to screenshot the frames and score them before saying done.' Another runs tests from hooks every time a file is saved and has Claude write a failing test first. These are individual reports, and we haven't verified their results.
A screenshot comparison is softer than a test, because a model is judging the picture. Keep the three-round limit, and look at the final screenshots yourself.
Where this advice runs out
- The test can share the code's mistake. A developer replied to Anthropic: 'passing checks mean little when code and tests share the same wrong assumption.' Our round 1 showed that in miniature. The article's answer is to prefer checks the author didn't write: generated inputs, an old system used as the answer key, or a reviewer that never saw the conversation. Another reply asked whether people should write the property tests themselves for the same reason. Anthropic's article doesn't say.
- Checks cost tokens and time. One reply complained that verifying 'eats all your tokens.' Anthropic's argument is that a test, once written, runs as normal software. In our small runs the agents with checks used about the same number of tokens as the agents without. Most of each total was the fixed context every session loads, so that comparison is rough. Our token counter explains what a token is.
- A goal is checked by reading. The model that judges a /goal condition reads the conversation. It doesn't run your tests. If Claude never ran them, the condition can't be confirmed.
- A check the agent can edit proves nothing. If the task lets Claude change the tests, a pass may mean the tests were weakened. Keep the checks where the change can't reach them, or review test changes yourself.
- Easy work doesn't need much. Our test and Anthropic's own figure point the same way. On a small, well-understood task the first draft is usually right, and the check mostly buys certainty.
- Rules pile up. A reply asked how to decide which rules to remove, since a rule that works and a rule that's dead look the same. The article says the team prunes on a routine and doesn't say how it chooses.
What to do, by how you use Claude
- You use Claude in the chat app. Ask for the check in the prompt. Tell it what a correct answer looks like, ask it to test its code where it can run code, and ask to see the output.
- You build alone with Claude Code. Put your test and lint commands in CLAUDE.md, run /verify before you commit, and add a Stop hook for the one check you never want skipped.
- You design or build front ends. Give Claude a reference image and a way to take screenshots. Ask for the differences as a list.
- You run a team. Keep review rules on a protected branch, send a failure to a person after three rounds, and start every new gate in observe mode.
- You're migrating old code. Use the old system as the answer key and compare on random inputs. It was the only check in our test that found something we hadn't thought of.
Our read
The advice is right, and it's older than AI. A developer who runs the code before saying it works is more reliable than one who doesn't, and the same holds for a model. What's new is the price. Writing a test used to cost an afternoon, and Claude now writes one in the time it takes to ask.
Anthropic's headline oversells one thing. 'Claude writes better code when it can verify its work' is true where the work is hard enough to get wrong, and our twelve runs show it isn't always that hard. On a small, familiar task the code came out right every time. The checks gave us proof, and proof is what lets you stop reading every line.
That is the stronger argument for the habit. The article says your job becomes 'defining what “done” looks like and reviewing the evidence.' You can only make that shift if evidence exists. An agent that says it's 72% sure and is right every time still needs you to check every time.
If you take one step today, add the line to your prompt: name the check, tell Claude to keep going until it passes, and ask for the output. We'll run a harder version of our test on a real multi-file feature and add the results here.
Where these apps rank
