Make Claude Code run tests before it can say “done”

A 20-line Stop hook runs the test suite whenever Claude tries to finish and sends it back on failure.

by elijahmanlockedin11226 Sep 2026

Prompt for your agent

Goal: Enforce passing tests before the agent finishes.
Setup: agents used in source: Claude; tools/MCPs stated: Stop hook.
Steps:
1. Add a Stop hook that runs your tests when Claude tries to finish.
2. If tests fail, return the failure so Claude goes back to work.
3. Related: one rulebook that overrides everything, “lanes” for job size, and permissions.ask for git push.
Rules: ask me before anything irreversible (sending, posting, paying, deleting); don’t invent data, results or tools I haven’t given you; tell me what you couldn’t verify.
Based on: elijahmanlockedin112 — https://dev.to/elijahmanlockedin112/claude-code-said-done-my-tests-said-otherwise-heres-the-20-line-fix-jc

Steps are from the source. Includes a “Based on” credit line.

I tried this

Tell the next builder. One anonymous answer each; click again to undo.

Agents, models and tools only what the source states

Agents
Claude
Tools
  • Stop hook

Sources & credit