How to avoid Cursor modifying a given file

I have a config file with keys and what not, every now and then Cursor keeps deleting my keys, substituting it by “YOUR_API_KEY” and then it tells me to get my real API key instead so it can continue, it’s driving me nuts because it affects other things. It arbitrarily changes the variable names for my config thingies then the rest of the code doesn’t match and obviously it doesn’t work.

I can add a .cursorignore or .cursorindexingignore, however I DO want it to index the file, what I don’t want is the AI modifying it at all.

What’s the correct way to handle this? Thanks in advance

To add more info, I tried with the .cursorignore, however it caused a fetch issue (it again renamed a variable for no real reason), then it gets stuck in a loop because the AI thinks the issue is in the config file (it’s trying to import the wrong name) so yeah, in a loop we are. I would really love if it would index the file while not being able to edit it whatsoever

Hi @Archy and welcome to Cursor Forum.

From your description I would say thats not so easily possible since the gitignore, cursorignore and cursorindexingignore work more or less in the same way in your case.

Yes cursorignore prevents agent from accessing the file.

One option would be to make the file read only. Though the agent might still use the terminal to change file permissions.

Another would be to pass in the prompt / user rules / project rules a statement to not modify the environment file (use the real name of your file).
Yes the model may ignore that instruction too.

1 Like