Claude Code stores all bash output in memory causing 90GB+ memory usage and crashes
Description
Claude Code appears to store all bash command output in memory for the entire session, leading to catastrophic memory usage that can reach 90GB+ and crash the application. This makes Claude Code unusable for real development workflows involving tests, builds, or any commands with substantial output.
Steps to Reproduce
- Start a Claude Code session
- Run
npm teston a project with comprehensive test suites (150+ tests) - Run
npm run buildon a medium-sized project - Continue working for 30-50 messages
- Watch system memory usage climb to 90GB+
Expected Behavior
- Bash output should be streamed and discarded after display
- Old command outputs should be garbage collected
- Memory usage should remain reasonable (<2GB for typical sessions)
Actual Behavior
- ALL bash output is retained in memory permanently
- Memory usage grows linearly with command output
- Sessions become unusable after running tests/builds
- Only fix is restarting Claude Code entirely
Impact
This issue makes Claude Code unsuitable for professional development work. We've had to implement extreme workarounds:
# Forced to use these truncated commands to prevent crashes:
npm test 2>&1 | tail -30 # Instead of npm test
npm run build 2>&1 | grep -i "error\|warning" || echo "✅" # Instead of npm run build
npm install --silent # Instead of npm install
System Information
- OS: macOS 15.6.1 (Darwin 24.6.0)
- Platform: darwin (arm64)
- Typical memory usage: 90GB+ after running tests/builds
Suggested Solutions
- Stream output without storing: Display bash output but don't retain it
- Output size limits: Auto-truncate stored output after X MB
- Garbage collection: Discard output older than N messages
- User preferences: Add settings for memory management:
claude.maxOutputRetention: 10MBclaude.discardOldOutput: trueclaude.streamOnlyMode: true
Workaround (Not Acceptable Long-term)
Currently forced to:
- Pipe all commands through
tail/grep - Restart Claude Code when memory exceeds limits
- Avoid running tests/builds entirely
- Keep sessions under 30 messages
Additional Context
This issue has been persistent enough that we've had to document extensive memory management rules in our project. Multiple sessions have crashed with 90GB+ memory usage. This is a critical blocker for using Claude Code in production development.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗