[BUG] Memory leak during API response streaming - 1GB/second growth rate causes 20GB+ allocation
Resolved 💬 7 comments Opened Jan 20, 2026 by haydenzone Closed Feb 28, 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?
Memory growth captured every 3 seconds via monitoring script:
16:17:12 - 604MB RSS (stable for 60+ seconds prior)
16:17:27 - 604MB RSS (stream processing begins)
16:17:30 - 1,689MB RSS (+1,085MB in 3s)
16:17:33 - 4,410MB RSS (+2,721MB in 3s)
16:17:36 - 7,267MB RSS (+2,857MB in 3s)
16:17:39 - 9,742MB RSS (+2,475MB in 3s)
Physical footprint reached 20.8GB before manual termination. Process remained in running state (R+), not crashed - memory just kept growing.
What Should Happen?
Memory should remain bounded during API response streaming. Response chunks should be processed and freed incrementally.
Error Messages/Logs
No error messages produced. The process continued running (state R+) while allocating
unbounded memory. Had to be manually killed.
Relevant debug log output before memory explosion:
2026-01-20T00:16:59.421Z [DEBUG] Getting matching hook commands for SubagentStart with query: project-manager
2026-01-20T00:17:12.219Z [DEBUG] [API:request] Creating client
2026-01-20T00:17:12.220Z [DEBUG] [API:auth] OAuth token check complete
2026-01-20T00:17:14.209Z [DEBUG] Stream started - received first chunk
Debug logging stopped after stream started. No errors logged during the memory leak.
Memory monitoring output showing the leak:
16:17:27 - 604MB RSS
16:17:30 - 1,689MB RSS
16:17:33 - 4,410MB RSS
16:17:36 - 7,267MB RSS
16:17:39 - 9,742MB RSS
Physical footprint at termination: 20.8GB
Steps to Reproduce
- Create a custom subagent that uses extended thinking (model: opus)
- Invoke the subagent via Task tool
- Wait for API response stream to begin
- Observe memory growth ~13 seconds after stream starts
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.12
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
Final output of the CLI
⏺ project-manager(Orchestrate todo-cli development)
⎿ Search(pattern: "/Users/haydenwaisanen/dev/todo-cli/**/*")
Found 59 files
tech-lead(Design technical architecture for todo-cli application)
+9 more tool uses (ctrl+o to expand)
ctrl+b to run in background
✻ Skedaddling… (ctrl+c to interrupt · 1m 1s · ↓ 2.6k tokens)
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
? for shortcuts
Aborted()This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗