[BUG] # Bug Report: Claude Code Subagent Memory Leak

Resolved 💬 3 comments Opened Feb 5, 2026 by stormgraser-ux Closed Feb 8, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Summary

Claude Code's Task tool spawns subagent processes that are not properly cleaned up after completion. These orphaned processes accumulate over time, each consuming ~400MB of RAM, eventually causing severe performance degradation.

Environment

  • Claude Code version: Latest (as of Feb 4, 2026)
  • OS: Windows 11 + WSL2 (Ubuntu 24.04)
  • Node.js: v22.x (WSL)

Symptoms

  • Claude Code becomes progressively sluggish over time
  • Response times increase dramatically
  • Eventually becomes nearly unresponsive
  • WSL memory usage grows continuously

Root Cause Identified

Subagent processes spawned by the Task tool persist after completing their work. They appear as processes with --resume <session-id> flags that never terminate.

Evidence

After just 17 minutes of normal Claude Code usage, ps aux revealed:

PID   %MEM  RSS       Command
1776  2.3   485MB     claude --resume 050ce2f4-... --disallowedTools ...
2328  1.9   401MB     claude --resume 050ce2f4-... --disallowedTools ...
2895  1.9   397MB     claude --resume 050ce2f4-... --disallowedTools ...
3557  1.9   398MB     claude --resume 050ce2f4-... --disallowedTools ...
4012  1.9   397MB     claude --resume 050ce2f4-... --disallowedTools ...
5236  1.9   404MB     claude --resume 050ce2f4-... --disallowedTools ...
6308  1.9   397MB     claude --resume 050ce2f4-... --disallowedTools ...
7023  2.1   433MB     claude --resume 050ce2f4-... --disallowedTools ...
8001  2.0   415MB     claude --resume 050ce2f4-... --disallowedTools ...
8401  1.9   398MB     claude --resume 050ce2f4-... --disallowedTools ...
11770 1.9   402MB     claude --resume 050ce2f4-... --disallowedTools ...

11 orphaned subagent processes consuming approximately 4.4GB of RAM - all trying to resume the same session ID repeatedly.

Impact

  • Memory: ~400MB leaked per subagent spawn
  • Accumulation: Processes never terminate, memory grows unbounded
  • Timeline: System became unusable after ~1-2 hours of active use
  • Workaround required: Manual process killing with pkill -f "claude.*--resume"

What Should Happen?

Expected Behavior

Subagent processes should terminate after:

  • Completing their assigned task
  • Returning results to the parent process
  • The parent session ending

Actual Behavior

Subagent processes persist indefinitely, all attempting to --resume the same session ID, consuming ~400MB each.

Workaround

We created local tooling to mitigate:

  • kill-orphan-agents - manual cleanup script
  • subagent-watchdog --daemon - auto-kills when >5 orphans accumulate
  • Added cleanup trap to launcher scripts

Error Messages/Logs

Steps to Reproduce

Steps to Reproduce

  1. Start Claude Code in a project
  2. Use it normally (the Task tool / subagent spawning appears to trigger this)
  3. Monitor processes: watch -n 10 'pgrep -c -f "claude.*--resume"'
  4. Observe count growing over time without corresponding cleanup

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.31 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

Additional Context

  • Interesting observation: OpenAI's Codex CLI running in the same WSL environment remained responsive while Claude Code was unresponsive. Codex uses a single-process architecture without subagent spawning, which is why it survived the memory pressure that Claude Code created for itself.
  • The subagents all have --disallowedTools flags, suggesting they're restricted task agents spawned by the Task tool for "fresh eyes" or exploration tasks.

Suggested Fix

Implement proper lifecycle management for subagent processes:

  1. Parent should track spawned subagent PIDs
  2. Terminate subagents when they complete or timeout
  3. Cleanup on parent session exit
  4. Consider a max concurrent subagent limit

---

Report prepared Feb 4, 2026
Happy to provide additional logs, process dumps, or diagnostics if helpful.

View original on GitHub ↗

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