claude-code - 💡(How to fix) Fix Stop:Callback blocks session exit after foreground Agent completions [2 comments, 3 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#49071Fetched 2026-04-17 08:51:44
View on GitHub
Comments
2
Participants
3
Timeline
8
Reactions
0
Timeline (top)
labeled ×5commented ×2cross-referenced ×1

When foreground agents are spawned via the Agent tool, Claude Code registers an internal Stop:Callback hook to prevent premature session termination. After all foreground agents complete and return results inline, the callback is never deregistered. Every subsequent stop attempt is blocked:

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.

Error Message

Stop:Callback hook blocking error from command: "callback": Background subagents are still running.

Root Cause

When foreground agents are spawned via the Agent tool, Claude Code registers an internal Stop:Callback hook to prevent premature session termination. After all foreground agents complete and return results inline, the callback is never deregistered. Every subsequent stop attempt is blocked:

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.

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

Environment

  • Claude Code CLI via Claude Desktop (Claudian) integration
  • macOS (Apple Silicon)
  • Session type: local-agent (Desktop wrapping CLI via stdio JSON)

Description

When foreground agents are spawned via the Agent tool, Claude Code registers an internal Stop:Callback hook to prevent premature session termination. After all foreground agents complete and return results inline, the callback is never deregistered. Every subsequent stop attempt is blocked:

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.

Repro

  1. Start a Claudian (Claude Desktop) session
  2. Spawn 2+ foreground agents via the Agent tool (not run_in_background)
  3. Wait for all agents to complete and return results inline
  4. Attempt to stop the session

Expected

Session stops normally — foreground agents that returned results should deregister the Stop callback.

Actual

Stop:Callback blocks every stop attempt indefinitely. The message claims "Background subagents are still running" but:

  • All agents were foreground (not run_in_background)
  • All agents completed and returned results
  • TaskOutput for both agent IDs returns "No task found"
  • No agent processes, lock files, or state files exist anywhere
  • Custom Stop hooks (session-capture.py) work correctly and allow after first fire

The only escape is /clear or closing the session window.

Investigation

Checked and ruled out:

  • User Stop hooks in .claude/settings.json — only custom session-capture.py, working correctly
  • ~/.claude/tasks/ — no active tasks
  • /tmp — no agent tracking files
  • Session directory state files — no agent registry
  • GrowthBook feature flags (tengu_lean_sub_pf7q, tengu_sub_nomdrep_q7k, tengu_mcp_subagent_prompt)
  • Cowork plugins — no Stop hooks

The Stop:Callback is internal — type: "callback" vs user hooks' type: "command". Not user-configurable or clearable.

Hypothesis

The runtime registers Stop callbacks when the Agent tool is invoked but only deregisters for background agents (tracked via TaskOutput). Foreground agents complete via inline tool results, bypassing the callback cleanup path. The Claude Desktop wrapper may add a second tracking layer via stdio JSON that doesn't reconcile with CLI state.

extent analysis

TL;DR

The issue can be mitigated by using the TaskOutput command with block=true to wait for foreground agent results before stopping the session.

Guidance

  • Investigate the Agent tool's implementation to understand how it registers and deregisters the Stop:Callback hook for foreground agents.
  • Verify that the TaskOutput command with block=true works as expected for foreground agents, despite the "No task found" error.
  • Consider adding a custom Stop hook to manually deregister the Stop:Callback hook after all foreground agents have completed.
  • Review the Claude Desktop wrapper's stdio JSON handling to ensure it doesn't interfere with the CLI state.

Example

No code snippet is provided as the issue is more related to the internal implementation of the Agent tool and the Claude Desktop wrapper.

Notes

The issue seems to be related to the difference in handling between foreground and background agents. The Stop:Callback hook is not being deregistered for foreground agents, causing the session to block indefinitely. The TaskOutput command with block=true might provide a temporary workaround, but a more permanent fix would require changes to the Agent tool or the Claude Desktop wrapper.

Recommendation

Apply workaround: Use the TaskOutput command with block=true to wait for foreground agent results before stopping the session. This might help mitigate the issue, but a more thorough investigation and fix are needed to resolve the root cause.

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