r/ClaudeCode • u/vinishkapoor • 9d ago
Tips & Workflows Tested a CLAUDE.md verification section plus a Stop hook against plain Claude Code. Both wrote correct code; the difference was what stayed in the repo
Same repo, same prompt, Opus 5.5 headless. One copy got 5 verification rules in CLAUDE.md plus a Stop hook that blocks “done” while tests fail. The other got nothing extra. A hidden grader Claude never saw ran 3,000 random strings, 5,000 random orders and 7 real files against both.
Both passed everything. Plain Claude actually checked a lot on its own. It compared old and new pricing code on random orders and round-tripped 20,000 strings. But all of that lived in throwaway scripts under /tmp, and only 4 small example tests were left in the repo.
With the rules, Claude kept the checks: 13 new tests, including property tests, a differential test against the old code saved as an oracle, and a speed test.
Cost: $0.55 vs $0.35, and 157s vs 104s. That’s about 57% more cost and about 51% more time on this task.
Then a one-line bug was planted in both finished repos:
- Plain repo: 1 of 7 tests failed, and nothing forces Claude to run them
- Verification repo: 4 of 16 failed, and the Stop hook exited with code 2, which sends Claude back to fix it
Two hook details worth copying:
- The
stop_hook_activecheck gives Claude one retry, so an unfixable test can’t loop forever - The message says “Fix the code (not the tests)”, so Claude doesn’t just edit the test to go green
Caveats: each version ran once, the tasks were small and Python-only, and the bug was planted by hand rather than through a second Claude session.
The full CLAUDE.md section, settings.json and verify.sh are in the article:
https://aiparabellum.com/claude-code-verification-make-claude-check-its-work/
•
u/AutoModerator 9d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Far_Reindeer8428 8d ago
we ran something close to this and the hook was what changed behavior. the rules alone got skimmed by the third session
1
u/ainexfinder 8d ago
The planted-bug result is the useful part: a Stop hook turns "run the tests" from a suggestion into a gate. A few things tend to make that kind of gate harder to game. Running the same check in CI on the PR covers sessions where local hooks aren't loaded, and requiring review on changes under the tests directory helps enforce "fix the code, not the tests" instead of just requesting it. Mutation testing (mutmut for Python) is a cheap way to measure whether the saved tests would catch a planted one-line bug, rather than relying on one hand-planted example. Flaky tests are worth checking too, since a hook that exits 2 on a flaky failure can burn its single retry on noise.
1
u/Extra_Aide5999 8d ago
one thing to check if you copy the stop hook: which directory it looks at. ours runs from the project dir claude code was started in and reads git status there. some of our sessions start in the main checkout and then cd into a worktree per task, so for those the hook was checking a tree nobody was editing. the main checkout's log has 23 blocks over about three weeks, all from the command guard, none from the stop hook. i only noticed today while answering a question about our commit hook, which has the same blind spot.
the two details you listed are close to ours. it doesn't run the tests itself, it holds the end of the turn while code changed after the last passing quick check, and only once: after that the agent can end the turn with the result or the reason it couldn't. and the message says failures in files this turn didn't touch are another session's work in progress, to name them and leave them alone. that one matters once several sessions share a checkout.
1
u/karol207 8d ago
Did you try just the CLAUDE.md section? I'm curious whether that's what got it to keep the tests. Both versions passed your hidden grader, so the extra tests left in the repo seem like the bigger win here.