claude-code-notifier
how it works guides faq
◐English
English العربية Deutsch Español Français עברית Italiano 日本語 한국어 Nederlands Polski Português (Brasil) Русский Türkçe Tiếng Việt 简体中文 繁體中文
Get started
All guides

Claude Code stop hook block cap: why a hook stopped blocking

Updated 27 November 2026 · 4 min read
on this page 01Why the cap exists 02What happens when the cap is reached 03Changing the cap 04Write the hook so it never needs the cap 05Stop hooks and long unattended runs 06FAQ

Claude Code caps how many times in a row a Stop hook can keep Claude working. A Stop hook that returns "decision": "block" (or exits with code 2) tells Claude to carry on instead of finishing. After stop hooks have continued the turn eight times in a row, Claude Code overrides the next block and ends the turn anyway, and shows a message that a hook blocked the turn from ending several consecutive times. The CLAUDE_CODE_STOP_HOOK_BLOCK_CAP environment variable changes the limit, and 0 turns the cap off.

01Why the cap exists

A Stop hook that blocks is a loop: Claude tries to finish, the hook says "not yet", Claude works some more and tries again. If the condition the hook checks can never be met, for example a test that cannot pass or a file that will never appear, the loop has no end and burns through your usage. The cap is a backstop for that case.

According to Anthropic's hooks reference, the count is of consecutive continuations. It resets each time Claude calls a tool, so a hook that blocks, after which Claude actually runs commands and edits files, is not the pattern the cap is aimed at. The cap bites when Claude keeps trying to stop without doing anything new.

02What happens when the cap is reached

  • Claude Code ignores the next block and ends the turn as if the hook had allowed it.
  • You see a notice in the session saying a hook blocked the turn from ending repeatedly.
  • The hook itself is not told that its decision was overridden, so a hook that logs "blocked" will log a block that did not happen.

If you see this notice and did not expect it, your hook is blocking on something Claude cannot fix. Look at the reason your hook returns: Claude acts on it, so it has to say clearly what is still missing.

03Changing the cap

Set the environment variable before starting Claude Code:

CLAUDE_CODE_STOP_HOOK_BLOCK_CAP=20 claude

Or put it in the env block of ~/.claude/settings.json so it applies to every session:

{
  "env": {
    "CLAUDE_CODE_STOP_HOOK_BLOCK_CAP": "20"
  }
}
  • The default is 8.
  • A higher number gives a deliberate long loop more rounds.
  • 0 turns the cap off. Only do that when the hook has its own exit condition, because nothing else will stop the loop.

04Write the hook so it never needs the cap

Every Stop hook receives stop_hook_active in its JSON input. It is true when Claude is already continuing because of a stop hook. Anthropic's advice is to check it, or read the transcript, so you never block on a condition that will not resolve.

#!/bin/bash
# ~/.claude/hooks/tests-must-pass.sh
input=$(cat)
if [ "$(echo "$input" | jq -r '.stop_hook_active')" = "true" ]; then
  exit 0   # already pushed Claude once; let it stop
fi
if ! npm test --silent >/dev/null 2>&1; then
  echo '{"decision": "block", "reason": "Tests are failing. Run npm test and fix them before finishing."}'
fi

This version blocks once and then lets Claude stop, so the cap never comes into play. If you want several rounds, keep your own counter in a file next to the hook and give up after a number you choose.

Make the reason actionable, too. "Tests fail in auth.spec.ts, run npm test" works; "not done" just makes Claude try to stop again.

05Stop hooks and long unattended runs

Blocking Stop hooks are popular for leaving Claude on a long task: the hook keeps it going until the tests pass. The cap means such a run can still end early, so you want to know when it does. A notification on Stop tells you the moment the turn really ends, whether the hook allowed it or the cap did. Claude Code Notifier is one way to get that on your phone: an independent tool (not made by Anthropic) with a free command line tool, ccn, for Mac, Windows and Linux, and apps for iPhone and Android. It installs its own hooks next to yours and does not block stops. See The Claude Code Stop hook for the full hook reference.

06FAQ

What is CLAUDE_CODE_STOP_HOOK_BLOCK_CAP?

An environment variable that sets how many consecutive times stop hooks may keep a Claude Code turn going. The default is 8, and 0 turns the cap off.

Why does Claude Code say a hook blocked the turn from ending?

Your Stop hook returned a block decision several times in a row without Claude doing new work in between, so Claude Code ended the turn to stop a possible endless loop.

How do I stop my Stop hook looping forever?

Check stop_hook_active in the hook's input and allow the stop when it is true, or keep a counter and give up after a fixed number of rounds.

Does the cap apply when Claude is using tools?

The count resets whenever Claude calls a tool, so a hook that blocks while Claude is actively fixing things is not cut off after eight rounds of real work.

Claude Code Notifier Get a push on your phone when Claude Code finishes or needs you, then approve, deny or answer from there. The ccn command line tool is free on Mac, Windows and Linux.
Download for iOS Download for Android Install ccn

Use OpenAI's Codex CLI? Notifier for Codex does the same for Codex.

Use Antigravity? Try Antigravity Notifier

Related guides

  • The Claude Code Stop hook: run something when Claude finishesHow Claude Code's Stop hook works, what input it gets, how to run a command when Claude finishes, and how to make Claude keep going safely.
  • Claude Code hooks explained: every event and what it is forWhat Claude Code hooks are, where they go in settings.json, how matchers, input and exit codes work, and what each hook event is for.
  • Leave Claude Code running and walk away: a workflowA practical routine for long Claude Code tasks: keep the computer awake, cut needless prompts, get pinged on your phone and reply from there.
  • How to get a notification when Claude Code finishesUse a Stop hook for "finished" and a Notification hook for "needs input". Copy-paste setups for Mac, Windows and Linux, plus phone alerts.
claude-code-notifier

Claude Code Notifier is an independent third-party application. It is not affiliated with, endorsed by, or sponsored by Anthropic, PBC. "Claude" and "Claude Code" are trademarks of Anthropic, PBC.

apps iOS App Android App ccn for macOS, Windows & Linux All guides Use Codex? Try Notifier for Codex Use Antigravity? Try Antigravity Notifier
legal Privacy Policy Terms of Service Other languages © 2026 touchtap. All rights reserved. TouchTap Ltd is registered in England and Wales, company number 13942589.