[BUG] Task tool subagents spawn duplicate MCP servers and leak ~/.claude/tasks/ directories on Windows

Resolved 💬 9 comments Opened Feb 24, 2026 by min-hinthar Closed Apr 8, 2026

Description

Two problems compound to cause escalating resource leaks on Windows:

  1. MCP server duplication: Each Task tool subagent (claude --resume) spawns its own complete set of MCP servers. With 5 configured MCP servers (Playwright, Context7, Sentry, Supabase, GitHub), a single subagent doubles the node.exe count from ~8 to ~16. Nested subagent chains (common in orchestration workflows) multiply this further.
  1. ~/.claude/tasks/ directory leak: TeamCreate/TaskCreate writes task directories to ~/.claude/tasks/{uuid}/. When the parent session is terminated (Ctrl+C, crash, freeze), TeamDelete never fires. These directories accumulate indefinitely — observed 25 stale directories spanning 3 weeks.

This compounds with the known orphaned subagent issue (#19045, #17391, #20369) but adds Windows-specific details and an additional leak vector (task directories + MCP duplication).

Environment

  • Claude Code version: 2.1.52
  • OS: Windows 11 (MINGW64_NT-10.0-26300, Git Bash via Windows Terminal)
  • MCP servers configured: 5 (Playwright, Context7, Sentry, Supabase, GitHub)
  • Workflow: GSD (get-shit-done-cc) which heavily uses Task tool with agent teams

Steps to Reproduce

MCP duplication

  1. Configure 3+ MCP servers in ~/.claude/settings.json
  2. Start a Claude Code session
  3. Use the Task tool to spawn a subagent
  4. Check processes: wmic process where "name='node.exe'" get ProcessId,CommandLine
  5. Observe: each MCP server now has 2 instances (one per CLI process)

Task directory leak

  1. Start a Claude Code session
  2. Use TeamCreate or TaskCreate (directly or via orchestration skill)
  3. Kill the session (Ctrl+C or close terminal)
  4. Check: ls ~/.claude/tasks/ — UUID directories remain
  5. Repeat over multiple sessions — directories accumulate

Expected Behavior

  1. Subagent processes should share the parent's MCP server connections, OR MCP servers should be cleaned up when the subagent exits
  2. ~/.claude/tasks/{uuid}/ directories should be cleaned up on session end (graceful or crash)

Actual Behavior

MCP duplication evidence

# Two claude-code CLI processes:
claude --dangerously-skip-permissions --resume  (PID 26016, parent)
claude --dangerously-skip-permissions --resume  (PID 23948, subagent)

# Each spawns its own MCP servers — duplicates:
npx @playwright/mcp@latest          (PID 18304 + PID 9052)
npx -y @upstash/context7-mcp        (PID 16120 + PID 20996)
npx -y @sentry/mcp-server@0.29.0    (PID 27804, single)
npx -y @supabase/mcp-server@0.6.3   (PID 8532, single)
npx -y @modelcontextprotocol/server-github@2025.4.8  (PID 1312, single)

# Total: 16 node.exe processes for a single user session

Task directory leak evidence

$ ls ~/.claude/tasks/ | wc -l
25

$ ls -lt ~/.claude/tasks/ | head -5
drwxr-xr-x  Feb 23  b041161e-c93b-457f-8708-3f53b096d54b/
drwxr-xr-x  Feb 23  8047846d-e967-4d78-8b12-65039f549f32/
drwxr-xr-x  Feb 19  99488560-2b54-4b0b-a75b-913908afb5b2/
drwxr-xr-x  Feb 19  efdcff71-b0ba-4edf-b7f4-c78c904fee95/
drwxr-xr-x  Feb 19  a01d3bd8-af5d-41ba-8b41-0f0fb46ffb72/
# ...spanning back to Feb 7

Workaround

# Kill all orphaned node processes (kills current session too)
taskkill //F //IM node.exe

# Clean stale task directories
rm -rf ~/.claude/tasks/*

# Restart
claude

Suggested Fixes

  1. MCP server sharing: Subagents should connect to the parent's MCP servers via IPC rather than spawning their own instances. This would cut per-subagent overhead from ~5 processes to 0.
  1. Session-end cleanup hook: Register a cleanup handler (even for SIGINT/SIGTERM on Windows) that:
  • Terminates all child subagent processes
  • Runs TeamDelete for any active teams
  • Removes ~/.claude/tasks/{uuid}/ directories owned by this session
  1. Task directory TTL: Add a periodic or startup sweep that removes task directories older than N hours (e.g., 24h) with no active team referencing them.
  1. Subagent timeout: The Task tool blocks the parent indefinitely waiting for subagent completion. A configurable timeout (default: 10 minutes?) with graceful termination would prevent infinite hangs.

Related Issues

  • #19045 — Subagent processes not terminated on Linux (same root cause, different OS)
  • #17391 — Orphaned processes cause 34GB+ memory consumption (macOS)
  • #20369 — Orphaned subagent memory leaks on parent termination
  • #25700 — Sessions in invisible wait states with no timeout
  • #15945 — MCP server causes 16+ hour hang, no timeout detection

View original on GitHub ↗

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