Fix Claude Code connection errors on Windows (ECONNREFUSED, Bun crash)
Fully resolve two common Claude Code errors on Windows - can't connect to the API (ECONNREFUSED) and a Bun crash (Internal assertion failure) - by removing the NPM build, clearing config caches, and installing the Native Stable build.
On this page
Two common errors when installing and using Claude Code on Windows are being unable to reach
the API (Unable to connect to API: ECONNREFUSED when you run a prompt) and a native compiler
crash (Bun has crashed: Internal assertion failure). The full fix: remove the deprecated NPM
install, clear the old caches/config, then reinstall using the Native Stable build.
Quick reference
Open PowerShell and run these commands in order.
-
Remove the old NPM install (if any):
npm uninstall -g @anthropic-ai/claude-code -
Delete the broken config and cache files:
Remove-Item -Path "$env:USERPROFILE\.claude" -Recurse -Force Remove-Item -Path "$env:USERPROFILE\.claude.json" -Force Remove-Item -Path ".claude" -Recurse -Force Remove-Item -Path ".mcp.json" -Force -
Reinstall with the Native Stable build:
& ([scriptblock]::Create((irm https://claude.ai/install.ps1))) stable
Step by step
Step 1: Remove the NPM build (deprecated)
Originally many people installed Claude Code through Node.js
(npm install -g @anthropic-ai/claude-code). Anthropic's docs now mark this as deprecated.
Running via Node.js on Windows often causes local port-resolution problems - most typically
the ECONNREFUSED error mid-prompt when the connection to the local server drops.
Remove the old build from NPM:
npm uninstall -g @anthropic-ai/claude-codeStep 2: Clear the cache and config files
When you move from NPM to the native build (compiled with the Bun core), the old JSON/YAML
config format may be incompatible. When Bun tries to read that file it can crash with:
panic: Internal assertion failure - Bun has crashed... yaml_parse(500).
To avoid leftovers from the old install, delete all the config cache (note: your old terminal chat history will be lost and the tool returns to its default state).
For your user account's home folder:
Remove-Item -Path "$env:USERPROFILE\.claude" -Recurse -Force
Remove-Item -Path "$env:USERPROFILE\.claude.json" -ForceIf there's a config file in the project folder where you opened PowerShell:
Remove-Item -Path ".claude" -Recurse -Force
Remove-Item -Path ".mcp.json" -ForceStep 3: Install the Native Stable build
The native build (a standalone .exe) runs lighter and skips the OS dependency. To avoid a
too-new Latest build hitting a Bun compiler bug on Windows (for example v2.1.100), it's best
to pin to the Stable channel:
& ([scriptblock]::Create((irm https://claude.ai/install.ps1))) stableTo update to the latest preview build later, drop the stable word and use irm https://claude.ai/install.ps1 | iex.
Troubleshooting / notes
- Rule out a proxy: sometimes the
ECONNREFUSEDerror comes from an HTTP agent forced onto the Windows terminal. Check for hidden proxy environment variables with$env:HTTP_PROXYor$env:HTTPS_PROXY, and clear them like$env:HTTP_PROXY=""if you find a stray proxy. - Extra system requirement: running
claudewith the native build doesn't need Administrator, but the machine must have Git for Windows installed, because Claude quietly uses its bundled Bash emulation library.
| Symptom | Fix |
|---|---|
ECONNREFUSED when running a prompt | Remove the NPM build, install Native Stable; check $env:HTTP_PROXY and $env:HTTPS_PROXY |
Bun has crashed: Internal assertion failure | Delete the old .claude, .claude.json, then reinstall the native build |
The claude command won't run | Install Git for Windows (Claude needs its bundled Bash emulation) |