A Stop hook loops until the whole session quota is gone
A Claude Code Stop hook that kept returning ok:false while a background agent ran looped for about 50 minutes and used the full session quota.
- Agents
- Claude Code
- Reported
- Source checked
- Tags
- hooks, loops, usage-limits
Symptom
The agent keeps producing turns without doing anything useful, and your usage limit is suddenly exhausted.
Cause
The hook forced Claude to continue after every turn, but the task required waiting idle for a background agent, so each forced turn ended and triggered the hook again.
Fix
Make Stop hooks respect stop_hook_active and cap how many times they can block. Don't make stopping depend only on an external event the agent can't influence.
#!/usr/bin/env bash
# Stop hook: never block twice in a row
input=$(cat)
if [ "$(echo "$input" | jq -r '.stop_hook_active')" = "true" ]; then
exit 0 # allow stop
fi
# ... your check; to block once:
echo '{"decision":"block","reason":"run tests first"}'