CleanupKit
A drop-in library for AI agent frameworks that guarantees subprocess cleanup via traps, so crashed sessions never leave runaway loops behind
AI agent developers using Claude Code, LangChain, or Pydantic AI in production
- Trap-based cleanup that fires on EXIT, INT, and TERM signals
- Reliable $! tracking even when job control is disabled
- Drop-in middleware for popular agent frameworks
- Test harness that proves cleanup fires on simulated interruption
The article documents a concrete bug class any agent developer shipping to production will hit; the fix (trap + $! tracking) is small but easy to get wrong
Niche but real pain point documented (e.g., Claude Code spawns Bun/Node subprocesses for Task/MCP that get reparented to PID 1 on crash), but source article had only 11 reactions and most devs likely patch this ad-hoc.Kill orphaned Claude/Codex subagent processes (tree cleanup fix) ↗5 AI Agent Failures in Production (And How to Fix Them) ↗
No AI-agent-specific cleanup library found; the only direct attempt is a one-off gist for Claude Code, and general-purpose solutions (pyreap, python-orphanage) don't target agent frameworks.Kill orphaned Claude/Codex subagent processes (tree cleanup fix) ↗pyreap: Automatically reap orphaned subprocesses if you die ↗python-orphanage: Let child processes suicide if they orphan ↗
Small process-cleanup utilities are almost universally free/open-source (pyreap, python-orphanage, NathanSkene gist); developers expect OSS for infra plumbing, and there's no clear paid-feature wedge without bolting on observability.pyreap: Automatically reap orphaned subprocesses if you die ↗python-orphanage: Let child processes suicide if they orphan ↗
Problem persists as long as agent frameworks spawn child processes (Task subagents, MCP servers, tool subprocesses), but framework-level fixes (e.g., Claude Code parenting fixes, LangChain lifecycle hooks) could absorb it over time.
Trap-based subprocess cleanup with process groups is a small, well-understood pattern; wrapping it for LangChain/Pydantic AI callbacks and Claude Code subagents is a few-day library build.