/exit warns about running background agents when none are running; agent sidecars never record completion

Status Fixed / completed
Reported on v2.1.200
Maintainer reply ✓ Yes — bcherny
Activity 3 comments · opened Jul 4, 2026 · closed Aug 17, 2026
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Claude Code 2.1.200
  • macOS (Darwin 25.3.0), arm64
  • Install path: ~/.local/bin/claude

---

Summary

After spawning any subagent via the Agent tool during a session, /exit warns that background agents are still running, even when every spawn was foreground (run_in_background: false, the default) and every result has already been returned to the main loop. Users have no way to see, list, or stop the agents the warning is referring to — they are, by every observable signal, already done.

The root appears to be that per-agent metadata written under ~/.claude/projects/<project>/<session>/subagents/agent-*.meta.json is written once at spawn and never updated. There is no status, endedAt, exitCode, completed, or any other terminal-state field, so nothing on disk distinguishes "returned six hours ago" from "still executing."

---

Reproduction

  1. Start a fresh session in any project.
  2. Use the Agent tool once (defaults — foreground, run_in_background: false). Any agent type; any prompt. Wait for the tool result to return in the transcript.
  3. Type /exit.

Expected: clean exit, no warning (nothing is running).
Actual: warning that background agents are still active, with a count.

The count grows with every additional Agent call in the session, regardless of whether any of them were ever backgrounded.

---

Evidence from an affected session

Inspecting ~/.claude/projects/<project>/<session>/subagents/:

  • 102 agent-*.meta.json sidecar files present.
  • 102 matching agent-*.jsonl transcript files present.
  • 0 foreground/background distinction on disk — the tool argument run_in_background is not reflected in the sidecar.
  • 0 files contain any terminal-state field.

Schema across all 102 files:

agentType: 102
description: 102
spawnDepth: 102
toolUseId: 85           # anonymous Agent() spawns
name: 17                # named/addressable spawns
taskKind: 17            # "in_process_teammate"
teamName: 17
color: 17
planModeRequired: 17
model: 17
permissionMode: 17
Terminal-state fields present: False

Representative meta contents (an agent whose result was returned to the main loop hours before /exit):

{
  "agentType": "<some-agent-type>",
  "description": "<one-line task summary>",
  "toolUseId": "toolu_bdrk_...",
  "spawnDepth": 1
}

Same shape for every agent in the directory. Nothing on disk changes when the agent finishes.

---

What appears to be broken (one or more of these)

  1. Sidecar metadata never records completion. .meta.json is write-once at spawn. Whatever check /exit uses to compute the "running" count has no ground truth to consult.
  1. /exit's "is running" filter is wrong. Even if terminal state lives somewhere else (in-memory only, or in the top-level session JSONL), the exit warning is counting sidecar files (or an equivalent addressable-agent set) rather than actual live process/task handles.
  1. User has no surface to inspect or reconcile. There is no visible list of "these agents are believed to be running" and no command to clear the phantom set. The warning cannot be acted on; users are left choosing between ignoring it (and risking real stranded work someday) or force-quitting.

---

Secondary observation — unbounded sidecar growth

Because completion is never recorded and sidecars are never pruned, subagents/ grows without bound across the life of a session. Long-lived sessions accumulate hundreds of transcripts totaling ~100MB+, indistinguishable to any tool from live work. This makes any "running count" that treats these files as authoritative permanently wrong.

---

Suggested direction (non-prescriptive)

Any one of these would resolve the false positive:

  • Update the sidecar (or write a companion .done marker) when the Agent tool returns its result to the parent.
  • Have /exit check active process/task handles instead of persisted sidecar files.
  • Expose a /agents or /tasks command that lists whatever /exit believes is running, so users can see and reconcile the discrepancy.

The first two prevent the false positive; the third at least makes it debuggable.

View original on GitHub ↗

3 Comments

arcavenai · 2 months ago

Retested. Still reproduces at 2.1.219, and the on-disk shape has not moved in the direction this report asked for.

Currently on 2.1.220. Sidecars on this machine: 9,854 agent-*.meta.json total, 1,881 written in the last 14 days. Zero contain status, endedAt, exitCode, completed, completedAt, finishedAt, durationMs, result or state.

Schema across those 1,881: agentType, description, spawnDepth, toolUseId, plus name, taskKind, teamName, color, planModeRequired, model, permissionMode on named spawns. Two fields are new since filing: parentAgentId (200 files) and spawnMode (5 files). Neither records completion.

Narrowed to sessions running 2.1.218 and 2.1.219: 3 sidecars, schema agentType, description, spawnDepth, toolUseId, no terminal-state field. Newest written 2026-07-24T23:09Z.

Scope note so this is not overstated: this confirms the root cause named in the report, write-once sidecars with no completion record, is still present through 2.1.219. I did not drive an interactive /exit to capture the warning text itself, so read this as evidence about the mechanism rather than a fresh screenshot of the prompt.

bcherny collaborator · 1 month ago

Thanks for the detailed report and repro. This was a real bug in 2.1.200: completed agents could still be counted as in-flight, so /exit warned about background agents that were already done.

It was fixed in 2.1.203 (released July 7, 2026): "Fixed /exit incorrectly warning about running background agents after all named agents had completed" — see the changelog.

One note on the diagnosis: the exit check doesn't read the agent-*.meta.json files — those intentionally hold only spawn metadata. Completion is tracked in the session itself, which is where the bug lived.

I attempted a fresh verification on 2.1.233 on Linux; the install succeeded but the test environment couldn't authenticate, so I'm relying on the changelog and the shipped fix. If you still see the warning on 2.1.203 or later, please reply with your version and repro and we'll reopen.

Closing — reply to reopen.

🤖 Generated with Claude Code

github-actions[bot] · 8 days 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.