[Bug] Memory leak in closed session tabs - processes and heap not released

Status Fixed / completed
Reported on v2.0.76
Maintainer reply None cached
Activity 5 comments · opened Jan 6, 2026 · closed Jan 27, 2026

Bug Description

Memory Leak Report: Claude Code VS Code Extension

Date: 2026-01-06
Reporter: magnus
Extension: anthropic.claude-code v2.0.75
VS Code: 1.107.1 (x64)
OS: Linux (32+ GB RAM)

---

Executive Summary

The Claude Code VS Code extension exhibits a critical memory leak where closed session tabs do NOT release their associated processes or memory. This causes linear RAM accumulation (~400 MB per session) that persists until VS Code is restarted.

Impact

  • After 20 sessions: ~8 GB RAM consumed (never released)
  • After 50 sessions: ~20 GB RAM consumed (system becomes unusable)
  • Workaround: Restart VS Code every 15-20 sessions

---

Reproduction Steps

Test Setup

  1. Open VS Code with Claude Code extension installed
  2. Open Developer Tools: Help → Toggle Developer Tools
  3. Navigate to Memory tab, take baseline heap snapshot

Test Procedure

  1. Baseline: 6 Claude sessions open
  • Heap Size: 152,362 kB
  • Processes: ~15 claude processes
  • RAM per process: 392M - 405M
  1. Close 4 sessions (keep 2 active)
  • Wait 30 seconds for garbage collection
  • Take heap snapshot
  1. Open 4 new sessions, then close them
  • Wait 30 seconds
  • Take heap snapshot

Results

| Snapshot | Tabs Open | Tabs Closed | Heap Size (kB) | Delta | Processes | RAM/Process |
|----------|-----------|-------------|----------------|-------|-----------|-------------|
| #0 | 6 | 0 | 152,362 | - | ~15 | 392M-405M |
| #1 | 2 | 4 | 152,469 | +107 | ~15 | 392M-451M |
| #3 | 2 | 8 (total) | 153,376 | +1,014 | ~15+ | 392M-568M |

Key Findings

  1. Memory NOT Released on Tab Close
  • Closing 4 tabs reduced heap by 0 kB (increased by 107 kB!)
  • Process count remained constant (~15 processes)
  • RAM per process did NOT decrease
  1. Linear Memory Growth
  • Opening + closing 4 sessions increased heap by 907 kB
  • Estimated ~227 kB per session never released
  • Process RAM grows from 400M → 568M
  1. Process Lifecycle Bug
  • Each session spawns a claude process
  • Processes do NOT terminate when tabs close
  • Processes accumulate in htop indefinitely

---

Technical Analysis

What Happens When a Tab is Closed

Working:

  • UI element (tab) is removed from DOM
  • User sees tab disappear

NOT Working:

  • Backend claude process continues running
  • Heap memory retained (conversation context, messages, API state)
  • File descriptors remain open
  • API connections to Anthropic server may persist

Memory Leak Math

Per Session Leak:
- Heap: ~227 kB
- Process RAM: ~400 MB

After N Sessions:
- Heap: N * 227 kB
- RAM: N * 400 MB

Examples:
- 20 sessions = 4.5 MB heap + 8 GB RAM
- 50 sessions = 11.4 MB heap + 20 GB RAM  ← System unusable

Root Cause Hypothesis

Based on code behavior and similar issues (#8722, #15210):

  1. Session lifecycle management incomplete
  2. Process cleanup hooks not called on tab close
  3. File watchers (FSWatcher) not properly disposed
  4. Conversation history loaded but never unloaded

Additional Context

Environment Details

  • OS: Linux 6.8.0-90-generic
  • RAM: 32+ GB
  • VS Code: 1.107.1 (994fd12f8d3a5aa16f17d42c041e5809167e845a)
  • Extensions:
  • anthropic.claude-code@2.0.75
  • saoudrizwan.claude-dev@3.46.1

Test Methodology

  • Used Chrome DevTools (built into VS Code)
  • Heap snapshots taken with 30s GC wait time
  • Process monitoring via htop
  • Controlled test: Known number of sessions opened/closed

Confidence Level

HIGH - Reproducible, measurable, consistent results across 3 snapshots.

---

References

---

Environment Info

  • Platform: linux
  • Terminal: vscode
  • Version: 2.0.76
  • Feedback ID:

Errors

[{"error":"AxiosError: Request failed with status code 403\n    at bx (file:///home/linuxbrew/.linuxbrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:56:1137)\n    at Unzip.<anonymous> (file:///home/linuxbrew/.linuxbrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:57:9852)\n    at Unzip.emit (node:events:520:35)\n    at Unzip.emit (node:domain:489:12)\n    at endReadableNT (node:internal/streams/readable:1701:12)\n    at process.processTicksAnd

Note: Error logs were truncated.

View original on GitHub ↗

5 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/15975
  2. https://github.com/anthropics/claude-code/issues/15906
  3. https://github.com/anthropics/claude-code/issues/8722

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

Magke · 7 months ago
Magke · 7 months ago

Resolved in recent versions
I can confirm this issue is now fixed. After updating to the latest version, closed session tabs properly release their processes and memory as expected.
Thanks to the team for addressing this! Closing as resolved.

github-actions[bot] · 6 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.