Unexpected cache for env variables

Where does the bug appear (feature/product)?

Cursor CLI

Describe the Bug

I used to have an environment system variable GEMINI_API_KEY in my Windows system. I created a node script to use Gemini API and set another GEMINI_API_KEY programmatically (i.e., in .env file). So, I removed the system env variable GEMINI_API_KEY from Windows. But when I run the script from CLI, it is still using the old value, not the new one from .env. I restarted IDE and Windows several times. The issue persists. I see process.env have the old value.

import dotenv from 'dotenv';

dotenv.config();
console.log(process.env); // process.env.GEMINI_API_KEY has the old value

When I tried in VS Code, it is fine and I found it uses the new value.

Steps to Reproduce

  1. Create a system environment variable in Windows, let’s say GEMINI_API_KEY.
  2. Create a node script that uses .env which have the same var name GEMINI_API_KEY.
  3. Run the script and it will use GEMINI_API_KEY from Windows.
  4. Delete GEMINI_API_KEY from Windows
  5. Restart PowerShell, IDE, Windows, etc.
  6. Run the script again and it will still use GEMINI_API_KEY from Windows. GEMINI_API_KEY from .env is never used.

Expected Behavior

After deleting GEMINI_API_KEY from Windows, I except GEMINI_API_KEY from .env to be used.

Operating System

Windows 10/11

Version Information

Version: 2.3.35 (system setup)
VSCode Version: 1.105.1
Commit: cf8353edc265f5e46b798bfb276861d0bf3bf120
Date: 2026-01-13T07:39:18.564Z
Electron: 37.7.0
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Windows_NT x64 10.0.26100

Does this stop you from using Cursor

No - Cursor works, but with this issue

1 Like

Hey, thanks for the report. This is a known issue with caching env variables in Cursor - a similar bug has been reported before.

Try this workaround - add the following to your settings.json:

"terminal.integrated.inheritEnv": false

After that, the terminal won’t inherit env from the parent process and should use the current values from .env.

I’ve passed the information to the team. Let me know if this helps!

Thank you for your support.

I found the setting from the menu File > Preferences > VS Code Settings. I unchecked the option, but I still see the old env value. It has no effect on Windows as described?

1 Like

I now see it is an issue in VS Code terminal too.