Skip to content

Orphaned subagent process leaks memory when parent terminal session terminated #20369

@madshn

Description

@madshn

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions