Task tool subagents leave orphaned processes, causing PTY exhaustion

Resolved 💬 4 comments Opened Jan 9, 2026 by hoiung Closed Jan 12, 2026

Description

When using the Task tool to spawn subagents (especially multiple in sequence), the child processes are not properly cleaned up after completion. This leads to PTY (pseudo-terminal) exhaustion and eventually the error:

Error: Could not fork child process: There are no available terminals (-1).

Steps to Reproduce

  1. Use Claude Code with a workflow that spawns multiple Task subagents in sequence
  2. Example: Run 3 Task calls with different models:

``
Task(model=haiku, prompt="...")
Task(model=sonnet, prompt="...")
Task(model=opus, prompt="...")
``

  1. After completion, check running processes:

``
tasklist | grep -iE "node|claude"
``

  1. Observe multiple orphaned node.exe and claude.exe processes accumulating
  2. After several such sequences, the PTY pool is exhausted

Observed Behavior

After running a workflow with 3 sequential Task subagents:

  • 4 claude.exe processes (~4.9 GB total memory)
  • 20+ node.exe processes

These processes persist after the subagents complete their work and return results.

Expected Behavior

Child processes spawned by the Task tool should be cleaned up after the subagent completes and returns its result.

Environment

  • OS: Windows 11
  • Claude Code version: Latest (as of 2026-01-09)
  • Terminal: Windows Terminal / PowerShell

Workaround

Restart Claude Code after workflows that spawn multiple subagents to clear orphaned processes.

Impact

  • Memory accumulation from orphaned processes
  • Eventually blocks all Task tool usage due to PTY exhaustion
  • Requires manual restart to recover

View original on GitHub ↗

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