Cursor's .env File Recognition in Agent Mode

When using Cursor’s agent mode, I’ve observed that it doesn’t seem to recognize .env files. While I strongly agree with the principle of not exposing the contents of .env files to the agent for security reasons, this behavior presents a challenge when attempting to have the agent write code that interacts with these files.

Specifically, if I try to prompt the agent to write code that involves reading an .env file, Cursor often misinterprets this. It might assume the file path is incorrect or that the .env file hasn’t been created yet. This has led to undesirable actions, such as the agent autonomously modifying the README file, citing a lack of permissions to create the .env file.

My request is simple: I would greatly appreciate it if Cursor could be updated to recognize the existence and path of .env files without necessarily reading their contents. This would prevent the agent from making incorrect assumptions and taking unprompted actions, while still maintaining the crucial privacy of my environment variables.

hi @taiga-K and welcome to Cursor Forum.

Thank you for the feature request

Could you check the global ignore files in Cursor settings?

You can set which file shouldnt be ignored (env is there)

Hi there,

Thanks so much for the quick reply and for the welcome!

I appreciate you pointing out the global ignore files in Cursor settings. I’m actually quite familiar with .cursorignore and believe it’s an essential feature. I fully agree that .env files should be ignored, especially given the sensitive information they can contain.

My core concern isn’t about ignoring the contents of the .env file; it’s about Cursor completely ignoring the file’s existence when it’s set to ignore. My request is for Cursor to acknowledge that an .env file exists at a given path, without actually reading or processing its contents. This would help prevent the agent from making incorrect assumptions about missing files, while still respecting the privacy of my environment variables.

Yes thats understandable :slight_smile: I encountered the same behavior. Though the model doesnt seem to be trying harder to read it or write to it.

Thanks for the feature request, I will flag it for review with Cursor Team!

1 Like