Skip to content

[BUG] Memory leak: Claude process consuming 23GB RAM and 143% CPU after 14 hours of runtime #11377

Closed as not planned

Description

@xssdem

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?

After running Claude Code for approximately 14 hours, the process became stuck and consumed excessive system resources, making the entire system unresponsive.

Issue Details:

  • Process stuck in running state with extreme resource consumption
  • Memory usage: ~23GB (virtual memory)
  • CPU usage: 143% sustained
  • Fault counter overflow: 2,147,483,647 (max int32)
  • System experienced severe swap thrashing (337M swap-ins, 361M swap-outs)
  • Process did not terminate automatically
  • Required kill -9 to terminate

System Impact:

  • System became nearly unresponsive
  • Load average spiked to 5.32+ (normal: <2)
  • Only 95MB of 18GB RAM remained free
  • 10GB+ of data compressed in memory pressure
  • 15 processes stuck waiting for resources

Environment:

  • Claude Code version: 2.0.22
  • OS: macOS 15.5 (24F74)
  • Hardware: Apple M3 Pro, 18GB RAM
  • Process runtime: 13 hours 56 minutes before kill

Process Stats (from top):

PID 68794:
%CPU: 143.8
MEM: 23GB (VSZ: 516274048 KB)
TIME: 13:56:30
FAULTS: 2147483647 (overflow)
STATE: running/stuck

Reproduction:

Unknown - process was left running overnight with normal Claude Code usage

Expected Behavior:

Process should either:

  1. Self-terminate when idle
  2. Implement memory limits/cleanup
  3. Detect stuck state and exit gracefully

Workaround:

Monitor for stuck processes and manually kill with kill -9

What Should Happen?

What Should Happen?

Claude Code's compacting operation should complete reliably:

1. **Timeout mechanism**: Compacting should have a maximum timeout (e.g., 5 minutes)
2. **Progress indicator**: Show compacting progress or that operation is running
3. **Graceful failure**: If compacting fails/hangs, abort and allow process to continue/exit
4. **Non-blocking**: Compacting should not block terminal closure or user interactions
5. **Resource limits**: Even if stuck, process should cap memory usage
6. **Health check**: Detect hung operations and auto-restart or exit cleanly

**Expected behavior on terminal close:**
- If compacting is running, either:
  - Complete it quickly (< 5 seconds), or
  - Cancel it and save state for next launch, or

### Error Messages/Logs

```shell
Error Messages/Logs

No error messages were displayed to the user. Process appeared stuck/hung.

System-level diagnostics from `top -l 1`:

PID    COMMAND      %CPU  TIME       MEM      STATE    FAULTS
68794  claude       143.8 13:56:30   23GB     running  2147483647

Memory pressure (`vm_stat`):
Pages stored in compressor: 2702322
Compressions: 3654510494
Swapins: 333726653
Swapouts: 357130544

Load average: 5.32 (normal < 2.0 for M3 Pro)
Physical memory: 17GB used / 18GB total (only 95MB free)

Steps to Reproduce

Reproduction scenario:

  1. Launch Claude Code in terminal: claude
  2. Use normally until Claude Code performs an internal compacting operation
  3. Compacting operation hangs/freezes
  4. Terminal window becomes unresponsive with UI stuttering/flickering
  5. Terminal cannot be closed because it's waiting for the compacting task to complete
  6. Process continues running indefinitely, consuming increasing amounts of RAM and CPU
  7. After ~14 hours, process reaches 23GB RAM and 143% CPU usage

Key observations:

  • Trigger: Compacting operation (likely database/index compaction)
  • Symptom: Terminal froze during compacting, UI started stuttering
  • Root cause: Compacting task never completed, blocking terminal closure
  • Result: Process hung indefinitely, leaking memory and CPU

Environment:

  • Multiple Claude Code terminal sessions were open
  • macOS 15.5, Apple M3 Pro, 18GB RAM
  • Claude Code version 2.0.22

To detect if you're affected:

# Check for hung Claude processes
ps aux | grep claude

# Look for processes with:
# - High runtime (several hours)
# - CPU > 100%
# - Memory > several GB

Critical bug: Compacting operation can hang indefinitely, preventing graceful shutdown and causing severe resource leaks.

### Claude Model

Sonnet (default)

### Is this a regression?

Yes, this worked in a previous version

### Last Working Version

_No response_

### Claude Code Version

Claude Code version: 2.0.22

### Platform

Anthropic API

### Operating System

macOS

### Terminal/Shell

VS Code integrated terminal

### Additional Information

_No response_

Activity

  1. github-actions commented on Nov 10, 2025

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] Memory leak and runaway write loop in claude --continue causes 28GB memory usage #10505
    2. Critical Memory Leak: Claude Code Consumed 129GB RAM and Caused System Freeze #11315
    3. Claude Code Memory Leak - Process Grows to 120+ GB RAM and Gets OOM Killed #4953

    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

  2. xssdem commented on Nov 10, 2025

    @xssdem
    Author

    👎

    This is NOT a duplicate - my issue has a specific root cause not mentioned in the other issues:

    Key differences:

    1. Specific trigger: Compacting operation froze and never completed
    2. UI symptoms: Terminal window became unresponsive with stuttering/flickering interface
    3. Blocking behavior: Could not close terminal because it was waiting for compacting task to finish
    4. Gradual leak: Process ran for 14 hours, gradually consuming resources (not sudden spike)

    Relation to #10505:
    While #10505 involves a runaway write loop, my issue is about a stuck compacting operation that blocks terminal closure. The compacting task hung, preventing graceful shutdown and causing the process to leak
    resources indefinitely.

    Root cause: The compacting operation has no timeout mechanism and can hang indefinitely, preventing process termination and causing severe resource leaks.

    This is a distinct bug requiring investigation into the compacting operation specifically.

  3. github-actions commented on Dec 11, 2025

    @github-actions

    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.

  4. github-actions commented on Jan 11, 2026

    @github-actions

    This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

  5. github-actions commented on Jan 20, 2026

    @github-actions

    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.

  6. locked as resolved and limited conversation to collaborators on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreautocloseIssue will be closed automaticallybugSomething isn't workinghas reproHas detailed reproduction stepsmemoryperf:memoryplatform:macosIssue specifically occurs on macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions