[BUG] `ELECTRON_RUN_AS_NODE=1` environment variable leaks from Claude Code into child processes, preventing Electron apps from starting
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude Code sets ELECTRON_RUN_AS_NODE=1 in its environment, which leaks into all child processes (Bash tool, integrated terminal). This causes any Electron app started from Claude Code to run in Node.js mode instead of app mode.
Result:
process.typeisundefined(should be"browser")require("electron")returns the binary path string instead of the Electron API object- Every Electron app crashes with:
TypeError: Cannot read properties of undefined (reading 'whenReady')
This affects ALL Electron versions (tested: 28, 33, 40, 41) and ALL build tools (raw Electron, electron-vite, Electron Forge).
What Should Happen?
Claude Code should not leak ELECTRON_RUN_AS_NODE=1 into child process environments. Electron apps started from Claude Code's terminal should run in normal app mode, just like when started from a regular terminal.
Error Messages/Logs
# Error when running official Electron Quick Start from Claude Code:
> electron .
/private/tmp/eq-test/main.js:25
app.whenReady().then(() => {
^
TypeError: Cannot read properties of undefined (reading 'whenReady')
at Object.<anonymous> (/private/tmp/eq-test/main.js:25:5)
at Module._compile (node:internal/modules/cjs/loader:1820:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1953:10)
at Module.load (node:internal/modules/cjs/loader:1540:32)
at Module._load (node:internal/modules/cjs/loader:1342:12)
at c._load (node:electron/js2c/node_init:2:17999)
at wrapModuleLoad (node:internal/modules/cjs/loader:262:19)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:169:5)
at node:internal/main/run_main_module:33:47
Node.js v24.14.0
# Diagnosis — the leaked env var:
$ echo $ELECTRON_RUN_AS_NODE
1
# process.type is undefined (should be "browser"):
$ electron -e "console.log('process.type:', process.type)"
process.type: undefined
# require("electron") returns string path, not API object:
$ electron -e "const e = require('electron'); console.log(typeof e, String(e).substring(0,80))"
string /path/to/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron
# After unsetting — everything works:
$ ELECTRON_RUN_AS_NODE= electron -e "console.log('process.type:', process.type)"
process.type: browser
Steps to Reproduce
- Open Claude Code (VS Code extension or CLI)
- In the terminal, verify the leaked variable:
echo $ELECTRON_RUN_AS_NODE
\# Output: 1
- Clone and run the official Electron Quick Start:
git clone https://github.com/electron/electron-quick-start.git /tmp/eq-test
cd /tmp/eq-test
npm install
npm start
- Observe the crash: TypeError: Cannot read properties of undefined (reading 'whenReady')
- Now unset the variable and try again:
ELECTRON_RUN_AS_NODE= npm start
- Electron starts successfully.
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.76
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
Root Cause
Claude Code is an Electron-based app. It sets ELECTRON_RUN_AS_NODE=1 so its own Node.js processes run correctly. However, this environment variable is inherited by all child processes spawned from Claude Code — including the user's terminal sessions and Bash tool invocations.
When a user starts an Electron app from this environment, the ELECTRON_RUN_AS_NODE=1 variable forces the Electron binary into Node.js mode, disabling the built-in electron module and preventing app initialization.
Workaround
Prefix Electron commands with ELECTRON_RUN_AS_NODE=:
- Terminal:
ELECTRON_RUN_AS_NODE= npm start - package.json:
"dev": "ELECTRON_RUN_AS_NODE= electron-vite dev"
Suggested Fix
Unset ELECTRON_RUN_AS_NODE from the environment before spawning child shells/processes:
delete process.env.ELECTRON_RUN_AS_NODEbeforechild_process.spawn()- Or pass
env: { ...process.env, ELECTRON_RUN_AS_NODE: '' }in spawn options
Tested Configurations (all fail without workaround)
| Electron | Build Tool | Package Manager | Result |
|----------|-----------|-----------------|--------|
| 28.3.3 | raw | npm | ❌ crash |
| 33.4.11 | electron-vite | pnpm | ❌ crash |
| 40.8.0 | raw | npm | ❌ crash |
| 41.0.2 | electron-vite | npm | ❌ crash |
All work correctly after ELECTRON_RUN_AS_NODE= (unset).
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗