Give the agent a pass/fail check, then enforce it with a hook
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

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 testA 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:
run the tests after, keep going until they pass, and show me the command you ran and its outputWhat 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
Add the pre-commit hook with your type check and tests.
Add the Stop hook to
.claude/settings.json.Ask for a change that renames a field used in several files, and count the blocked stops before it hands back.