/exit warns about running background agents when none are running; agent sidecars never record completion
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
- Start a fresh session in any project.
- Use the
Agenttool once (defaults — foreground,run_in_background: false). Any agent type; any prompt. Wait for the tool result to return in the transcript. - 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.jsonsidecar files present. - 102 matching
agent-*.jsonltranscript files present. - 0 foreground/background distinction on disk — the tool argument
run_in_backgroundis 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)
- Sidecar metadata never records completion.
.meta.jsonis write-once at spawn. Whatever check/exituses to compute the "running" count has no ground truth to consult.
/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.
- 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
.donemarker) when the Agent tool returns its result to the parent. - Have
/exitcheck active process/task handles instead of persisted sidecar files. - Expose a
/agentsor/taskscommand that lists whatever/exitbelieves is running, so users can see and reconcile the discrepancy.
The first two prevent the false positive; the third at least makes it debuggable.
3 Comments
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.jsontotal, 1,881 written in the last 14 days. Zero containstatus,endedAt,exitCode,completed,completedAt,finishedAt,durationMs,resultorstate.Schema across those 1,881:
agentType,description,spawnDepth,toolUseId, plusname,taskKind,teamName,color,planModeRequired,model,permissionModeon named spawns. Two fields are new since filing:parentAgentId(200 files) andspawnMode(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
/exitto capture the warning text itself, so read this as evidence about the mechanism rather than a fresh screenshot of the prompt.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
/exitwarned about background agents that were already done.It was fixed in 2.1.203 (released July 7, 2026): "Fixed
/exitincorrectly 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.jsonfiles — 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
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.