Workaround to lock parts of code?

It seems once my script hits 1500+lines the AI or the editing handler becomes stupid and frequently deletes entire parts of code by mistake.

I can see countless ask about locking part of code, but it’s not here yet. Do you guys use any workaround to protect code in any other way? I was thinking to section my script in different files as the AI rarely (if ever) suggests changes to multiple ones in one reply (without a follow up question).

Yeah, when working with large files, the AI in Cursor can sometimes act unpredictably. Breaking the code into smaller modules can really help: it reduces the chances of the AI accidentally modifying the code and makes the process easier to manage.

I’d also suggest using Git to ensure you can always roll back changes.

Adding comments to critical code sections, like // DO NOT EDIT, can help you manually track them. Additionally, you can define rules for the AI to ensure it never deletes marked code sections.