[BUG] Memory Leaks with Opus 4.6 CLI - massive sudden spikes in RAM/SWAP usage
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?
Environment:
- Claude Code (Max Plan)
- Model: Opus 4.6 (did NOT experience this on Opus 4.5)
- Platform: GCP VM, Ubuntu Linux, 15GB RAM, 16GB swap
- VS Code SSH Remote for terminal access
- Project type: Next.js
Frequency: 4 incidents in ~24 hours
Behavior:
Memory spikes suddenly (not gradual accumulation). Typical pattern:
- Normal operation at ~1GB RAM per session with occasional small spikes
- Issue simple command (e.g., "fix the font size on this badge")
- RAM spikes to 6-14GB within 1 minute (yes within 1 minute, not a typo)
- Status shows "0 tokens used"
- No tool calls visible in output
- Session appears to be "spinning" but never does anything
- Happened within main session as well as subagent session
Recovery:
- Pressing ESC immediately releases the memory IF caught as it's happening
- If not caught in time, swap fills up and VM becomes unresponsive
- First incident required a complete restart of the VM
- Second incident I was able to slowly and painfully access browser-based SSH and kill the Claude PID hogging 25GB of RAM+SWAP
- Third and fourth time I was able to hit ESC as it was happening after I installed a resource monitor
Possible trigger:
In one incident, the CC session self-diagnosed: "Yeah that was the system reminder trying to get me to use task
tools." The <system-reminder> about task tools may be triggering expensive processing.
Key observations:
- Spike happens BEFORE any action is actually taken by Claude Code (0 tokens)
- No tool calls executed — bug is in local preprocessing
- ESC releases memory instantly — suggests active allocation, not cached data
- Only happening on Opus 4.6, not 4.5
- All incidents on same Next.js project (not Python/Streamlit project on same VM, but I haven't tried Opus 4.6 on the python project yet)
Impact: VM crashes or becomes unresponsive if not caught quickly. Requires constant memory monitoring to use Claude Code reliably.
What Should Happen?
No good reason for Claude Code to hog 10GB+ RAM/SWAP within 1 minute without actually doing anything.
Error Messages/Logs
Steps to Reproduce
Unfortunately I can't replicate this on demand. It's happening randomly within a regular working session. This morning it happened after a fresh start (session had been compacted and restarted) on the second command.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
Version: 2.1.37
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗