claude-code - 💡(How to fix) Fix Stop hook false-positive: stale subagent IDs block session end [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48470Fetched 2026-04-16 06:59:15
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×5commented ×2

Error Message

Stop:Callback hook blocking error from command: "callback": Background subagents are still running. Use TaskOutput task_id="..." block=true to wait for their results before ending your turn. 6. Actual: The runtime's internal pre-stop check detects stale agent IDs and blocks with the "Background subagents are still running" error. The Stop hook never fires because the runtime blocks first. The user can continue chatting past the error. The session isn't truly stuck — it just can't cleanly stop until the stale IDs are somehow cleared.

Root Cause

  1. Configure a Stop hook that blocks on the first stop attempt (e.g. to prompt for end-of-session questions), then allows on subsequent attempts via a state file gate.
  2. During the session, spawn multiple subagents via the Agent tool. Let them all complete and consume their results.
  3. The Stop hook fires correctly on the first stop attempt — blocks, surfaces the prompt, works as intended.
  4. After addressing the prompt, attempt to stop again.
  5. Expected: The Stop hook allows (state file exists), session ends.
  6. Actual: The runtime's internal pre-stop check detects stale agent IDs and blocks with the "Background subagents are still running" error. The Stop hook never fires because the runtime blocks first.

Fix Action

Workaround

The user can continue chatting past the error. The session isn't truly stuck — it just can't cleanly stop until the stale IDs are somehow cleared.

Code Example

Stop:Callback hook blocking error from command: "callback": Background subagents are still running. Use `TaskOutput task_id="..." block=true` to wait for their results before ending your turn.
RAW_BUFFERClick to expand / collapse

Bug

When a Stop hook is configured and subagents (via the Agent tool) were used during a session, subsequent stop attempts are blocked by an internal runtime check with:

Stop:Callback hook blocking error from command: "callback": Background subagents are still running. Use `TaskOutput task_id="..." block=true` to wait for their results before ending your turn.

However, all subagents have completed and TaskOutput returns "No task found" for every agent ID.

Repro steps

  1. Configure a Stop hook that blocks on the first stop attempt (e.g. to prompt for end-of-session questions), then allows on subsequent attempts via a state file gate.
  2. During the session, spawn multiple subagents via the Agent tool. Let them all complete and consume their results.
  3. The Stop hook fires correctly on the first stop attempt — blocks, surfaces the prompt, works as intended.
  4. After addressing the prompt, attempt to stop again.
  5. Expected: The Stop hook allows (state file exists), session ends.
  6. Actual: The runtime's internal pre-stop check detects stale agent IDs and blocks with the "Background subagents are still running" error. The Stop hook never fires because the runtime blocks first.

Root cause (hypothesis)

Claude Code's task lifecycle tracking retains completed agent/task IDs in an active-task registry. When the Stop hook blocks and forces a new turn, the runtime's pre-turn/pre-stop check sees these stale IDs and assumes tasks are still running. TaskOutput correctly reports "No task found" — the tasks are genuinely done, but the registry wasn't cleaned up.

Environment

  • Claude Code Desktop (Code tab), v1.2581.0+
  • macOS (Apple Silicon)
  • Max plan, Opus 4.6
  • Stop hook: Python script using {"decision": "block", "reason": "..."} protocol
  • 4 subagents spawned via Agent tool (all foreground, all completed)

Workaround

The user can continue chatting past the error. The session isn't truly stuck — it just can't cleanly stop until the stale IDs are somehow cleared.

extent analysis

TL;DR

The most likely fix is to clear the stale agent IDs from the task lifecycle tracking registry to prevent the runtime's internal pre-stop check from blocking the Stop hook.

Guidance

  • Investigate the task lifecycle tracking registry to understand how completed agent/task IDs are retained and how they can be cleaned up.
  • Verify that the TaskOutput command is correctly reporting "No task found" for every agent ID, indicating that the tasks are genuinely completed.
  • Consider implementing a mechanism to automatically clean up completed agent IDs from the registry when the Stop hook blocks and forces a new turn.
  • Review the Stop hook's logic to ensure it is not inadvertently causing the runtime's pre-stop check to detect stale agent IDs.

Example

No code snippet is provided as the issue does not contain sufficient information about the specific code implementation.

Notes

The provided workaround of continuing to chat past the error is not a reliable solution, as it does not address the underlying issue of stale agent IDs. A more robust solution would involve cleaning up the task lifecycle tracking registry.

Recommendation

Apply a workaround to clear the stale agent IDs from the task lifecycle tracking registry, as upgrading to a fixed version is not mentioned in the issue. This is because the issue seems to be related to the specific implementation of the task lifecycle tracking registry and the Stop hook, rather than a version-specific bug.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Stop hook false-positive: stale subagent IDs block session end [2 comments, 2 participants]