[BUG] "ReferenceError: Bun is not defined" fires repeatedly on Windows (npm install), causes crashes

Resolved 💬 8 comments Opened Jan 30, 2026 by renatoacairo Closed Mar 4, 2026

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?

Claude Code installed via npm install -g on Windows throws ReferenceError: Bun is not defined dozens of times per session. The error fires on nearly every API request cycle, eventually destabilizing the session and causing crashes (aborted API requests, session termination).

This is not a one-off error — it's a continuous loop. In a single session's debug log, I counted 30+ occurrences. The error occurs because the bundled cli.js contains code paths that reference the Bun runtime, but the npm-installed version runs on Node.js.

This has been happening across multiple recent versions, not just the current one.

Error Stack Trace

ReferenceError: Bun is not defined
    at i57 (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:1447:3896)
    at n57 (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:1447:4104)
    at IvK (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:5142:6790)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:5142:4110
    at async v_6 (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:1075:2007)
    at async aMA (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:5142:4080)
    at async nf (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:3143:5189)
    at async nf (file:///C:/Users/Renato/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:3143:11070)

Cascading failures observed in the same sessions

  1. API requests aborted — likely a consequence of the Bun error destabilizing the runtime:
API error (attempt 1/11): undefined Request was aborted.
Error in non-streaming fallback: Request was aborted.
Error: Request was aborted.
  1. Symlink permission errors on Windows (secondary, but related to Windows support):
Error: EPERM: operation not permitted, symlink
  'C:\Users\Renato\.claude\projects\...\subagents\agent-a615177.jsonl'
  -> 'C:\Users\Renato\AppData\Local\Temp\claude\...\tasks\a615177.output'

Steps to Reproduce

  1. Install Claude Code via npm on Windows: npm install -g @anthropic-ai/claude-code
  2. Start any session: claude
  3. Use the tool normally (any prompt works)
  4. Check debug log at ~/.claude/debug/<session-id>.txt
  5. Observe ReferenceError: Bun is not defined firing repeatedly throughout the session
  6. Session eventually crashes or API requests start aborting

What Should Happen

The code should detect the runtime (Node.js vs Bun) and avoid calling Bun-specific APIs when running under Node.js. The error should never fire at all on npm-installed versions.

Claude Model

Claude Opus 4.5 (also happens with other models)

Is this a regression?

No — has been present across multiple recent versions.

Last Working Version

_Unknown — has been present for several versions._

Claude Code Version

2.1.25

Platform

Anthropic API (OAuth)

Operating System

Windows 11

Terminal/Shell

Windows Terminal (Git Bash)

Additional Information

  • The error fires 30+ times in a single session (confirmed from debug logs).
  • This happens on a freshly restarted PC with no other applications running — not a memory/resource issue.
  • Issue #21809 also shows this same error in its logs but is filed as a different bug. This report isolates the Bun is not defined error as the primary issue.
  • The symlink EPERM error is a separate Windows issue (Windows requires elevated permissions or Developer Mode for symlinks), but compounds the instability.

View original on GitHub ↗

This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗