Skip to content

[BUG] Memory leak in long-running idle Claude Code sessions #18859

Description

@diangao

Preflight Checklist

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

What's Wrong?

Multiple idle Claude Code sessions accumulated ~15GB memory each over an 18-hour period without any user interaction. 4 sessions combined used ~60GB, exceeding my 24GB RAM and triggering macOS jetsam (OOM killer), causing a complete system crash.

Key finding: Debug logs show context size remained constant at 6664 chars throughout the 18 hours, yet each process grew to ~15GB. This suggests the leak is NOT from context accumulation but from something else (V8 heap fragmentation, MCP connections, internal caching, etc.).

From jetsam report:

  • "largestProcess" : "2.1.7" (Claude Code)
  • 4 processes with rpages 950,000-980,000 (~15GB each)
  • Combined CPU time suggests processes were actively doing something despite being idle

What Should Happen?

Idle Claude Code sessions should:

  • Maintain a low memory footprint (<500MB when idle)
  • Release unused memory through garbage collection
  • Not grow unboundedly without active user interaction

Error Messages/Logs

From /Library/Logs/DiagnosticReports/JetsamEvent-2026-01-15-182249.ips:

"largestProcess" : "2.1.7"

Process memory details (name: "2.1.7"):
PID 10652: rpages=977,907 (~15GB), cpuTime=1805.89s
PID 11129: rpages=950,678 (~14.5GB), cpuTime=3364.34s
PID 11605: rpages=981,949 (~15GB), cpuTime=391.86s
PID 75191: rpages=976,069 (~15GB), cpuTime=1604.92s

(macOS page size = 16KB, so 977,907 pages × 16KB ≈ 15GB)

From ~/.claude/debug/ logs - context stayed constant:
2026-01-15T00:30:45.055Z [DEBUG] Auto tool search disabled: 6664 chars
...
2026-01-16T02:14:31.824Z [DEBUG] Auto tool search disabled: 6664 chars

Steps to Reproduce

  1. Run claude in terminal
  2. Use the session normally (file reads, bash commands, etc.)
  3. Stop interacting but keep the session open (don't /exit)
  4. Monitor memory usage in Activity Monitor over time
  5. Memory grows continuously even when idle

My specific case:

  • 4 sessions open for ~18 hours
  • Each grew to ~15GB despite being idle
  • Context size stayed constant at 6664 chars (verified in debug logs)

The core issue: idle sessions accumulate memory without releasing it, regardless of context size.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.7 (at time of crash), now on 2.1.12

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

Environment:

  • macOS 15.7 (24G207)
  • Apple M2, 24GB RAM
  • iTerm2 with zsh

Session timeline:

  • Sessions started: 2026-01-15T00:01 UTC
  • Crash time: 2026-01-15T18:22 PST
  • Total runtime: ~18 hours
  • User idle time before crash: ~2 hours

MCP configuration:

  • claude-in-chrome MCP server was connected to some sessions

Available for debugging:

  • Full jetsam report at /Library/Logs/DiagnosticReports/JetsamEvent-2026-01-15-182249.ips
  • Debug logs in ~/.claude/debug/ from affected sessions
  • Willing to provide additional logs or test fixes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions