claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Claude Code Memory Leak - Process Grows to 120+ GB RAM and Gets OOM Killed

Open chatgpt-copypasta opened this issue 1 year ago • 97 comments

Claude Code Memory Leak - Process Grows to 120+ GB RAM and Gets OOM Killed

Description

Claude Code has a severe memory leak that causes the process to grow to over 120GB of RAM before being killed by the Linux OOM killer. This happens consistently during extended coding sessions, approximately every 30-60 minutes of active use.

Environment

  • Claude Code Version: 1.0.53
  • OS: Ubuntu 24.04
  • Kernel: Linux 6.14.11
  • Total System RAM: 128GB
  • Installation Method: Direct installation in home directory

Steps to Reproduce

  1. Start Claude Code in interactive mode
  2. Use it for an extended coding session (30-60 minutes)
  3. Perform typical operations: file reading, editing, searching, running bash commands
  4. Monitor memory usage with ps aux | grep claude
  5. Process will gradually consume all available RAM until OOM killed

Expected Behavior

Claude Code should maintain stable memory usage throughout the session, not exceeding a reasonable amount (e.g., 1-2GB for typical usage).

Actual Behavior

The claude process memory usage grows unbounded until it consumes all available system RAM (120+ GB) and triggers the OOM killer.

Evidence

OOM Kill Log Entries (from dmesg):

Killed process 1983785 (claude) total-vm:234427056kB, anon-rss:124857720kB, file-rss:0kB, shmem-rss:0kB, UID:XXXX pgtables:267248kB oom_score_adj:0
Killed process 1991601 (claude) total-vm:234453364kB, anon-rss:125118596kB, file-rss:596kB, shmem-rss:0kB, UID:XXXX pgtables:267880kB oom_score_adj:0
Killed process 1997049 (claude) total-vm:234463420kB, anon-rss:125275392kB, file-rss:5856kB, shmem-rss:0kB, UID:XXXX pgtables:269168kB oom_score_adj:0
Killed process 2001723 (claude) total-vm:234420884kB, anon-rss:119597028kB, file-rss:3748kB, shmem-rss:0kB, UID:XXXX pgtables:257104kB oom_score_adj:0
Killed process 2009167 (claude) total-vm:234464008kB, anon-rss:120216960kB, file-rss:372kB, shmem-rss:0kB, UID:XXXX pgtables:252260kB oom_score_adj:0

Key observations:

  • total-vm consistently around 234GB (virtual memory)
  • anon-rss (actual RAM used) between 119-125GB
  • Multiple OOM kills in the same session indicate this is a recurring issue
  • Memory consumption appears to be primarily anonymous pages (anon-rss), not file-backed

Impact

This memory leak makes Claude Code unusable for extended coding sessions as it:

  1. Causes system-wide memory exhaustion
  2. Triggers OOM killer which terminates other processes
  3. Loses session context when Claude is killed
  4. Requires frequent restarts, disrupting workflow

Additional Information

  • The memory growth appears gradual over time, not sudden
  • The issue persists across multiple sessions
  • After OOM kill and restart, memory usage starts low (~400MB) and grows again

Potential Debugging Steps

To help diagnose this issue, the following information might be useful:

  1. Memory profiling of the claude process
  2. Heap snapshots at various points during execution
  3. Tracking of any unbounded data structures (conversation history, file caches, etc.)

Workaround

Currently, the only workaround is to periodically restart Claude Code before memory exhaustion occurs, which is highly disruptive to workflow.


Priority: High - This makes the tool unusable for its intended purpose of extended coding assistance

chatgpt-copypasta avatar Aug 01 '25 23:08 chatgpt-copypasta

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/3643
  2. https://github.com/anthropics/claude-code/issues/1009
  3. https://github.com/anthropics/claude-code/issues/2938

If your issue is a duplicate, please close it and 👍 the existing issue instead.

🤖 Generated with Claude Code

github-actions[bot] avatar Aug 01 '25 23:08 github-actions[bot]

does this was fixed? seems to be i had that too once, the IDE showed the notification e.g. out of memory.

fsjn avatar Aug 04 '25 00:08 fsjn

I'm still having this issue regardless of where I run it. It's making CC hard to use, as it crashes machine after a while

0bLoM avatar Aug 11 '25 10:08 0bLoM

I've been having this since I started using subagents (since version ~1.0.70). Can't use more than 2 Claude Code instances because I ONLY have 32 GB of RAM.

almirsarajcic avatar Aug 14 '25 03:08 almirsarajcic

me too..

tg201005 avatar Aug 15 '25 13:08 tg201005

I've solevd this by commiting to memory that CC should terminate any processes it's done using. I have stopped having issues.

0bLoM avatar Aug 15 '25 13:08 0bLoM

I've solevd this by commiting to memory that CC should terminate any processes it's done using. I have stopped having issues.

thanks, bro. Can you explain more? Do you use CC hooks?

tg201005 avatar Aug 16 '25 00:08 tg201005

I am still seeing this on 1.0.98 where I've got 4 processes each taking about 2.5GB RAM

akhilnchauhan avatar Sep 02 '25 20:09 akhilnchauhan

Environment

  • Claude Code Version: 2.0.1 (Claude Code)
  • Claude Model: claude-sonnet-4-5-20250929
  • Platform: Linux 6.14.0-15-generic
  • RAM: 15GB
  • Swap: None

Issue Description

Claude Code process experiencing rapid memory growth leading to OOM kills. Monitoring shows memory jumps from stable baseline to crash threshold within minutes.

Memory Growth Pattern (from monitoring)

2025-10-11 18:46:48 PID:3174091 RSS:204MB VSZ:32120MB ← stable 2025-10-11 18:47:48 PID:3174091 RSS:1554MB VSZ:33467MB ← 7x jump in 60s 2025-10-11 18:48:48 PID:3174091 RSS:3967MB VSZ:35869MB ← nearly doubled 2025-10-11 18:49:48 PID:3174091 RSS:4301MB VSZ:36201MB ← crash threshold [Process killed by OOM]

Historical OOM Kills

10+ kills over 2 days (Oct 3-5):

  • Processes growing from 1.3GB → 4.3GB RSS before kill
  • Virtual memory: 33GB → 37GB range

Sample kern.log Entry

2025-10-05T14:12:52 kernel: Out of memory: Killed process 1418229 (claude) total-vm:36857676kB, anon-rss:4102880kB, file-rss:3048kB, shmem-rss:0kB, UID:1001 pgtables:119712kB oom_score_adj:0

Impact

System unusable for extended Claude Code sessions. Process requires restart every 30-60 minutes to prevent OOM.

Monitoring Setup

Created automated monitoring script logging memory every 60s to track growth patterns.

psicilia5179 avatar Oct 12 '25 05:10 psicilia5179

I got a record 34 GB yesterday on my Mac M1 Max 32 GB!

clemlesne avatar Oct 21 '25 08:10 clemlesne

Image

97gb here :)

leidig54 avatar Oct 23 '25 16:10 leidig54

Image

on v2.0.27

marccardinal avatar Oct 25 '25 00:10 marccardinal

Yesterday my claude instance got up to 107GB after a few hours of very intensive work and took down my whole machine.

edfactor avatar Nov 01 '25 12:11 edfactor

Consistently getting 130GB+

and sometimes VS Code just crashes UI

Image

Only 2 VS Code windows are running simultaneously...

UPD. I think it was audio and ntfy hooks (asked CC to optimize them and remove ntfy)

bogomazov avatar Nov 03 '25 10:11 bogomazov

Image Related?

lanmower avatar Nov 03 '25 17:11 lanmower

My CC shows that on every startup right away

lanmower avatar Nov 03 '25 21:11 lanmower

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 09 '25 10:12 github-actions[bot]

up

senkenn avatar Dec 09 '25 10:12 senkenn

Here because i've seen it 128GB RAM and recently started getting "Your system has run out of application memory" -- it's claude code. 120GB+ !!

rolanday avatar Dec 16 '25 03:12 rolanday

On Mac it spins up dozens and dozens of claude instances each with ~250mb memory usage. I'm using the VS Code extension, and it seems to partially help to close tabs and re-open them, but only partially. It's really really annoying and leads to the system eventually filling swap to the point it's unusable and I have to reboot.

josefguenther avatar Dec 28 '25 20:12 josefguenther