Unresolvable TypeError: fetch failed on Clean WSL Installation
Body:
Environment
- Platform (select one):
- [x] Anthropic API
- Claude CLI version: 1.0.30 (Claude Code)
- Operating System: Windows 11 with WSL 2 (Ubuntu)
- Terminal: Windows Terminal (Ubuntu Profile)
Bug Description
The claude CLI tool consistently fails with API Error (Connection error.) which traces to a TypeError: fetch failed on any command that requires a network connection (e.g., /init). This occurs on a completely clean, fresh WSL (Ubuntu) installation with a correct Node.js environment, and persists after all known WSL networking workarounds have been applied.
Steps to Reproduce
- On a Windows 11 machine, install a fresh instance of WSL (Ubuntu).
- Install Node.js v20.x via the official NodeSource repository (
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs). - Configure npm to use a local directory:
npm config set prefix '~/.npm-global'and add~/.npm-global/binto thePATH. - Install the CLI:
npm install -g @anthropic-ai/claude-code. - Navigate to any project directory.
- Run
claude. - At the
>prompt, run/init.
Expected Behavior
The /init command should successfully connect to the Anthropic API, analyze the codebase, and generate a CLAUDE.md file.
Actual Behavior
The command fails with repeated API Error (Connection error.) messages. The underlying error is a TypeError: fetch failed.
Additional Context
This appears to be a critical application-level issue specific to the WSL environment, as all underlying system and Node.js network diagnostics succeed.
Key Diagnostic Information:
curl -v https://api.anthropic.com/v1/healthsucceeds.node -e "fetch('https://api.anthropic.com/v1/health')"succeeds.
Failed Mitigation Attempts:
We have exhaustively tried every common solution, none of which resolved the application's specific error:
- Forcing Node.js DNS to
ipv4firstviaNODE_OPTIONS. - A full WSL network reconfiguration (
wsl --shutdown,.wslconfigset tonetworkingMode=mirrored). - System-wide disabling of IPv6 in WSL via
sysctl. - Running on a fresh WSL instance with a correct Node.js installation (no
nvm).
This indicates a probable application-level issue (e.g., a bundled undici version, a custom network agent, or a certificate problem) that is incompatible with the WSL environment.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗