Skip to content

Bun runtime unsuitable for long sessions: mimalloc crashes after 12-24h, ~1GB/h memory growth, system-wide stuttering #36132

@kolkov

Description

@kolkov

Summary

Bun runtime (v1.3.11) is not suitable for long-running Claude Code sessions. The mimalloc memory allocator crashes with "Illegal instruction" after 12-24 hours of continuous use, regardless of other fixes applied. This is a fundamental runtime limitation, not a Claude Code application bug.

Evidence: Two crashes, different causes, same mimalloc panic

Metric Crash #1 (v2.1.76) Crash #2 (v2.1.79)
Session duration 12.4 hours 23.7 hours
RSS 2.58 GB 1.73 GB
Committed memory 13.81 GB 15.40 GB
Page faults 27 million 67 million
Auto-updater Enabled (memory leak) Disabled (DISABLE_AUTOUPDATER=1)
Claude Code version 2.1.76 2.1.79
Crash address 0x7FF641918940 0x7FF7A3A98940
Error mimalloc scavenger panic mimalloc panic

Crash #1 was partially explained by the auto-updater memory leak (fixed in v2.1.77). Crash #2 occurred with auto-updater disabled — the mimalloc allocator itself leaks committed memory at roughly 0.6-1 GB/hour during active Claude Code sessions.

Crash details

Crash #1 (v2.1.76, 12.4 hours)

Bun v1.3.11 (a2743b6d) Windows x64 (baseline)
Elapsed: 44576556ms | RSS: 2.58GB | Commit: 13.81GB | Faults: 27235766
allocator->scavenger_data.is_in_use = yes
panic: Illegal instruction at address 0x7FF641918940

Crash #2 (v2.1.79, 23.7 hours)

Bun v1.3.11 (a2743b6d) Windows x64 (baseline)
Elapsed: 85278850ms | RSS: 1.73GB | Peak: 1.93GB | Commit: 15.40GB | Faults: 67347099
panic(thread 59820): Illegal instruction at address 0x7FF7A3A98940

Both crashes share the same pattern: mimalloc's scavenger (garbage collector) encounters an inconsistent state after hours of memory fragmentation → "Illegal instruction" → process terminates. In some cases the IDE (GoLand/VS Code) crashes along with it; in others the IDE survives but becomes sluggish due to memory pressure before the crash.

Impact

  • All unsaved work is lost — no graceful shutdown, no session save
  • IDE crashes too — if Claude Code runs inside GoLand/VS Code terminal, the IDE terminal tab dies
  • No warning — memory grows silently in the background, crash is sudden
  • System-wide impact — before crash, mimalloc garbage collection causes system-wide stuttering: mouse lag, keyboard input delays across ALL Windows applications, not just Claude Code
  • Affects autonomous agents — overnight agent runs (a key Claude Code use case) are unreliable
  • Debug log evidence: Slow PostToolUse hooks: 2319ms, Slow render: 143ms with full-screen damage, Edit tool validation error: File has not been read yet (tool result loss due to memory pressure)

Why this matters

Claude Code's value proposition includes long autonomous sessions — Rakuten famously ran a 7-hour autonomous refactoring of a 12.5M line codebase. But with Bun crashing after 12-24 hours, overnight and multi-hour autonomous sessions are a gamble.

Root cause

Bun v1.3.11 uses mimalloc as its memory allocator. During long-running sessions with many tool calls (thousands of Bash, Read, Edit, Write invocations), memory fragmentation accumulates. mimalloc's scavenger thread eventually encounters inconsistent allocator state, triggering a hardware trap (illegal instruction).

This is not specific to Claude Code — it's a Bun runtime issue. Related: oven-sh/bun#27690.

Suggested mitigations

  1. Short-term: Warn users after N hours of continuous session (e.g., "Session running for 12h — consider restarting to prevent crash")
  2. Short-term: Auto-save session state periodically so crash recovery is possible
  3. Medium-term: Upgrade Bun or switch mimalloc configuration to reduce fragmentation
  4. Long-term: Consider a more stable runtime — Node.js doesn't have this issue, and a Go rewrite would eliminate it entirely

Environment

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas reproHas detailed reproduction stepsperf:memoryplatform:windowsIssue specifically occurs on Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions