Cursor·Fixpromptingintermediate

Cursor Breaking Working Code When Adding Features

Quick Answer

Cursor sometimes 'improves' existing code while making requested changes. Without git commits, you can't easily revert. Start with "Commit before every AI edit" before making broader code changes.

You're in the right place if...

  • !Working feature broke after adding a new one
  • !Cursor refactored code that didn't need it
  • !Tests now fail

Why this happens

Cursor sometimes 'improves' existing code while making requested changes. Without git commits, you can't easily revert.

Fix

1

Commit before every AI edit

Always create a safe restore point:

git add -A && git commit -m 'save before AI changes'
2

Add constraints to your prompt

Prevent unwanted refactoring:

Add [feature] to [file].

CONSTRAINTS:
- Do not modify any existing functions
- Do not change existing component props
- Do not alter existing styling
- Only add new code, never remove working code
- If you need to refactor, ask me first

Prevent this next time

Git commit before every Cursor prompt. Three seconds to commit saves hours of debugging.

Frequently Asked Questions

git checkout -- . reverts all uncommitted changes. Or Cmd+Z in each file.

Yes. It takes 3 seconds and gives you a guaranteed restore point.

Related fixes

Weekly Newsletter

Get next week's fix before you need it.

Join developers getting weekly vibe coding tips, error fixes, and tool updates.

Subscribe on Substack →