Orphaned background --fork-session worker runs for hours and is respawned by the cc-daemon after kill (silent quota burn)

Open 💬 1 comment Opened Jun 30, 2026 by dwbimstr

Summary

A backgrounded, forked session (claude.exe --bg-pty-host … --fork-session --resume <transcript>.jsonl --permission-mode bypassPermissions) kept running autonomously for ~16 hours with no foreground/terminal attached, continuously appending to its transcript (grew to ~37 MB) and consuming API quota. Killing the worker process did not stop it: the local claude daemon run (cc-daemon) immediately respawned a new --bg-pty-host that re---resumed the same session within ~18s. Only killing the entire daemon process tree stopped it.

Environment

  • Claude Code: 2.1.197
  • OS: Pop!_OS 22.04 LTS (Linux 6.17.9, x86_64)
  • Install: npm global (@anthropic-ai/claude-code)

What I observed

  • A foreground session (call it A) had earlier spawned background work (background agents / a workflow) via the --fork-session + cc-daemon mechanism.
  • Long after session A moved on, a forked background session (a different session-id, --fork-session --resume <A's-transcript>.jsonl --permission-mode bypassPermissions) was still alive ~16h later, its transcript actively growing in real time, with no UI/terminal attached.
  • kill -9 on the --bg-pty-host + worker PIDs stopped them, but within ~18s claude daemon run (socket under /tmp/cc-daemon-1000/<id>/) respawned a fresh --bg-pty-host that re-resumed the same session and continued writing the transcript.
  • Killing the full daemon tree (claude daemon run + every --bg-pty-host / --bg-spare / worker child) finally stopped it. Nothing restarted the daemon (no systemd unit, no cron — its original launcher had exited and it had reparented to systemd --user), so it stayed down.

Impact

Silent, unbounded API-quota consumption by an orphaned background session with no attached UI, surviving for hours and not stoppable by killing the visible worker (the supervising daemon resurrects it). In our case it burned roughly a week's quota before it was noticed.

Expected

  • A backgrounded/forked session should terminate (or be reapable) when its parent foreground session ends, or have a bounded lifetime / idle timeout.
  • Killing the worker should not be silently undone by the daemon for an orphaned session.
  • A documented, clean command to list and stop runaway background sessions — without having to kill -9 the entire daemon tree (which also disables legitimate background tasks for the still-active session).

Workaround

Identify and kill -9 the entire claude daemon run process tree (daemon + all --bg-pty-host / --bg-spare / worker children), not just the worker. Then verify the session's transcript mtime freezes and that no new --bg-pty-host respawns.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗