[DOCS] Stop hook docs omit consecutive block cap and override env var

Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened May 16, 2026 · closed Jun 4, 2026

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/hooks

Section/Topic

Stop hook input and decision control, plus the stop-hook troubleshooting guidance

Current Documentation

The docs currently say:

In addition to the common input fields, Stop hooks receive stop_hook_active and last_assistant_message. The stop_hook_active field is true when Claude Code is already continuing as a result of a stop hook. Check this value or process the transcript to prevent Claude Code from running indefinitely.

And the troubleshooting guide says:

Claude keeps working in an infinite loop instead of stopping. Your Stop hook script needs to check whether it already triggered a continuation. Parse the stop_hook_active field from the JSON input and exit early if it's true:

What's Wrong or Missing?

Changelog v2.1.143 introduced a built-in safeguard for repeatedly blocked stop hooks, but the hooks documentation does not describe that behavior.

A. The built-in cap is not documented

The current hooks docs explain how to avoid indefinite looping by checking stop_hook_active, but they do not say that Claude Code now ends the turn with a warning after 8 consecutive stop-hook blocks instead of continuing forever.

B. The override is not documented

The release entry names CLAUDE_CODE_STOP_HOOK_BLOCK_CAP as the override for that threshold, but the environment variable reference does not document this variable.

C. User-visible behavior is missing

The docs do not tell users what happens when the cap is reached, so someone debugging a repeatedly blocking Stop hook has no documentation explaining why the turn stopped with a warning.

Suggested Improvement

Add a short note to the Stop / SubagentStop documentation explaining the built-in circuit breaker, for example:

Claude Code limits repeated Stop-hook continuations. After 8 consecutive blocks, the turn ends with a warning instead of continuing indefinitely. To change that threshold, set CLAUDE_CODE_STOP_HOOK_BLOCK_CAP.

Also update the troubleshooting section in https://code.claude.com/docs/en/hooks-guide so the "Stop hook runs forever" section mentions that newer versions end the turn after the consecutive-block cap is reached, and add CLAUDE_CODE_STOP_HOOK_BLOCK_CAP to https://code.claude.com/docs/en/env-vars.

Impact

Medium - Makes feature difficult to understand

Additional Context

Affected Pages:

| Page | Line(s) | Context |
|------|---------|---------|
| https://code.claude.com/docs/en/hooks | 1894-1915 | Stop hook input and decision control mention preventing indefinite looping but not the built-in consecutive-block cap |
| https://code.claude.com/docs/en/hooks-guide | 913-926 | Troubleshooting still frames this as an infinite-loop problem with only the stop_hook_active workaround |
| https://code.claude.com/docs/en/env-vars | 180-251 | Environment variable reference does not list CLAUDE_CODE_STOP_HOOK_BLOCK_CAP |

Total scope: 3 pages affected

Source: Changelog v2.1.143

Exact changelog entry: "Fixed stop hooks that block repeatedly looping forever - the turn now ends with a warning after 8 consecutive blocks (override via CLAUDE_CODE_STOP_HOOK_BLOCK_CAP)"

View original on GitHub ↗

3 Comments

ianymu · 4 months ago

+1 — ran into the 8-block cap last week while testing a Stop hook that gates session-end on verification (.claude/state/stop-verify.log must contain a VERIFIED entry from the last 5 min, otherwise exit 2). When the model loops trying to log-then-stop-then-log, the cap kicks in and the user just sees the turn end silently.

Two concrete docs requests from the user side:

  1. Surface the cap warning text in the docs verbatim, so people searching for it can find the connection. Right now if you search for the warning message you get nothing in the official docs.
  2. Document the JSON contract for "block but don't count toward cap" (if it exists) — e.g. for diagnostic Stop hooks that report but don't actually want to consume cap slots, it would help to know whether decision: "approve" + stderr message is the right shape.

For anyone hitting this in the wild before docs land: I open-sourced the Stop hook pattern I'm using at https://github.com/ianymu/claude-verify-before-stop (pure bash, MIT) — the relevant bit is using exit 2 for the block + checking stop_hook_active to avoid stacking blocks. The cap behavior caught me by surprise too; would love this documented.

coygeek · 4 months ago

Issue #59583 Verification

Title: [DOCS] Stop hook docs omit consecutive block cap and override env var
Issue Date: 2026-05-16
Verification Date: 2026-06-04
Status: RESOLVED

---

Issue Summary

This issue reports that the Stop hook documentation did not explain the built-in cap that ends a turn after repeated Stop-hook blocks, did not document the CLAUDE_CODE_STOP_HOOK_BLOCK_CAP override, and did not describe the warning users see when that cap is reached.

---

Verification Results

Claim 1: The main hooks page does not document the built-in Stop-hook block cap

Status: RESOLVED

At https://code.claude.com/docs/en/hooks, line 2053 now states: The stop_hook_active field is true when Claude Code is already continuing as a result of a stop hook. Check this value or process the transcript to avoid blocking on a condition that will never resolve. Claude Code overrides the hook and ends the turn after 8 consecutive blocks.

Verdict: The main hooks page now documents the built-in circuit breaker and its default threshold of 8 consecutive blocks.

---

Claim 2: The documentation does not describe the user-visible warning behavior when the cap is reached

Status: RESOLVED

At https://code.claude.com/docs/en/hooks-guide, lines 918-920, the troubleshooting guide now says: Claude keeps working instead of stopping, then ends the turn with a warning that the Stop hook blocked too many consecutive times. It then states: Claude Code overrides a Stop hook after it blocks 8 times in a row without progress. At line 931, the same section adds: If your hook legitimately needs more than eight iterations to converge, raise the cap with CLAUDE_CODE_STOP_HOOK_BLOCK_CAP.

Verdict: The troubleshooting guide now documents both the warning users see and the capped Stop-hook behavior.

---

Claim 3: The environment variable reference does not document CLAUDE_CODE_STOP_HOOK_BLOCK_CAP

Status: RESOLVED

At https://code.claude.com/docs/en/env-vars, line 246, the environment variable table now includes: CLAUDE_CODE_STOP_HOOK_BLOCK_CAP | Maximum number of consecutive times a Stop or SubagentStop hook may block the turn from ending before Claude Code overrides it and ends the turn anyway (default: 8). Set to 0 to disable the cap.

Verdict: The override variable is now documented with its purpose, default behavior, and disable option.

---

Current State

| Claim | Status |
|-------|--------|
| Main hooks page omits the built-in Stop-hook block cap | RESOLVED |
| User-visible warning behavior is missing from the docs | RESOLVED |
| Environment variable reference omits CLAUDE_CODE_STOP_HOOK_BLOCK_CAP | RESOLVED |

---

Suggested Fix

N/A - issue has been resolved.

---

References

  • URL: https://code.claude.com/docs/en/hooks-guide
  • Lines 916-931: The troubleshooting section explains that the turn ends with a warning after repeated Stop-hook blocks and points users to CLAUDE_CODE_STOP_HOOK_BLOCK_CAP.
  • URL: https://code.claude.com/docs/en/changelog
  • Lines 427-427: The changelog entry for v2.1.143 matches the now-documented behavior: the turn now ends with a warning after 8 consecutive blocks (override via CLAUDE_CODE_STOP_HOOK_BLOCK_CAP).

---

Conclusion & Recommendation

Primary Concern: The docs previously failed to explain the Stop-hook consecutive-block cap, the warning shown when that cap is hit, and the override environment variable.

Resolution Status: RESOLVED

Recommendation: CLOSE

The current hooks, troubleshooting, and environment variable pages now document the cap, the warning behavior, and the override variable. The issue's reported documentation gaps are no longer present.

github-actions[bot] · 2 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.