AIToday
Large Language ModelsAI Coding AssistantsZenn AI/MLPublished: Nov 16, 2026, 04:00 JST

Custom Claude Code Stop hook loops 1,314 times, costs $335

Send on LINE
Custom Claude Code Stop hook loops 1,314 times, costs $335

3 Key Points

  1. What happened

    Without /goal, the developer's Stop hook kept sending Claude back to work because completion records were missing, cycling every 7.5 seconds for about three hours — 1,314 rejections, 2,736 context re-reads and 16.5億 tokens, about $335 at API list prices.

  2. Why it matters

    The built-in safety cutoff (which ends the loop after 8 consecutive rejections) never fired because tool calls broke the count, so a self-built hook can silently burn a week's quota.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

By signing up you agree to the Terms of Service and Privacy Policy.

Context & Analysis

The appeal of a custom Stop hook was control: instead of letting /goal's conversational check decide, the developer wanted completion judged by concrete state — a pass record, a merge to main, and CI results. Any missing piece would send Claude back to work, which sounds stricter and more reliable than the built-in option. The failure came from a gap the hook didn't cover: while background jobs like tests were still running, Claude had nothing to do but wait, so it tried to stop, got rejected, and repeated the cycle. /goal avoids this by skipping its judgment entirely while background work is in flight, but the custom hook had no such waiting mechanism. The first attempt — waiting up to 10 minutes before rejecting — only slowed the loop. The official 8-rejection cutoff exists but counts only rejections with no tool calls in between, so a hook that reads notifications or runs commands each time effectively disables it. The final trade-off was to give up "never stop" and allow a single rejection, while a separate push hook catches code that fails the checks.

FAQ
Why didn't Claude Code's built-in cutoff stop the loop?
Official documentation says Stop hooks stop after 8 consecutive rejections, but that counter only counts when no tool calls occur in between. This developer read notifications or ran commands on each rejection, so it never reached 8.
What was the token cost of the loop?
About 16.5億 tokens across 2,736 re-reads of roughly 60万 tokens each. At API list prices that comes to about $335, mostly from cache reads billed at $0.20 per 1 million tokens.
How did the developer finally stop it?
The final fix was allowing only one rejection using `if (input.stop_hook_active) process.exit(0)`, which the official docs recommend. To keep code from slipping through, they added a push hook instead.
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

By signing up you agree to the Terms of Service and Privacy Policy.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleNikkei survey: New York's 50 AI startups tied closely to finance, medical