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
- 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 valuedatabase
- Comments should be ignored when parsing the
.env
file
Actual Behavior
- Environment variable
CACHE_STORE
has the valuedatabase # 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
- The stored value persists even when the
-
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
- Despite clearing cache directories in
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.
I canât continue using Cursor on this project until itâs fixed