If you’re running Claude Code daily, you’ve probably noticed your session start costs creeping up while your process list looks like a zombie apocalypse. Developer dimitreee did exactly that, discovering that fresh sessions were burning through roughly 55k tokens before he even typed a command. The culprit wasn’t his prompts, but the silent accumulation of plugin descriptions, MCP tool schemas, and forgotten configurations loaded at startup. To combat the digital detritus, he built Agent GC, an open-source tool designed to measure context bloat and sweep away orphaned processes without nuking your actual work.
The Hidden Cost of Agent Bloat
The problem is twofold: expensive context and leaked resources. The 55k token figure represents the median startup cost across seven days of interactive sessions, driven by everything from duplicate plugins to MCP servers that never successfully connected. On the infrastructure side, the situation is worse. When an agent exits, its stdio MCP servers often get re-parented to launchd or init instead of dying, leading to massive process leaks. One report cited 96 orphaned processes lingering after a single day of work. Agent GC tackles this by measuring the exact token cost of each source—plugin, skill, or MCP server—and offering reversible switches to disable them, rather than making destructive decisions automatically.
Borrowing Logic from Runtime Garbage Collection
For the leftover files and processes, Agent GC adopts the structure of tracing garbage collectors found in runtimes like the JVM or Go. It defines 'roots' as running processes and config references, treating temp dirs, transcripts, and worktrees as 'heap objects.' The core logic lives in a single 'mark' function that determines if an object is dead. A critical safety feature is the 'agent epoch' rule: if any running agent started before an object went quiet, that object is kept alive. This prevents the tool from deleting a temp directory or transcript that a long-running session might still be appending to, even if it hasn’t been touched in days.
Quarantine, Not Delete
Unlike language runtimes where a bad free corrupts memory, a bad free here deletes user work. Agent GC mitigates this risk by using a quarantine system. Files and directories are renamed into a 'graveyard' with a manifest, staying there for a week before final deletion. Orphaned processes aren’t killed immediately; they are paused with SIGSTOP. If you realize you need a process back, you can resume it for an hour. Only after that grace period, and if the process is still stopped and unchanged, does the tool send SIGTERM. This conservative approach ensures that safety trumps efficiency, freeing disk space slightly later but preserving data integrity.
Live Mode and Event-Driven Cleanup
Moving beyond simple cron jobs, Agent GC features a 'live mode' that reacts to agent exits in real time. Using kqueue on macOS and pidfd on Linux, the tool detects when an agent process terminates, waits two seconds for helpers to be re-parented, and then runs a young collection. This suspends orphaned MCP servers seconds after they become useless, rather than waiting for a 15-minute timer. Between events, the daemon sleeps until the next expiration deadline, consuming only about 0% CPU and 25 MB of RAM when idle. It deliberately avoids touching node_modules or build caches, focusing strictly on agent-specific artifacts like worktrees and transcripts.
Key Takeaways
- Startup costs for Claude Code can hit 55k tokens due to unoptimized plugin and MCP configurations.
- Orphaned MCP processes are a common leak, with reports of nearly 100 lingering processes after one day.
- Agent GC uses a 'quarantine' model, renaming files to a graveyard and pausing processes with SIGSTOP before deletion.
- The tool is open-source, written in Rust, and currently supports Claude Code and Codex CLI on macOS and Linux.
The Bottom Line
This is the kind of pragmatic, safety-first tooling the AI agent ecosystem desperately needs. We’re all hoarding digital junk; it’s about time we had a janitor that doesn’t throw out the baby with the bathwater.