[Windows] Blank VS Code windows open on startup — missing ELECTRON_RUN_AS_NODE=1
Bug Description
On Windows, every time Claude Code starts, 3+ blank VS Code welcome windows pop up. This happens because Claude Code calls code --list-extensions, code --list-extensions --show-versions, and code --force --install-extension anthropic.claude-code on startup without setting ELECTRON_RUN_AS_NODE=1 in the environment.
Root Cause
The function that provides the environment for these code CLI calls (minified, name varies per version — LV8 in 2.1.55, fD8 in 2.0.77, tE0 in another 2.0.77 build) handles Linux correctly but returns undefined on Windows:
// Current (broken on Windows)
function XXX() {
if (platform() === "linux") return { ...process.env, DISPLAY: "" };
return; // undefined — no ELECTRON_RUN_AS_NODE
}
Without ELECTRON_RUN_AS_NODE=1, the code command resolves to VS Code's bash script which calls Code.exe. On Windows, the env var set inside the bash script doesn't survive the process chain properly, so Code.exe launches as a full GUI Electron app instead of a headless Node CLI. This triggers VS Code's single-instance mechanism via Explorer, opening blank welcome windows.
Fix
One-line change — return ELECTRON_RUN_AS_NODE=1 on non-Linux platforms:
// Fixed
function XXX() {
if (platform() === "linux") return { ...process.env, DISPLAY: "" };
return { ...process.env, ELECTRON_RUN_AS_NODE: "1" };
}
Steps to Reproduce
- Install Claude Code on Windows 10/11
- Open VS Code
- Launch Claude Code from VS Code's terminal
- Observe 3+ blank VS Code welcome windows appearing
Environment
- OS: Windows 10 Pro 10.0.19045
- Claude Code versions tested: 2.0.77, 2.1.55, 2.1.71 (all affected)
- VS Code versions tested: Multiple (downgraded 2 levels, same issue)
- Node: System node via npm global install
Diagnosis Method
Used a PowerShell process monitor script to capture parent-child process chains of every new Code.exe process. This revealed:
node(Claude Code cli.js) spawnscode --list-extensionscoderesolves to VS Code's bash script → callsCode.exewithoutELECTRON_RUN_AS_NODE=1Code.exelaunches as full GUI Electron app- Existing VS Code instance (via Explorer) opens new blank renderer windows
Workaround
Manually patch the minified cli.js using regex to find and fix the function. Pattern to match:
(function \w+\(\)\{if\(\w+\(\)==="linux"\)return\{\.\.\.process\.env,DISPLAY:""\});return\}
Replace the trailing ;return} with ;return{...process.env,ELECTRON_RUN_AS_NODE:"1"}}.
Note: This patch must be re-applied after every Claude Code update since cli.js gets overwritten.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗