Background agent keeps running and billing after its window is closed AND after logout/re-login — invisible from the active session, found only by luck on another device

Status Open
Reported on v2.1.210
Maintainer reply None cached
Activity 3 comments · opened Jul 15, 2026

What happens

A long-running background agent (a remote-connected "Code" session) kept running and consuming usage after I (1) closed its terminal window and (2) logged out and re-authenticated. Neither action stopped it.

After re-authenticating, the still-running agent did not appear in my active session view — from where I was now working, it did not appear to exist at all. It only surfaced because I happened to open the mobile app, where the still-"Connected" agent was listed, while being completely absent from the session view I was actively using on my machine.

Had I not caught it by chance on a different surface, it would have kept billing indefinitely against a session I had been told was terminated, with no way to see it.

Why this is bad

  1. It contradicts documented and instructed behavior. Closing the terminal window is widely described — including by the tool itself, in-session, repeatedly — as the way to end background agents. It does not. The agent keeps running and keeps billing.
  2. Logout neither stops it nor surfaces it. Re-authenticating leaves the prior background agent alive and billing, and gives no warning or reconciliation that a prior-session agent is still consuming usage. This rhymes with #76346 (a usage bucket surviving /logout + /login on the OAuth token) and #67064 / #57285 (logout not actually clearing session state) — but here it is the live, billing agent that persists, not just a token or a counter.
  3. It's invisible from where you are. The still-running agent is not present in the active session list; it showed up only on a separate surface. There is no "these background agents are still running and billing" reconciliation at the one moment it matters — immediately after you log in.
  4. Silent usage drain is the direct consequence. This is the same failure class as #72623 (orphaned background --fork-session worker, silent quota burn) and #64744 (persisted background loop, unbounded token spend) — a background unit you believe is stopped keeps spending, silently.

A second, compounding breakage in the same incident

After this happened, --resume for the main agent stopped working the way it had for months. Instead of resuming the existing session, I was forced to start it fresh in agent mode — the prior session was no longer resumable or visible. This matches #60341 (CLI --resume produces sessions invisible to the sidebar; desktop silently drops sessions on relaunch) and #73526 (Code sessions show "No messages yet", cliSessionId nulled on launch, and sending a new message silently forks a disconnected session).

So the same event that left a ghost agent billing in the background also severed the legitimate resume path for the agent I was actually trying to continue — two independent failures from one action.

What should happen

  • Closing the terminal window (or logging out) should either actually terminate background agents, or clearly tell the user they are still running and will keep billing, with a one-step way to stop them.
  • Immediately after login, surface any background agents still running or billing on this machine (including any left over from before a logout / re-login) — a reconciliation prompt, not something the user has to discover on another device by luck.
  • --resume should not silently break after a re-auth or relaunch; the prior session should remain resumable, or the tool should say why it isn't.

Usage

This one is not academic. I lost a meaningful amount of usage to an agent I had been explicitly and repeatedly told — by the tool itself — was already stopped, and which I could not see from where I was working. Usage consumed by a background process that the product misrepresents as terminated, and hides from the active session, should be credited back. I am asking for that credit directly, and firmly.

To be precise about what this does and does not explain: this is a distinct, additional drain, separate from other usage overhead I have already measured cleanly and can attribute directly to specific actions. I am not folding those into this — they stand on their own. What this bug explains is the usage I have watched draw down in other places that I otherwise could not account for: an invisible agent billing against a session I had been told was dead. I reported background agents continuing to consume usage after their window was closed previously — it is still not fixed, and this is that same failure, still live, now shown to also survive a full logout and re-login.

This is part of the same week-long pattern I have been documenting in #76987 — usage spent on the tool's own defects rather than on the work I actually asked for.

Related (same underlying "background / auth state does not match reality" area)

  • #72623 — orphaned background worker, silent quota burn
  • #64744 — persisted background loop, unbounded token spend
  • #70373 — backgrounding a session with in-flight subagents forks / orphans the original
  • #76346 — usage bucket survives /logout + /login
  • #67064 / #57285 — logout does not actually clear session / auth state
  • #60341 / #73526 — --resume / relaunch produces invisible or force-forked sessions
  • #75036 / #56913 — background/delegated work state does not match reality (still open)
  • #76987 — the running usage-impact thread this belongs to

Environment

  • Claude Code 2.1.210, Windows (PowerShell / Windows Terminal)
  • Background agents launched from the CLI, remote-connected and visible in the mobile "Code" sessions view

View original on GitHub ↗

3 Comments

ThatDragonOverThere · 1 month ago

@kcarriedo — flagging you here since you've independently documented this exact coordination / lifecycle / state-machine failure class alongside me on #56913 and #54393, and this is a clean new instance of it.

Same shape you articulated there: a background unit's real state — here, an agent that is running and actively billing — diverges from every surface the user can actually see. Closed the window (which the tool itself tells users ends background agents): still running. Logged out and re-authenticated: still running, still billing, and now completely absent from the active session view. The only place it surfaced was a different device, by luck. The primitives leave lifecycle and reconciliation to userspace — except now there's a direct, unrecoverable usage cost attached, and no reconciliation surface at the one moment it matters (right after login).

For the record: this class keeps getting reported — #72623, #64744, #76346, #75036, #56913 — and remains unfixed. It is not an edge case; it silently drains paid usage against sessions the product actively tells you are dead. Filing it as its own issue (#77876) with the full cluster linked so it doesn't vanish as a comment on one of the neighbors. It needs actual triage and a fix, not another auto-dedupe-and-close.

kcarriedo · 1 month ago

The "invisible session billing after logout" failure mode is genuinely bad, and the "found it by chance on a different device" part is the scariest detail here -- that's not a recoverable pattern for most users.

The root problem seems to be that session lifecycle is tracked per-surface rather than per-account. The session is "alive" at the account layer but the active-session view only reflects what the current surface knows about, so closing a window or re-authenticating doesn't propagate a stop signal to the background agent process.

A few things worth noting for anyone hitting this now:

  • If you can still reach the mobile app (or another surface where the session is visible), closing it from there does seem to stop it. Not a fix, but a recovery path if you catch it in time.
  • The Anthropic usage dashboard at console.anthropic.com should show active token consumption in roughly real time. If you're running long-horizon background agents and want a smoke alarm, checking there after closing a session is worth the habit until this is resolved.
  • For unattended/overnight runs specifically, structuring them with an explicit time budget in the system prompt ("stop and summarize after X hours regardless of task state") gives a backstop against runaway billing -- the agent terminates on its own rather than waiting for an external kill signal that may never arrive.

This deserves a clear fix at the session lifecycle layer: closing the window or session view from any authenticated surface should propagate a stop to the background agent, and the active-sessions list should be account-scoped, not surface-scoped. The current behavior is a billing trap.

ThatDragonOverThere · 1 month ago

Update — the same stuck session has a second, opposite failure mode: it timed out and then sat idle for hours doing nothing

Follow-up on this exact situation, because it turns out a stale-auth background session is unmanaged in both directions.

The original report here was: a background session left running on an authentication I'd already signed out of kept running and billing invisibly. That's one failure mode.

Here's the other one, from the same kind of stuck session, later the same day: it timed out and disconnected itself — and then, instead of erroring, attempting to reconnect, or notifying me in any way, it sat completely idle for the entire afternoon. This was my main workload session. It produced nothing for hours and I only found out by going and checking.

So the two failure modes are mirror images of each other, same root cause:

  • Keeps running and billing forever, invisibly (the original report), or
  • Times out, self-disconnects, and sits idle forever, invisibly (this one).

The common thread is that a background/remote session on stale authentication is decoupled from any lifecycle management at all. Nothing keeps it alive when you want it alive, nothing cleanly stops it when it should stop, and nothing tells you which of those two things is happening. You cannot tell a session that's silently burning usage from one that's silently doing nothing — both look identical from where you're sitting, which is "not in front of that window."

One honest note on evidence: I can confirm the billing half of this eventually stopped, but only because an unrelated full OS crash killed the process outright and nothing respawned it — i.e. the only thing that reliably ended the runaway session was the machine crashing. The idle-timeout half I'm reporting first-hand; a later restart overwrote the session's on-disk timestamps, so I can't pin the exact minute it went idle, only that it did and stayed that way for the afternoon.

And to be precise about the cost, because it's not what you'd assume: the idle period itself burned almost nothing — on the order of 1-2%, and even that I can't cleanly isolate because other sessions were running concurrently. The expensive part had already been spent. This was the same session that cost roughly 40% of a weekly allocation just to resume and hand off (the startup + handoff overhead I measured separately in #76987). So the failure didn't waste usage by idling — it wasted usage by making that ~40% setup pointless. The session was expensively prepared and then, silently, did nothing with it. That's the real cost of this failure mode: not the idle, but the wasted preparation to reach it.

Same area as #75036 and #56913 (background work state not matching reality) and part of the ongoing pattern in #76987.