← All tips

Tip & trick / Cursor / AI tools / Git

Cursor Agent changes unrelated files: limit scope and review the diff

Stop a small bug fix from becoming a refactor with a file allowlist, a focused prompt, and a review of tracked and new files.

You ask Cursor to fix a double-submit bug. The patch also rewrites navigation, changes dependencies, and formats half the repository. Reviewing those extra edits takes longer than the original fix.

Users reported unrelated changes in July and August 2026. Those reports establish the symptom, not its frequency or the behavior of every current version. The workflow below gives you a way to spot unwanted edits even when the agent ignores an instruction.

Give the task a file boundary

Record the current working state before starting:

sh
git status --short
git diff HEAD

Keep existing work separate from the agent's patch. If the tree is already dirty, save a recoverable baseline using your normal Git workflow; comparing everything with HEAD later will include those earlier edits too.

Attach the actual handler and its test. This example prompt uses illustrative checkout paths; substitute the files you inspected in your repository:

text
Fix one bug: two quick clicks on Pay send two create-order requests.
Expected: while a submission is pending, another click sends no request.
After a failed submission, the user must be able to retry.

Allowed edit files:
- src/checkout/submitOrder.ts
- src/checkout/submitOrder.test.ts

Read other files for context, but edit only these two. Preserve existing
behavior outside this bug. Do not reformat unrelated code, upgrade
dependencies, or change navigation or authentication.

Reproduce the bug with a failing test before editing the implementation.
Keep both the duplicate-click and retry-after-failure cases in that test.
Make the smallest fix, run the focused test, and review the final diff.
If another file needs editing, stop and explain why.
Report the actual commands and results, including checks you couldn't run.

The file boundary is a prompt instruction, not enforced write protection. Cursor recommends test-driven work and a fresh conversation when the agent keeps making the same mistakes. If a long chat has drifted, start a new one with the current files, reproduction, and scope rather than repeating corrections in the old thread.

Review files before accepting the fix

sh
git status --short
git diff --stat HEAD
git diff --name-only HEAD
git diff HEAD

git diff HEAD covers tracked changes, including staged edits. It omits the contents of untracked files; git status --short exposes those as ?? entries. Open any new files separately. Confirm every changed path belongs to the agreed task and that the test still checks the promised behavior.

If unexpected edits appear, stop the agent and inspect them before accepting or reverting anything. Restore only changes you have identified as unwanted; a blanket reset can erase work that existed before the session.

Sources checked October 4, 2026. This is a review workflow, not a guarantee that a prompt prevents scope drift.

End of note

← Back to tips

Search articles and tips

Search in