Claude Code on Windows in 2026: WSL vs Native Setup (Plus a Cheaper API Option)
Claude Code runs natively on Windows as of 2026, but WSL (Windows Subsystem for Linux) still gives a smoother experience with fewer path and permission errors. If you just want the fastest working setup: install Node.js 18+, run npm install -g @anthropic-ai/claude-code, then set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY before launching claude in your project folder.
Native Windows vs WSL: Which Should You Use?
Anthropic added native Windows support to Claude Code in early 2026, so you no longer strictly need WSL. That said, the two paths behave differently in practice:
| Setup | Pros | Cons |
|---|---|---|
| Native Windows (PowerShell/cmd) | No extra install, works with Windows file paths directly, faster for simple projects | Occasional issues with shell tool calls, some npm global scripts fail silently on PATH problems |
| WSL2 (Ubuntu) | Matches Anthropic's primary dev/test environment, better compatibility with bash-based tool calls and git hooks | Extra install step, file paths cross the Windows/Linux boundary (/mnt/c/...), slightly higher memory use |
If your project already uses Docker, WSL2, or a Linux-based build pipeline, keep using WSL — Claude Code will simply feel more predictable there. If you're doing lightweight scripting or working purely with Windows-native tools (e.g. .NET, PowerShell automation), native install is fine.
Native Windows Setup (Step by Step)
# 1. Install Node.js 18 or newer from nodejs.org (check "Add to PATH" during install)
# 2. Verify Node and npm
node -v
npm -v
# 3. Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# 4. Confirm the binary is on PATH
claude --version
# 5. Set your API credentials (PowerShell)
$env:ANTHROPIC_BASE_URL = "https://your-relay-endpoint/v1"
$env:ANTHROPIC_API_KEY = "sk-xxxxxxxx"
# 6. Launch inside your project directory
cd C:\Users\you\projects\myapp
claude
To make the environment variables persistent, add them via System Properties → Environment Variables instead of setting them per-session, otherwise you'll need to re-export them every time you open a new terminal.
WSL2 Setup (Step by Step)
# 1. Enable WSL2 and install Ubuntu (PowerShell, run as Administrator)
wsl --install -d Ubuntu
# 2. Inside the Ubuntu shell, install Node via nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
nvm install 20
# 3. Install Claude Code
npm install -g @anthropic-ai/claude-code
# 4. Add credentials to ~/.bashrc so they persist
echo 'export ANTHROPIC_BASE_URL="https://your-relay-endpoint/v1"' >> ~/.bashrc
echo 'export ANTHROPIC_API_KEY="sk-xxxxxxxx"' >> ~/.bashrc
source ~/.bashrc
# 5. cd into your project (Windows drives are mounted under /mnt/c)
cd /mnt/c/Users/you/projects/myapp
claude
Common Errors and Fixes
| Error | Cause | Fix |
|---|---|---|
'claude' is not recognized | npm global bin folder not on PATH | Run npm config get prefix, add that path to your Windows PATH variable, restart the terminal |
| EACCES / permission denied on WSL | Global npm install used sudo inconsistently | Reinstall Node via nvm inside WSL instead of the system apt package, avoid sudo npm install -g |
| Requests hang or time out | Corporate proxy or firewall blocking outbound HTTPS | Set HTTPS_PROXY env var, or switch to a relay endpoint reachable without a VPN |
| 401 Unauthorized | API key not exported in the current shell session | Confirm with echo $ANTHROPIC_API_KEY (WSL) or echo $env:ANTHROPIC_API_KEY (PowerShell) |
Cutting the Cost (and Skipping the Credit Card)
Once Claude Code is running, the bigger recurring cost is usage — long agentic sessions burn through tokens fast, and Anthropic's direct API requires a US-billing-compatible credit card, which isn't always available outside the US. A practical workaround developers use in 2026 is pointing ANTHROPIC_BASE_URL at an OpenAI-compatible relay instead of Anthropic's endpoint directly. This is exactly the setup shown above — you only change the base URL and key, no code changes needed.
Safa API is one such relay: it forwards requests to the official Claude, GPT, and Gemini APIs without degrading model quality, supports prompt caching to cut repeated-context costs, accepts Alipay so you don't need a foreign credit card, and lets you switch between Claude/GPT/Gemini under one API key and one endpoint — useful if you want to fall back to another model when one provider is slow or rate-limited. Pricing is generally lower than official direct billing, which matters if Claude Code is your daily driver.
常见问题 / FAQ
Do I need WSL to run Claude Code on Windows in 2026?
No. Claude Code has native Windows support, but WSL2 still gives more consistent behavior for bash-based tool calls, git hooks, and Docker-based projects.
Why does Claude Code say "command not found" after npm install?
This almost always means the npm global bin directory isn't on your PATH. Run npm config get prefix and add the result to your PATH, then restart the terminal.
Can I use Claude Code without a US credit card?
Yes — set ANTHROPIC_BASE_URL to a third-party relay endpoint that accepts local payment methods like Alipay, instead of billing directly through Anthropic.
官方直连 · 一个接口接入 Claude / GPT / Gemini · 7×24 稳定
免费注册试用 →