[BUG] Memory leak: Claude process consuming 23GB RAM and 143% CPU after 14 hours of runtime
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?
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:
- Self-terminate when idle
- Implement memory limits/cleanup
- Detect stuck state and exit gracefully
Workaround:
Monitor for stuck processes and manually kill with kill -9 <PID>
What Should Happen?
What Should Happen?
```markdown
Claude Code's compacting operation should complete reliably:
- Timeout mechanism: Compacting should have a maximum timeout (e.g., 5 minutes)
- Progress indicator: Show compacting progress or that operation is running
- Graceful failure: If compacting fails/hangs, abort and allow process to continue/exit
- Non-blocking: Compacting should not block terminal closure or user interactions
- Resource limits: Even if stuck, process should cap memory usage
- 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
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:
- Launch Claude Code in terminal:
claude - Use normally until Claude Code performs an internal compacting operation
- Compacting operation hangs/freezes
- Terminal window becomes unresponsive with UI stuttering/flickering
- Terminal cannot be closed because it's waiting for the compacting task to complete
- Process continues running indefinitely, consuming increasing amounts of RAM and CPU
- 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:
```bash
# 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_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗