Cursor Chat Reads the Wrong File

You @ one file and Cursor answers about a different same-named file. Fix the @-picker, stale index, and symlink causes with full-path references and a resync.

You type @utils.ts in chat and ask Cursor to explain formatDate. The answer is about code you don’t recognize — it read packages/admin/utils.ts instead of packages/web/utils.ts. Or, weirder: it talks about a function you deleted three days ago. This is almost never hallucination. Either the @ picker landed on the wrong same-named file, the semantic index lags what’s actually on disk, or a symlink made Cursor treat two paths as one.

Fastest fix (90% of cases): delete the @-pill, retype the reference with its full path (@packages/web/utils.ts, not @utils.ts), and add one line to your prompt asking the model to echo the path it’s reading before it answers. If it still serves stale content after a rename or delete, force a resync from Cursor Settings → Indexing. The rest of this guide covers the six buckets this falls into and how to make the fix stick.

Verified against Cursor’s indexing and ignore-file behavior as of June 2026.

Which bucket are you in?

Symptom in the replyMost likely causeJump to
Right function name, wrong package/path@ picker stored a different same-named fileCause 1
Talks about code you renamed or deletedIndex lags disk after git mv / git rmCause 2
Two paths “are the same file”Symlinked directoryCause 3
@-pill is greyed / “missing”Stale attachment in an old chatCause 4
Explains test data, not real logicFixture shares the source filenameCause 5
Works on your Mac, wrong on Linux CICase-sensitivity driftCause 6

Common causes

1. Multiple same-named files; @ picker landed on the wrong one

index.ts, types.ts, utils.ts, config.ts appear dozens of times in monorepos. @ autocomplete sorts by similarity; you clicked the second item but it stored the first path.

How to judge:

fd "utils.ts" .             # or find . -name "utils.ts" -not -path "*/node_modules/*"

More than one line → ambiguity.

2. Index stale — referencing renamed / deleted file

You ran git mv old.ts new.ts or git rm old.ts; the index hasn’t refreshed. Cursor still serves the old file from cached index.

How to judge: open Cursor Settings → Indexing (newer builds renamed this from Features → Codebase Indexing). Check the file count and indexing status. If the count predates your rename, or the status hasn’t moved since you changed files on disk, the index is stale.

packages/shared symlinks to ../shared. Cursor may store both paths but read by symlink target, mismatching what you @-ed.

How to judge:

find . -type l -not -path "*/node_modules/*"

4. Old chat references a stale attachment

An older chat @-ed a file whose path is no longer valid. Continuing the same chat, Cursor tries to read the stale path and ends up on cache or a same-named file.

How to judge: the @-pill in the context panel is greyed or marked “missing.”

5. Test fixture has the same name as source

src/parser.ts and src/__tests__/fixtures/parser.ts. Retrieval ranks the fixture higher and the model explains fixture logic.

How to judge: context panel shows files under fixtures/ or __tests__/ with the target name.

6. Case-sensitivity drift (macOS vs Linux)

APFS on macOS is case-insensitive by default; User.ts and user.ts are one file on macOS, two on Linux CI. Cursor indexes by OS behavior, confusing cross-machine collaboration.

How to judge: fd -i "user.ts" . (ignore case) — multiple hits.

Before you start

  • Identify the entry point: chat / Composer (Agent) / Cmd+K inline edit. Cmd+K binds to the cursor position and won’t pick a wrong file, so if the bug only shows in chat/Composer, it’s a retrieval or @-picker problem, not the editor.
  • Commit before reproducing so rename / unlink changes stay tracked.
  • Note Cursor version (Help → About), active model, whether you’re in a monorepo or a multi-root workspace.

Info to collect

  • File you @-ed + what the model’s reply references.
  • fd <filename> . output (every same-named file).
  • Cursor Settings → Indexing — file count and indexing status.
  • Screenshot of the Composer / chat context panel — which path did it actually load?

Shortest fix path

“Disambiguate now → systemic cleanup.”

Step 1: Remove old @, re-attach with full path

Delete the @-pill, retype:

@packages/web/utils.ts

So @ resolves the full path rather than just the filename. Still ambiguous? Go deeper:

@packages/web/src/utils.ts  (not @utils.ts)

In a monorepo, scoping the search first also helps: use @folder (for example @packages/web) to limit retrieval to one package before you @ the file, instead of letting @codebase rank every same-named file across the repo.

Step 2: Spell it out in the prompt

I'm asking about the formatDate function in packages/web/utils.ts (NOT any other utils.ts in this repo).
Please confirm the file path you're reading before answering.

Make the model echo the path; you catch mistakes immediately.

Step 3: Force a resync of the index

The reliable trigger is the button in settings, not a keyboard shortcut. Open Cursor Settings → Indexing and click the resync/reindex control (older builds labeled this section Features → Codebase Indexing). For a full rebuild after a large structural change (mass rename, branch switch, big merge), the command palette equivalents are Cmd+Shift+P → Reindex Codebase and Reindex Codebase (Rebuild).

Note: the old Cursor: Resync Index command name has been folded into the settings panel in current builds, so search the palette by typing reindex if you don’t find it. A large repo (tens of thousands of files) can take several minutes to hours; semantic search is unavailable until indexing reaches roughly 80% complete, so wait for the status to finish before re-testing your prompt.

Step 4: Rename to disambiguate (most reliable)

If both same-named files have to coexist long-term, give one a unique name:

git mv packages/admin/utils.ts packages/admin/adminUtils.ts
# update imports
rg "from .*admin/utils" --files-with-matches | xargs sed -i '' 's|admin/utils|admin/adminUtils|g'

The model can’t mix them up anymore.

Step 5: Drop stale @s + start a fresh chat

Old chats carry dead @-pills. Open a new chat (Cmd+L resets), re-@, no stale context.

If a directory is symlinked and shows up as a duplicate path, exclude the symlinked copy from the index — but use the right ignore file. As of June 2026 the two behave differently:

  • .cursorindexingignore removes a path from semantic search only; you can still @-mention the file and the agent can still read it. This is what you want for a symlink duplicate: index the canonical path, hide the alias, keep both reachable.
  • .cursorignore blocks the path from search, Tab, Agent, Inline Edit, and @-mention references. Use it only if you never want the agent touching that path at all (secrets, build output).
# Hide the symlinked alias from the index but keep it @-mentionable
echo "packages/shared-link" >> .cursorindexingignore
# Better long-term: replace the symlink with native npm/pnpm/yarn workspaces

After editing either file, run Step 3 again so the index reflects the new exclusions.

How to confirm it’s fixed

  • After re-@, ask the model to echo the file path it loaded and confirm it matches the one you wanted.
  • Open the context panel and verify the single pill points to the full, correct path (no greyed/“missing” pills).
  • Take a unique string from the model’s answer and grep/rg it in the file you intended — it should be present there and absent from the same-named decoy.
  • For an index-staleness fix, re-run the same prompt after the resync status shows complete; the deleted/renamed reference should no longer appear.

If it still fails

  • Reduce the prompt to what's in this file? with exactly one fully-pathed @ and no other context.
  • Roll back the most recent rename or .cursorindexingignore / .cursorignore change in case it introduced a new collision.
  • Confirm the file isn’t accidentally in .cursorignore (which blocks @-mention entirely) when you meant .cursorindexingignore.
  • Search forum.cursor.com for “wrong file context”; include your fd output and a context-panel screenshot.
  • Grab View → Output → Cursor indexing logs and post them to the forum’s Bug Reports category.

Prevention

  • Give important files unique names; avoid bare utils.ts / types.ts / index.ts where you can.
  • Right after big renames or branch switches, resync from Cursor Settings → Indexing instead of waiting for auto-sync.
  • Always @ with a full path; build the muscle memory so you don’t pick the wrong row in the picker.
  • In monorepos, scope with @folder before reaching for @file.
  • Replace symlinks with native workspaces (npm / pnpm / yarn) so two paths never point at one file.
  • For cross-OS projects use a case-sensitive filesystem (macOS supports a case-sensitive APFS volume created in Disk Utility).

FAQ

Why does Cursor read a file I deleted days ago? The semantic index is a cached embedding of your codebase, not a live read of disk. After git rm or git mv it can keep serving the old content until it resyncs. Force a resync from Cursor Settings → Indexing, then re-ask.

Is this a hallucination? Usually not. Hallucination invents code that exists nowhere; this bug returns real code from the wrong same-named file or a stale index. If you can grep the model’s snippet in some file in your repo, it’s a retrieval/indexing problem, not a hallucination.

What’s the difference between .cursorignore and .cursorindexingignore? .cursorignore blocks a path from search, Tab, Agent, Inline Edit, and @-mention — the agent can’t reach it at all (the terminal and MCP tools are the exception). .cursorindexingignore only removes it from the index/search; you can still @-mention it and the agent can still read it on demand. For symlink duplicates, use .cursorindexingignore.

Does Cmd+K inline edit have this problem? No. Cmd+K binds to your current cursor position and file, so it edits exactly where you are. The wrong-file issue is specific to chat and Composer (Agent) retrieval and the @ picker.

How long should a reindex take? A small project resyncs in seconds. A large repo with tens of thousands of files can take several minutes to hours, and semantic search stays unavailable until indexing reaches roughly 80%. Watch the status in Cursor Settings → Indexing before re-testing.

Tags: #Troubleshooting #Cursor #Debug #Wrong edit