Cursor IDE is incorrectly parsing environment variables from .env files by including inline comments as part of the variable value. This persists even after clearing cache and restarting the application.
Environment
OS: macOS 24.3.0
Cursor Version: Latest (as of February 2024)
Project Type: Node.js/TypeScript application using pnpm
Steps to Reproduce
Create a .env file with an environment variable that has an inline comment:
CACHE_STORE=database # Defaults to database. Other available cache store: redis and filesystem
Try to read the environment variable in your application
The variable value incorrectly includes the comment text
Expected Behavior
Environment variable CACHE_STORE should have the value database
Comments should be ignored when parsing the .env file
Actual Behavior
Environment variable CACHE_STORE has the value database # Defaults to database. Other available cache store: redis and filesystem
The comment is being included as part of the variable value
This behavior persists even after:
Clearing Cursorās cache directories
Restarting the application
Setting terminal.integrated.inheritEnv to true
Starting a new shell session
Investigation Details
Verified the issue is Cursor-specific by testing in other editors (W i n d s u r f) where the environment variables are parsed correctly
Attempted to resolve by clearing cache directories in:
~/Library/Application Support/Cursor/
Various cache subdirectories (Cache, CachedData, etc.)
Checked configuration files:
config.json
settings.json
Workspace storage
Modified terminal settings without success
Impact
This bug affects any application that relies on environment variables with inline comments in their .env files, potentially causing configuration issues and application malfunctions.
Workaround
Currently, the only reliable workarounds are:
Remove all inline comments from .env files
Use a different IDE/editor
Move comments to their own lines
Critical Persistence Issue
A particularly concerning aspect of this bug is the extreme persistence of incorrectly parsed environment variables:
Once Cursor incorrectly parses and stores an environment variable, it becomes effectively āstuckā:
The stored value persists even when the .env file is modified
New values in the .env file are ignored in favor of the cached version
The application consistently reverts to the first incorrectly parsed value
Attempted Resolution Methods (All Failed):
Clearing all Cursor cache directories
Restarting Cursor
Creating new terminal sessions
Modifying terminal inheritance settings
Explicitly unsetting the variables in the terminal
Reloading the workspace
Cache Clearing Ineffectiveness:
Despite clearing cache directories in ~/Library/Application Support/Cursor/
Despite removing cached data from various subdirectories
Despite restarting the application
The original, incorrect environment variable value persists
This persistence suggests that Cursor is either:
Storing environment variables in an undocumented location
Implementing aggressive caching that overrides the actual .env file values
Not properly refreshing its environment variable cache when files are modified
The inability to update stored environment variables without a complete reinstall represents a significant usability issue, especially during development when environment configurations need to be modified frequently.
Additional Notes
The issue appears to be related to how Cursor handles environment variable parsing rather than the actual application code
The problem persists across different shell sessions and terminal instances within Cursor
The behavior is consistent and reproducible across different projects
Similar issue here - old DATABASE_URL that was set in a previous version of a .env file is persisting despite it having changed, and despite the .env file being deleted.
Causing issues with updating database connections in my Next.js app.
This doesnāt seem like a Cursor issue on the surface (although it could be contributing to it) - the .env file is read by your application code, not Cursor. Youāll need to check how your app is loading the environment variables
Most likely youāre using something like dotenv to load the .env file. Try running printenv DATABASE_URL in your terminal to see if the var is actually set in your shell environment
If we can track down a cause within Cursor, or at least the difference with what Cursor is doing vs any other software that works, Iād be happy to get the team to fix whatever the issue is!
I finally came back to Cursor after a ~14 day hiatus with a fresh pair of eyes and got Cursor to help me find the root cause of the problemā¦
The root cause of the problem is the folder where Cursor stores state in the globalStorage folder inside a userās Library folder
Unfortunately, the solution wiped the chat history, so Iām not able to show what happened, but suffice to say, I was asked to completely shut down Cursor and run the following command in Terminal and I think itās worked:
rick@Mac ~ % rm ~/Library/Application\ Support/Cursor/User/globalStorage/state.vscdb* 2>/dev/null && echo āState files removed. Please restart Cursor.ā
State files removed. Please restart Cursor.
rick@Mac ~ %
Cursor stored my initial .env file which had documentation within it (it was a repo I had cloned), like this:
In the .env file:
CACHE_STORE=database # Other options include āfilesystemā
Despite changing the value to CACHE_STORE=filesystem, what it actually stored was āCACHE_STORE=database # Other options include āfilesystemāā as a stringā¦
No matter what I did, nothing would change the value of CACHE_STORE when I tried to run the code in Cursorā¦It was only when I tried to duplicate the error in Windsurt out of desperation that I realised that this was a bug in Cursor.
I hope this helps the team fix this incredibly painful issue - I lost two weeks worth of work because of this - In sheer desperation I ditched the prototype I was working on and re-built it in another IDE that workedā¦
It shouldnāt be this hardā¦Hope this helps othersā¦
This has been driving me nuts for at least a month now. Thank you for getting to the bottom of it!!! I love cursor but this bug made it virtually unusable for projects that I had used inline comments with.
Pretty much an identical issue. Unfortunately, I donāt have a globalStorage folder and cannot resolve this.
What seems to be occuring is that Cursor on startup is reading from my .env file and setting the envās based on the file. Then any subsequent updates to the .env file donāt update within Cursorās integrated terminal.
Any attempts of using load_dotenv() without override=True result in the old (seemingly cached) version of my env variable being used. Inline comments also get picked up as part of the env variable ā thankfully I just edited them to be non-inline.
My colleague has the exact same issue, but no one else on our team does.
Thanks!!! The issue still persisted in version 0.50.4. I finally resolved it by deleting all state.vscdb* files. The only downside is that all my configurations and plugins need to be set up from scratch again.
This just became an issue for me out of nowhere, and seemingly after an update that I just made to Cursor, is anyone else still having these issues? Iām a little nervous to try the solution offered by @zhonglimh
Okay, I fixed it by checking the inline terminal environment contributions. And I had seen that some Python plug-in was contributing to the environment.