claude-code - 💡(How to fix) Fix Background agent UI Stop button is a no-op for stuck agents — process keeps consuming tokens

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…

Clicking the Stop button on a running background agent (Agent tool invoked with run_in_background: true) does not terminate the agent. The agent process continues running indefinitely — token counter keeps climbing, tool calls keep firing — until the entire Claude Code session is restarted.

Root Cause

Clicking the Stop button on a running background agent (Agent tool invoked with run_in_background: true) does not terminate the agent. The agent process continues running indefinitely — token counter keeps climbing, tool calls keep firing — until the entire Claude Code session is restarted.

Fix Action

Fix / Workaround

Tried as workaround

Code Example

No task found with ID: af81da7e7c2c1d33e
RAW_BUFFERClick to expand / collapse

Summary

Clicking the Stop button on a running background agent (Agent tool invoked with run_in_background: true) does not terminate the agent. The agent process continues running indefinitely — token counter keeps climbing, tool calls keep firing — until the entire Claude Code session is restarted.

Repro

  1. Spawn a background agent via the Agent tool with run_in_background: true.
  2. Agent gets stuck mid-execution (e.g. waiting on a network call, an infinite-loop merge resolution attempt, or a slow process).
  3. Click the Stop button in the agent panel of the Claude Code UI.
  4. Observe that the agent's wall-clock counter keeps incrementing.
  5. Observe that the token / tool-use counters keep climbing.
  6. The agent does NOT exit until the entire Claude Code session is restarted.

Evidence from a recent session

Two examples encountered:

  • Agent A: 134 minutes wall-clock, 191.5k tokens, 105 tool uses before the next session restart finally killed it. Stop button clicked multiple times — no effect.
  • Agent B: ~120 minutes wall-clock, 279k tokens, 153 tool uses, 0 commits produced. Stop button no-op.

Tried as workaround

The model attempted to call the TaskStop tool with the agent ID returned by the original Agent invocation (e.g. af81da7e7c2c1d33e). TaskStop returned:

No task found with ID: af81da7e7c2c1d33e

This suggests the UI Stop button and the TaskStop tool may use different ID namespaces — the IDs returned by Agent to the model do not match what TaskStop expects, and the UI's Stop button does not signal the underlying process either.

Expected

Clicking Stop sends SIGTERM (or equivalent OS-level signal) to the agent process. Agent terminates within a few seconds. Any uncommitted work in its isolated worktree remains for inspection; agent is removed from the running-agents panel.

Actual

Stop button has no visible effect. Process keeps consuming tokens and tool calls until session restart. No way to selectively kill one stuck agent — only nuclear option is restarting the whole Claude Code session, which kills ALL running agents (including healthy ones).

Impact

  • Token waste — stuck agents can consume tens of thousands of tokens spinning on the same operation
  • Cannot recover from a stuck agent without losing all parallel agents
  • Defeats the purpose of having a Stop button as a UX affordance

Frequency

Encountered 4 separate times across multi-day work sessions using background agents heavily (typically 5-6 concurrent agents per batch). Reproducible on Windows host.

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