Claude Code, Codex CLI, and OpenCode on WSL2 Ubuntu 24.04: Complete Setup Guide
As of 2026-12-04, running Claude Code, Codex CLI, and OpenCode reliably on Windows requires installing them inside WSL2 Ubuntu 24.04, storing repositories on Linux ext4 (/home/<user>/projects), and configuring each tool inside WSL. WSL 1 triggers Exec format error in Claude Code and lacks the bubblewrap sandbox required by Codex CLI 0.115+. Isolating Linux installs from /mnt/c/Program Files/nodejs and writing your QCode cr_ key directly inside WSL prevents OS-mismatch errors and missing environment variables.
QCode is an independent third-party model API service, not affiliated with or endorsed by Anthropic, OpenAI, Google, Microsoft, or OpenCode. Facts in this guide were verified on 2026-12-04 against the official documentation linked below.
Updated 2026-12-04
Key facts
- WSL2 is required: Claude Code needs WSL 2 (Ubuntu 20.04+ including 24.04, Debian 10+, or Alpine 3.19+; 4 GB+ RAM) and throws
Exec format erroron WSL 1; Codex CLI (rust-v0.174.0track) dropped WSL 1 in0.115+due tobubblewrap. - Stop Windows Node.js PATH leaks: Install Claude Code with Anthropic's standalone script (
curl -fsSL https://claude.ai/install.sh | bash), and use standalone installers or Linux-nativenvm(Node 22 LTS) for Codex CLI and OpenCode (v2.4.4) sowhich nodenever hits/mnt/c/Program Files/nodejs. - Keep repos on Linux ext4: Cloning into
/home/<user>/projectsavoids DrvFs slowdowns, incomplete Claude Code search results, and Codex CLI SQLite timeouts under/mnt/c/.... - Windows env vars do not cross into WSL2: PowerShell variables stay on Windows, and
%USERPROFILE%\.codex\config.tomlis separate from WSL~/.codex/config.toml. - One QCode
cr_key covers three native protocols: Routeclaude-opus-5-5($4 / $20 per 1M) to/api,gpt-6.2-sol($2 / $10) to/openai, andgemini-4-neon($3 / $15, live on QCode since 2026-12-03) to/gemini(/gemini/v1betain OpenCode). - VS Code Remote-WSL & clipboard shortcut: Run
code .from Ubuntu with Microsoft's WSL extension (VS Code1.94.0+for Claude Code for VS Code), and useAlt+VwhenCtrl+Vfails to paste screenshots in a WSL terminal.
Why WSL2 (Ubuntu 24.04) works where WSL 1 fails
Modern terminal coding agents depend on a real Linux kernel for ELF binaries, process sandboxing, and fast POSIX file watching, which only WSL2 provides. As verified on 2026-12-04 in the Claude Code setup documentation and the OpenAI Codex CLI repository, WSL 1 fails immediately on two counts:
- Claude Code (
claude) officially requires WSL 2 (Ubuntu 20.04+ including 24.04, Debian 10+, or Alpine 3.19+, 4 GB+ RAM) and throwsExec format erroron WSL 1. - Codex CLI (
codex) dropped WSL 1 support in0.115+(current CLI trackrust-v0.174.0, Apache-2.0) because its Linux sandbox relies onbubblewrap.
Open Windows PowerShell first and confirm Ubuntu 24.04 runs on version 2:
# Check installed WSL distros and their WSL version (1 or 2)
wsl -l -v
# Convert Ubuntu-24.04 from WSL 1 to WSL 2 if VERSION shows 1
wsl --set-version Ubuntu-24.04 2
Once VERSION shows 2, all three CLIs share Ubuntu 24.04 cleanly:
| Tool (Verified 2026-12-04) | WSL2 Requirement | Recommended WSL2 Install | Linux Config File | QCode Base URL & Default Model |
|---|---|---|---|---|
Claude Code (claude) |
WSL 2, Ubuntu 20.04+, 4 GB+ RAM | curl -fsSL https://claude.ai/install.sh \| bash |
~/.claude/settings.json |
https://api.qcode.cc/api (claude-opus-5-5) |
Codex CLI (rust-v0.174.0, Apache-2.0) |
WSL 2 (0.115+ needs bubblewrap) |
curl -fsSL https://chatgpt.com/codex/install.sh \| sh or npm install -g @openai/codex |
~/.codex/config.toml + ~/.codex/auth.json |
https://api.qcode.cc/openai (gpt-6.2-sol) |
OpenCode (v2.4.4, MIT) |
WSL 2 (native Linux filesystem) | curl -fsSL https://opencode.ai/v2/install \| bash or npm i -g @opencode/cli@latest |
~/.config/opencode/opencode.json |
/api/v1, /openai/v1, /gemini/v1beta |
If you also run other Linux-first agents on Windows, see our Magpie WSL setup guide.
Fixing the top WSL2 traps: PATH leakage and /mnt/c slowdowns
Most WSL2 agent issues stem from Linux shells invoking Windows Node.js under /mnt/c/Program Files/nodejs or leaving Git repositories on the Windows NTFS mount under /mnt/c/. Both pitfalls are explicitly covered in Claude Code's troubleshooting guide and Microsoft's WSL filesystem documentation.
Stopping /mnt/c/Program Files/nodejs PATH leakage
WSL2 appends Windows PATH directories to Ubuntu shells by default. If Node.js is installed on Windows but missing inside Ubuntu, npm resolves to Windows' binary, triggering OS-mismatch packages or exec: node: not found errors.
Prefer standalone Linux installers first; if you install @openai/codex or @opencode/cli via npm, install Linux-native Node 22 LTS with nvm inside Ubuntu and verify which node:
# 1. Install Claude Code via Anthropic's standalone Linux installer (no Node.js required)
curl -fsSL https://claude.ai/install.sh | bash
# 2. Install Codex CLI via the standalone Linux script
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# 3. Install OpenCode v2 (installs binary to $HOME/.opencode/bin)
curl -fsSL https://opencode.ai/v2/install | bash
# 4. If you prefer npm for @openai/codex or @opencode/cli, verify Linux-native Node first
which node && which npm
# Expected: /home/<user>/.nvm/versions/node/v22.x.x/bin/node (NEVER /mnt/c/Program Files/nodejs)
If you install @anthropic-ai/claude-code via npm and it misdetects the host OS, Anthropic's fallback (without sudo) is npm config set os linux && npm install -g @anthropic-ai/claude-code --force. See our Claude Code installation guide for standalone checks.
Keeping repositories on Linux ext4 instead of /mnt/c
Active repositories belong under /home/<user>/projects on native Linux ext4, never under /mnt/c/.... Crossing the DrvFs translation boundary causes three recurring failures:
- Severe I/O latency:
git, dependency installs, and build tools run far slower on/mnt/c/than on ext4. - Incomplete searches: Claude Code file search can miss matches inside
/mnt/c/...mounts. - SQLite timeouts: Codex CLI session state stored in SQLite can hit lock timeouts across DrvFs.
Clone repos under /home/<user>/projects, and browse them from Windows Explorer via \\wsl$ when needed.
Configuring QCode inside WSL2 Ubuntu (Claude Code, Codex, OpenCode)
Environment variables set in Windows PowerShell or System Settings do not propagate into WSL2, so configure each agent inside Ubuntu. Windows %USERPROFILE%\.codex\config.toml and WSL ~/.codex/config.toml are also separate files — keep them aligned if you use Windows Codex Desktop alongside WSL2.
One QCode cr_ key works across https://api.qcode.cc, https://asia.qcode.cc, and https://us.qcode.cc, following strict protocol boundaries:
- Anthropic (
/api): Claude models only — defaultclaude-opus-5-5($4 / $20 per 1M, official API price ×1.0, 1M context),claude-sonnet-5-5($2 / $10),claude-fable-5-2($8 / $40), andclaude-haiku-5-5($0.10 / $0.50 up to 100K input). - OpenAI (
/openai,/openai/v1): GPT models only — defaultgpt-6.2-sol($2 / $10 ×1.0; >272K input uses OpenAI's 2× input / 1.5× output tier) andgpt-6.2-astra($8 / $40 ×1.0). Codex CLI useshttps://api.qcode.cc/openaiwithwire_api = "responses". - Google Gemini (
/gemini): Live on QCode since 2026-12-03 forgemini-4-neon($3 / $15 ×1.0, implicit cached read $0.15 / 1M, 1M context).gemini-4-carbon,gemini-4-argon, andgemini-4-hydrogenare not listed on QCode/modelsyet. - Listed Chinese models:
deepseek-v4.1-flash,kimi-k3.1-pro,glm-5.3, andqwen3.8-maxwork on/apiand/openai/v1, billed at the live /models rate.
1. Claude Code (~/.claude/settings.json)
Write strict JSON (no comments or trailing commas) to ~/.claude/settings.json; its "env" block overrides shell variables. Omit /v1 and any trailing slash from ANTHROPIC_BASE_URL (the SDK appends /v1/messages). Enterprise admins can opt into Windows policy inheritance via "wslInheritsWindowsSettings": true.
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"env": {
"ANTHROPIC_BASE_URL": "https://api.qcode.cc/api",
"ANTHROPIC_AUTH_TOKEN": "cr_your_key",
"ANTHROPIC_MODEL": "claude-opus-5-5"
}
}
ANTHROPIC_AUTH_TOKEN sends Authorization: Bearer cr_your_key and takes precedence over ANTHROPIC_API_KEY. See our ANTHROPIC_BASE_URL setup guide for additional client rules.
2. OpenAI Codex CLI (~/.codex/config.toml and ~/.codex/auth.json)
Codex CLI merges /etc/codex/config.toml, ~/.codex/config.toml, --profile, project .codex/config.toml (which cannot override model_provider, base_url, or auth), and CLI flags. Add QCode to ~/.codex/config.toml:
model_provider = "qcode"
model = "gpt-6.2-sol"
model_reasoning_effort = "high"
[model_providers.qcode]
name = "qcode"
base_url = "https://api.qcode.cc/openai"
wire_api = "responses"
requires_openai_auth = true
Save the same key in ~/.codex/auth.json (or run printenv OPENAI_API_KEY | codex login --with-api-key inside WSL):
{
"OPENAI_API_KEY": "cr_your_key"
}
With requires_openai_auth = true, Codex reads auth.json and ignores env_key; to use an environment variable instead, set requires_openai_auth = false and env_key = "QCODE_API_KEY" (never both). Inspect merged settings with codex doctor or /debug-config, and see our Codex CLI guide for profiles.
3. OpenCode (~/.config/opencode/opencode.json)
The OpenCode repository (v2.4.4, MIT) supports Anthropic, OpenAI, and Google Gemini in one ~/.config/opencode/opencode.json. Because OpenCode's @ai-sdk/anthropic appends /messages, include /v1 (https://api.qcode.cc/api/v1), and use /gemini/v1beta for @ai-sdk/google:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"npm": "@ai-sdk/anthropic",
"options": {
"baseURL": "https://api.qcode.cc/api/v1",
"apiKey": "{env:QCODE_API_KEY}"
}
},
"openai": {
"npm": "@ai-sdk/openai",
"options": {
"baseURL": "https://api.qcode.cc/openai/v1",
"apiKey": "{env:QCODE_API_KEY}"
}
},
"google": {
"npm": "@ai-sdk/google",
"options": {
"baseURL": "https://api.qcode.cc/gemini/v1beta",
"apiKey": "{env:QCODE_API_KEY}"
}
}
}
}
Add export QCODE_API_KEY="cr_your_key" to ~/.bashrc (or run opencode auth login / /connect). See our OpenCode AI coding guide for model-switching commands.
VS Code Remote-WSL, clipboard shortcuts, and endpoint health checks
Running VS Code through Microsoft's WSL extension keeps editing, terminals, and agents inside Ubuntu 24.04 on native ext4. Open your project with code . from Ubuntu (or WSL: Reopen Folder in WSL).
Three practical WSL2 tips prevent daily friction:
- Claude Code for VS Code (VS Code
1.94.0+) runs inside WSL2 and reads~/.claude/settings.jsondirectly. - Image paste in WSL terminals: Press
Alt+VwhenCtrl+Vfails to paste screenshots into Claude Code. - OAuth callback fallbacks: If you ever use browser login instead of an API key, copy the verification code from Windows into Claude Code's prompt, use
codex login --device-authfor Codex CLI, or exportBROWSER=/mnt/c/Progra~2/Microsoft/Edge/Application/msedge.exein~/.bashrcfor OpenCode.
Verify all three QCode endpoints from Ubuntu with curl. Since 2026-11-27, unauthenticated requests to /api/v1/models and /openai/v1/models return HTTP 401 application/json (invalid_api_key), while a valid cr_ key returns HTTP 200 JSON. Always test /v1/models (bare https://api.qcode.cc/api returns a 200 HTML page):
# 1. Confirm unauthenticated /v1/models returns HTTP 401 JSON (endpoint reachable)
curl -i -s https://api.qcode.cc/api/v1/models | head -n 12
# 2. Verify Anthropic, OpenAI, and Gemini endpoints with your cr_ key (expect HTTP 200 JSON)
curl -s -H "Authorization: Bearer cr_your_key" https://api.qcode.cc/api/v1/models | head -c 300
curl -s -H "Authorization: Bearer cr_your_key" https://api.qcode.cc/openai/v1/models | head -c 300
curl -s -H "x-goog-api-key: cr_your_key" https://api.qcode.cc/gemini/v1beta/models | head -c 300
# 3. Open your ext4 project directly inside VS Code Remote-WSL
cd ~/projects/my-app && code .
When all three authenticated calls return HTTP 200 JSON with claude-opus-5-5, gpt-6.2-sol, and gemini-4-neon, your WSL2 stack is ready.
FAQ
Why does Claude Code fail with Exec format error on WSL?
Your distro is running WSL 1 instead of WSL 2. Claude Code requires WSL 2 (Ubuntu 20.04+ including 24.04, 4 GB+ RAM). Check with wsl -l -v in PowerShell and convert using wsl --set-version Ubuntu-24.04 2.
Why did my Windows PowerShell API keys not work inside WSL2 Ubuntu?
Windows PowerShell and System Environment Variables do not carry over into WSL2 shells automatically. Define ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN inside WSL's ~/.claude/settings.json (or ~/.bashrc), and maintain WSL ~/.codex/config.toml separately from %USERPROFILE%\.codex\config.toml.
Should I clone Git repositories under /mnt/c or /home in WSL2?
Always clone under native Linux ext4, such as /home/<user>/projects. Using /mnt/c/... routes I/O through DrvFs, slowing git and package installs, causing incomplete Claude Code search results, and triggering Codex CLI SQLite timeouts.
Why does npm install inside WSL2 fail with OS mismatch or node not found?
WSL2 inherits Windows PATH by default, so npm can invoke /mnt/c/Program Files/nodejs if Linux Node is absent. Install Claude Code with curl -fsSL https://claude.ai/install.sh | bash (no Node required), and install Node 22 LTS via nvm inside Ubuntu so which node resolves under ~/.nvm/.
How do I paste screenshots into Claude Code in a WSL2 terminal?
Press Alt+V when Ctrl+V fails to paste clipboard images in a WSL terminal, per Anthropic's troubleshooting guide.
Can one QCode key run Claude Code, Codex CLI, and OpenCode with Gemini 4 Neon in WSL2?
Yes. As of 2026-12-04, one cr_ key works across /api (claude-opus-5-5), /openai (gpt-6.2-sol), and /gemini or /gemini/v1beta (gemini-4-neon). Keep each family on its native endpoint; gemini-4-carbon, gemini-4-argon, and gemini-4-hydrogen are not listed on QCode /models yet.
One QCode key for Claude Code, Codex CLI, and OpenCode on WSL2
Running all three agents in WSL2 Ubuntu 24.04 takes only one QCode cr_ key covering Claude 5.5 (claude-opus-5-5 at $4 / $20), GPT-6.2 (gpt-6.2-sol at $2 / $10), and gemini-4-neon ($3 / $15) at official API price ×1.0, plus listed Chinese models at the live /models rate. Pay-as-you-go packs start at $4 for $30 of quota (7 days valid, stackable on renewal) on /pay-as-you-go, while 30-day personal plans start at $9 ($5/day, resetting at 00:00 UTC+8) on /pricing.