Task tool subagents leave orphaned processes, causing PTY exhaustion
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
- Use Claude Code with a workflow that spawns multiple Task subagents in sequence
- Example: Run 3 Task calls with different models:
````
Task(model=haiku, prompt="...")
Task(model=sonnet, prompt="...")
Task(model=opus, prompt="...")
- After completion, check running processes:
````
tasklist | grep -iE "node|claude"
- Observe multiple orphaned
node.exeandclaude.exeprocesses accumulating - After several such sequences, the PTY pool is exhausted
Observed Behavior
After running a workflow with 3 sequential Task subagents:
- 4
claude.exeprocesses (~4.9 GB total memory) - 20+
node.exeprocesses
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
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗