Orphaned subagent process leaks memory when parent terminal session terminated

Resolved 💬 14 comments Opened Jan 23, 2026 by madshn Closed May 28, 2026

Description

When a parent Claude Code terminal session is terminated (e.g., VS Code integrated terminal closed/killed), subagents spawned via the Task tool are not properly cleaned up. The orphaned subagent process accumulates massive memory (30GB in this case) and must be manually killed.

Steps to Reproduce

  1. Run Claude Code in VS Code integrated terminal
  2. Spawn a subagent using the Task tool (in this case, n8n-workflow subagent to monitor an ongoing execution)
  3. Parent session freezes or becomes unresponsive
  4. Terminate the VS Code terminal
  5. Subagent process is orphaned (reparented to launchd/PID 1 on macOS)

Observed Behavior

  • Subagent process continues running detached
  • Process accumulates ~30GB memory in WebKit Malloc (mostly swapped to disk)
  • Process state shows as uninterruptible wait (U)
  • Regular kill doesn't work; requires kill -9
  • Briefly becomes zombie before cleanup

Memory Profile (from vmmap -summary)

Physical footprint:         30.8G
Physical footprint (peak):  30.8G

WebKit Malloc               37.0G virtual   708.9M resident   29.8G swapped

Expected Behavior

  • Subagent processes should be terminated when parent session exits
  • If orphaned, processes should not leak memory indefinitely
  • Graceful signal handling (SIGTERM should work)

Environment

  • Claude Code version: 2.1.17
  • Platform: macOS 26.2 (Darwin 25.2.0, ARM64)
  • Terminal: VS Code integrated terminal
  • Subagent type: n8n-workflow

Additional Context

Process details before kill:

PID    PPID  RSS       VSZ        COMMAND
73002  1     479984    538806112  claude

Parent PID 1 (launchd) confirms orphaned state.

View original on GitHub ↗

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