Fix Claude Code 'Bun Has Crashed' Error
The “Bun has crashed” message in Claude Code means the Bun runtime hit a fatal error — usually a segfault or out-of-memory condition. This guide gives you the exact diagnostic and fix steps to resolve it permanently.
The Problem
You are working in Claude Code and suddenly see Bun has crashed. Report this as a bug: followed by a crash report with a stack trace. The process exits immediately, and you lose your current conversation context. This is different from a handled error — Bun itself has terminated due to an unrecoverable condition.
Quick Solution
Step 1: Check the crash report. Bun prints a crash URL or stack trace. Look for the key indicator:
# If the crash just happened, check the most recent crash report:
ls -la /tmp/bun-crash-*
Step 2: Update Bun to the latest version. Most “Bun has crashed” issues are fixed in newer releases:
bun upgrade
bun --version
Verify you are on version 1.1+ at minimum.
Step 3: If the crash happens specifically during large file operations, increase memory:
export BUN_JSC_FORCE_RAM_SIZE=8192
claude
Step 4: If the crash is reproducible (happens every time you do the same operation), identify the trigger. Run with debug output:
BUN_DEBUG_QUIET_LOGS=0 BUN_GARBAGE_COLLECTOR_LEVEL=2 claude 2>/tmp/bun-debug.log
Then reproduce the crash and check the log:
tail -100 /tmp/bun-debug.log
Step 5: If nothing else works, switch to Node.js as your runtime:
npm install -g @anthropic-ai/claude-code
claude
This uses Node.js instead of Bun, bypassing the crash entirely.
How It Works
“Bun has crashed” is Bun’s top-level crash handler for unrecoverable errors. It triggers when JavaScriptCore (Bun’s JS engine) encounters a segmentation fault, when the process runs out of memory, or when an internal assertion fails. Claude Code is a memory-intensive application — it holds conversation context, file buffers, and tool outputs in the JS heap simultaneously. Under Bun, the JSC garbage collector may handle these allocation patterns differently than V8 (Node.js), occasionally triggering a crash. The crash handler captures a stack trace and suggests filing a bug report with the Bun team.
Common Issues
Segfault during WebSocket operations. Claude Code uses streaming WebSocket connections to the API. Bun’s WebSocket implementation has had segfault bugs in certain connection lifecycle scenarios. Upgrading Bun usually fixes this.
Crash on macOS after sleep/wake. If your Mac went to sleep and you resume Claude Code, the network connection may be in a broken state that triggers a Bun crash. Close and reopen your terminal, then restart Claude Code.
Crash in Docker containers with low memory. If running Claude Code in a container with less than 2GB RAM, Bun may crash under memory pressure. Increase the container’s memory limit:
docker run --memory=4g your-image claude
Example CLAUDE.md Section
# Crash Prevention
## Runtime
- Bun runtime with BUN_JSC_FORCE_RAM_SIZE=8192
- If "Bun has crashed" occurs, switch to Node.js: npm install -g @anthropic-ai/claude-code
## Stability Rules
- Commit code before large refactoring operations
- Do not read files larger than 1MB — use grep to find relevant sections
- Limit concurrent file operations to avoid memory spikes
- If working in Docker, ensure container has minimum 4GB RAM
## After a Crash
- Check git status for any partial writes
- Review /tmp/bun-crash-* for crash reports
- Restart Claude Code with: claude --no-resume
- Report persistent crashes to github.com/oven-sh/bun/issues
Best Practices
-
Auto-save with git commits. Before any large operation (multi-file refactor, dependency update), commit your work. A “Bun has crashed” error can leave files in a partially modified state.
-
Set BUN_JSC_FORCE_RAM_SIZE in your shell profile. Do not rely on defaults. Add
export BUN_JSC_FORCE_RAM_SIZE=8192to~/.zshrcso every Claude Code session has adequate memory. -
Keep both Node.js and Bun installed. When Bun crashes block your work, switching to Node.js is the fastest path back to productivity. Have both runtimes ready.
-
File crash reports. The Bun team actively fixes crash bugs. Reporting the crash URL from the error message helps them prioritize fixes.
-
Monitor for patterns. If crashes happen at specific times (after sleep, during large reads, during network reconnects), document the pattern and avoid the trigger while waiting for a fix.
Related Reading
- Claude Code Bun Crash Fix
- Claude Code Docker Build Failed Fix
- Best Way to Use Claude Code for Debugging Sessions
Built by theluckystrike. More at zovo.one