How to Prevent Cursor AI from Breaking or Overwriting Older Features in Large Projects?

Hi everyone,

I’m currently working on a complex project using Cursor AI, and I’ve encountered a recurring issue as the project grows in size and complexity.

As the scope of the project expands, Cursor AI often starts making changes or implementing new features that inadvertently break or overwrite older, already functional parts of the code. I suspect this might be due to the limited context window of the AI, which prevents it from retaining or fully understanding the broader scope of the project when working on individual tasks.

For example:

  • It might introduce a new feature but inadvertently modify or remove a related, pre-existing function, leading to regressions.
  • It sometimes overlooks dependencies or context from other parts of the project, leading to inconsistencies.

This makes it challenging to maintain a stable, scalable codebase as the project evolves.

I’m curious:

  1. Is there a best practice or workflow for mitigating this issue? (e.g., modularizing code, improving prompt engineering, or using external context managers?)
  2. Are there tools or techniques to “extend” the memory of Cursor AI or ensure it respects existing code more effectively when making changes?
  3. Has anyone else faced this problem, and if so, how did you address it?

Ideally, I’d like to let the AI operate as autonomously as possible without needing to constantly babysit or review every change it makes. Any advice, tips, or workarounds would be greatly appreciated!

Thank you in advance for your help!

2 Likes

yes, I have the same concern. My solution is to use Git and commit multiple times to prevent destructive updates to my code

It’s actually not cursor but models, I’ve experienced that with all AI assistants and even with coding via chat GPT directly by posting a code.

There are 2 things:

  1. When applying, check the code very thoroughly, you can choose what to apply and what not. This what I like in cursor - less chances for error to appear or slip through.

  2. You can customize rules for AI in the cursor settings, I have multiple customization but to minimize inadvertent changes I use:

Do not change any other methods or anything in the files I sent unless it's absolutely necessary for what I ask for to work. 
Do not do refactoring of code unless I explicitly ask to do it.
Do not fix style in the existing code unless I ask for that. 
Do not add or remove new lines in the end of the code (i.e. leave it as is either with or without). 
Do not remove existing comments unless I explicitly ask for it or we're removing that code completely.

Note that it’s “not a robot” and it won’t always follow the instructions precisely, but for me it reduces “accidental” changes to the point that’s OK for me. If it’s not enough for you - I suggest to elaborate on points. Like to add “Do not change any files or classes or methods outside what we work on unless I explicitly ask to change multiple files” - or something like that, I noticed that it response well on repetative instrucitons written in different words or from different angle.
Or something like “If you change other method or file than we work on - explain in details why did you do this change”

I was annoyed that it was keep sending me back whole files content where only one line was changed, so I have to repeat like 7-8 times not to do it with examples for it to start sending me only related changes.

1 Like