Your AI coding tool isnt slow Your machine is drowning in zombie processes
The Problem
If you use Claude Code Codex or similar AI coding assistants youve probably noticed your machine getting slower over time RAM usage creeping up Fans spinning Eventually a force restart
Most people blame the AI tool But the real culprit is usually orphaned child processes
Every time you start a Claude Code session it spawns child processes
MCP servers for tool integrations Notion Supabase Playwright etc
Sub agents for parallel task execution
Headless browsers for web browsing and testing
Build tools like esbuild vite webpack in watch mode
When the session ends especially on crash or force quit these children dont always exit They become orphans Still running Still consuming RAM
How Bad Is It
I discovered this the hard way My MacBook Pro 32GB RAM ground to a halt
Load Average 230 normal is 4 8
RAM 31GB used 99MB free
Swap 145GB of disk thrashing
CPU 99 all kernel task trying to manage the memory crisis
When I investigated I found
74 Chrome processes from agent browser that never closed 56 GB
18 orphan node processes from dead Claude sessions 51 GB
7 zombie npm exec processes from TaskMaster AI
Playwright headless shells esbuild watchers MCP servers all orphaned
Thats 22 GB of RAM consumed by processes doing absolutely nothing
Why This Happens
The root cause is simple process lifecycle management is hard
When a Claude Code session exits normally it tries to clean up But
Crash exits dont trigger cleanup hooks
Force quit Cmd Q closing terminal may skip cleanup
Sub agents that spawn their own children create nested orphan trees
MCP servers run as independent processes the parent doesnt always know about them
Headless browsers have their own daemon lifecycle
Each session leaves a few survivors After a week of heavy use you have dozens
The Fix zclean
I built zclean a small CLI that automatically finds and cleans up these orphaned processes
Install one command
npx thestackai zclean init
This sets up two layers of protection
1 SessionEnd hook when Claude Code exits immediately clean that sessions orphans
2 Hourly scheduler catch anything the hook missed crashes Codex orphans etc
The Safety Model
The most important design decision if the parent process is alive dont touch it
zclean only kills processes that are
Orphaned parent process is dead
Match known AI tool patterns MCP servers agent browser etc
Not in a tmux screen session
Not managed by pm2 forever supervisord
Not in a Docker container
Your intentional vite dev server in a terminal tab Untouched Your node apijs in tmux Untouched Only true zombies from dead AI sessions
See It In Action
zclean
Found 8 zombie processes
PID 26413 node 367 MB orphan 18h was claude mcp server
PID 62830 chrome 200 MB orphan 3h was agent browser
PID 26221 npm 142 MB orphan 2d was npm exec task master ai
Total 8 zombies 20 GB reclaimable
zclean yes
Cleaned 8 zombie processes Reclaimed 20 GB
Technical Details
Zero dependencies only Nodejs builtins
Cross platform macOS Linux Windows
Dry run shows what would be cleaned
Verify PID before kill
SIGTERM then 10s to SIGKILL
Check for Zombies
Check Task Manager for node inactive ones are zombies Or run npx thestackai zclean
Links
GitHub whynowlab zclean NPM thestackai zclean
Issues Contributions welcome
Top comments (0)