Skip to content
Schemory
Article worksNew

Give the agent a pass/fail check, then enforce it with a hook

Log in to cache0 cached it

An agent stops when the work looks done. Give it a command that says pass or fail, and wire that command into a hook so "done" means green.

Reported by @juliandierker · Verified 2026-11-21

Agent
Claude Code
Stack
TypeScript

Problem

Without a check to run, the agent has only its own judgement of "looks finished". It reports success with type errors, red tests or unformatted files still in the diff. Anthropic's Claude Code guide and AI Hero both put this first: the agent needs a feedback loop it cannot argue with.

Setup

The agent edits, the hook runs type check and tests, a failure goes back to the agent, only green reaches the commit

Two layers. A pre-commit hook blocks a bad commit, as in AI Hero's "Essential AI Coding Feedback Loops":

# .husky/pre-commit
npx lint-staged
npm run typecheck
npm run test

A Stop hook blocks the agent from ending its turn on a red type check, as in Anthropic's best-practices page. Exit code 2 sends stderr back to the agent:

{
  "hooks": {
    "Stop": [{ "hooks": [{ "type": "command", "command": "npx tsc --noEmit 1>&2 || exit 2" }] }]
  }
}

Then ask for evidence, not a summary:

Closing instruction
run the tests after, keep going until they pass, and show me the command you ran and its output

What happened

Without it

"All tests pass", with no output, and three type errors left for review.

With it

The agent reads the hook's error, fixes it, and only hands back on green. Repetition costs it nothing, so it keeps going where a person would give up.

Sources: Best practices for Claude Code, Essential AI coding feedback loops (AI Hero).

Reproduce

  1. Add the pre-commit hook with your type check and tests.

  2. Add the Stop hook to .claude/settings.json.

  3. Ask for a change that renames a field used in several files, and count the blocked stops before it hands back.

Worth keeping?

Cache it and it lands on your page, next to everything else you keep.

Score 0 from caches on Schemory

Log in to cache0 cached it

NewAt 10 caches a report turns Trusted.