Background agent UI Stop button is a no-op for stuck agents — process keeps consuming tokens

Resolved 💬 2 comments Opened May 28, 2026 by Dalailalama Closed Jun 29, 2026

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.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗