Environment variables from the first VS Code launch carry over to later windows
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Type: Bug
## Description
VS Code keeps a shared main process running across windows. When the first window starts with an environment variable, the main process keeps that value. Later windows inherit the same value, even when they open unrelated directories. It remains visible in their integrated terminals unless it is overwritten.
For example, a developer loads an LLM API key into the current environment. They then launch VS Code with `code` to debug an AI agent. The key unexpectedly appears in other newly opened VS Code windows.
## Steps to Reproduce (using `code-insiders` instead of `code`)
1. Exit all VS Code instances and prepare two empty directories: `D:\probe-a` and `D:\probe-b`.
2. In the first `cmd.exe`, run:
```cmd
set MY_API_KEY=abcdefghijklmn
code-insiders --disable-extensions --new-window D:\probe-a
```
3. Wait for the first VS Code window to finish opening.
4. Open a new `cmd.exe` and run:
```cmd
:: Clear the variable and confirm it is not set in this terminal:
set MY_API_KEY=
set MY_API_KEY
:: Start the second VS Code window:
code-insiders --disable-extensions --new-window D:\probe-b
```
5. In the second VS Code window, open the integrated terminal and run:
```cmd
cmd
set MY_API_KEY
```
## Actual Result
The second window displays:
`MY_API_KEY=abcdefghijklmn`
## Expected Result
A variable passed when opening the first window should not silently carry over to another window opened from a separate terminal.
## Additional Information
This affects workflows that launch VS Code with the `code` command. The variable remains visible to later windows until all VS Code instances are closed.
Related but not identical issues:
- https://github.com/microsoft/vscode/issues/47816
- https://github.com/microsoft/vscode/issues/194736
VS Code version: Code - Insiders 1.131.0-insider (b9ebf999d312fa4a308b624eef68731c6057459a, 2026-07-24T16:39:12Z)
OS version: Windows_NT x64 10.0.26200
Modes:
System Info
|Item|Value|
|---|---|
|CPUs|AMD Ryzen 9 7950X3D 16-Core Processor (32 x 4192)|
|GPU Status|2d_canvas: enabled
GPU0: VENDOR= 0x10de, DEVICE=0x2684 [NVIDIA GeForce RTX 4090], DRIVER_VENDOR=NVIDIA, DRIVER_VERSION=32.0.15.9186 *ACTIVE*
GPU1: VENDOR= 0x1002, DEVICE=0x164e [AMD Radeon(TM) Graphics], DRIVER_VERSION=32.0.21043.5001
GPU2: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.26100.8875
Machine model name:
Machine model version:
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgpu: enabled
webnn: disabled_off|
|Load (avg)|undefined|
|Memory (System)|191.21GB (153.95GB free)|
|Process Argv|--disable-extensions --new-window D:\\probe-a --crash-reporter-id 016c6548-017b-496f-b626-b2d30a6f7e24|
|Screen Reader|no|
|VM|0%|
Extensions disabled
A/B Experiments
```
vsliv368:30146709
pythonvspyt551:31249597
nativeloc1:31118317
dwcopilot:31158714
dwoutputs:31242946
copilot_t_ci:31333650
g012b348:31231168
pythonrdcb7:31268811
pythonpcpt1cf:31399617
6518g693:31302842
b6b4d950:31327385
envsactivate1:31349248
editstats-enabled:31346256
cloudbuttont:31366566
3efgi100_wstrepl:31403338
839jf696:31457053
cp_cls_t_966_ss:31526232
4je02754:31455664
c3h7c220:31478652
cp_cls_c_1081:31454833
conptydll_true:31485575
e9c30283:31453065
test_treatment2:31471001
46204921:31447328
idci7584:31454084
e3e4d672:31454087
ei9d7968:31462942
f860i809:31458078
hhf17803:31462392
7e187181:31482583
h08i8180_copy:31475366
ec1eg703:31520046
ddid_c:31478205
hmra_i5g22:31518061
bjc72774_agent_sandbox:31538428
7df3h592:31491241
cp_cls_t_1082:31535311
logging_enabled_new:31490725
jb_cp_cls_t_632:31543129
32d76977:31503652
ha629193:31508444
cdk-lw-on:31524445
f9bf7985:31541111
a1ije391_t:31533808
g4a0e106:31510899
8hfba999:31537718
jbcp_cls_pctr_t:31531130
cp_intellij_t_nes:31548657
jf4hg949:31526829
hide-eh-duplicates:31543293
h561g132:31534507
replace-eh-with-ah:31545853
ihg5j128:31534457
f412h606:31543414
enable_editor_pane_layout:31551200
52258b4d:31547953
fbihi617_lg_t:31548132
ac562147:31553899
c7c27ce7:31551212
0dg73464:31554309
d4c76da2:31554780
treatment-23-1:31555779
unuse_dynamic_mcp:31555281
```
Contributor guide
Assessment
This issue has not been assessed yet.