Environment Variable Parsing Bug in Cursor IDE

Issue Description

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

  1. 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
    
  2. Try to read the environment variable in your application
  3. 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

  1. 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
  2. Attempted to resolve by clearing cache directories in:
    • ~/Library/Application Support/Cursor/
    • Various cache subdirectories (Cache, CachedData, etc.)
  3. Checked configuration files:
    • config.json
    • settings.json
    • Workspace storage
  4. 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:

  1. Remove all inline comments from .env files
  2. Use a different IDE/editor
  3. 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:

  1. 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
  2. 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
  3. 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

Verification

You can verify this behavior by running:
bash

node -e "console.log('CACHE_STORE:', process.env.CACHE_STORE)"

This will show the environment variable including the comment text.

:no_entry_sign:I can’t continue using Cursor on this project until it’s fixed

2 Likes

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.

Cursor version: Version: 0.45.10

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!

This is VSCode bug and Cursor inherit this.

If we restart terminal we got updated envs from .env, although it is uncomfortable. Maybe Cursor can fix this without awaiting VSCode fix?

Hi,

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…

2 Likes

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.