Why Does Cursor Edit the Wrong File, and How Do You Stop It?
Agent takes your request literally, and where you give no intent, it uses its best judgment. A wrong edit usually means it had to guess the file, the pattern or the limit. Fix it by naming the target with @, pointing to one example, and saying what not to touch.
Scope for this change: Change only: @[file 1] @[file 2] Follow the pattern in: @[reference file] Don't touch: [folder or file] Task: [the change] Before editing, tell me which files you'll change and why. If you think another file is involved, name it and ask first.
- Picks a similar file
- Invents a pattern
- Edits more than asked
- Right file
- Your pattern
- A small diff
Try it now
- 1Find a recent chat where Agent changed something you didn't expect, and restore its checkpoint.
- 2Resend the request using the template above, with explicit
@mentions. - 3Compare the diffs. It worked if the new diff is confined to the files you named, and if any extra file it wanted comes up as a question.
Use it when
Look for this whenever Agent edits something unexpected, invents a helper that already exists, or produces a diff far larger than the request. Before you change models, first check whether your request actually said which file you meant.
Skip it when
This isn't the cause every time. If Agent can't see a file at all, check .cursorignore and .gitignore first. If it's forgetting constraints late in a long session, the cause is the context window, and a fresh chat helps more than extra @ mentions.
Why it works
Agent decides what to read through its own search, so a vague request leads it to the most plausible match, which may not be yours. Two files with similar names are enough to do it. Cursor's course also calls scope creep one of the most common failures, where the agent makes unrelated changes after being asked for too much at once. The accuracy list on Cursor's troubleshooting page is mostly about context: be specific, use Plan mode for broad tasks, start a new chat when switching, add rules, and use @.
Example
Say a monorepo has apps/web/config.ts and apps/api/config.ts. You ask to "raise the upload limit in config", and it changes the web one, when the limit is enforced by the API. Asking again with @apps/api/config.ts and "don't touch apps/web" gets the right edit. A one-line rule like "The upload limit lives in the API config" stops it recurring.
Going further
When the same wrong guess recurs, stop fixing prompts and fix the setup. Write the correction as a rule, with a glob if it applies to one area. Exclude generated copies with .cursorignore so they stop competing with the originals. For wide requests, use Plan mode so you see the file list before anything changes. And note that a mention is a focus, not a fence, so if you truly mean "only these files", say so in words.
Common mistakes
- Changing to a costlier model when the real problem is a vague request.
- Assuming Agent knows which
config.tsyou mean. - Asking for three unrelated things in one prompt, then trying to untangle the diff.
- Correcting the same wrong guess in every chat rather than adding a rule.
Sources
- Understanding your codebase, Cursor Learn
- Working with agents, Cursor Learn
- Agent troubleshooting, Cursor Help
- Prompting agents, Cursor Docs
- Rules, Cursor Docs
Checked 6 November 2026. Products change often, so confirm details with the vendor.