Subagent (Task tool) processes leak - not cleaned up after completion

Resolved 💬 3 comments Opened Feb 10, 2026 by igorgesso Closed Feb 13, 2026

Description

Subagent processes spawned via the Task tool remain alive as sleeping (Sl state) Node.js processes indefinitely after completing their work. They are never cleaned up, accumulating across sessions.

Impact

Each orphan process holds an inotify file descriptor. On Linux systems with default fs.inotify.max_user_instances=128, this quickly exhausts the limit, causing:

  • Rails/Node/any app using inotify to crash with Errno::EMFILE: Too many open files - Failed to initialize inotify
  • System-wide degradation as other applications (VS Code, Cursor, Docker, etc.) also compete for inotify instances

Reproduction

  1. Use Claude Code with Task tool (subagents) across multiple sessions
  2. After a few sessions with parallel agents, check: ps aux | grep claude | wc -l
  3. Observe dozens of sleeping claude processes from days ago

Evidence

On a system after ~3 days of normal Claude Code usage:

  • 76 claude processes running (most in Sl sleeping state)
  • 37 processes from 3 days prior still alive
  • 135 inotify instances consumed out of 128 limit (already over)
  • After manually killing orphans: dropped to 12 processes and 87 inotify instances
# Example: processes from Feb 6 still alive on Feb 9
751626 Sl   Fri Feb  6 12:52:44 2026 claude
751637 Sl   Fri Feb  6 12:52:44 2026 claude
754287 Sl   Fri Feb  6 12:55:20 2026 claude
...37 more from same day...

Expected Behavior

Subagent processes should be terminated when they complete their task and return results to the parent session.

Workaround

Manually kill orphan processes:

# Kill sleeping claude processes not attached to a terminal
ps -eo pid,stat,comm | grep 'claude' | grep 'Sl ' | awk '{print $1}' | xargs kill

Environment

  • Claude Code CLI (installed via npm)
  • Linux (Ubuntu) with kernel 6.14.0
  • Default fs.inotify.max_user_instances=128

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗