Cursor Chat Reads the Wrong File

You @ one file and Cursor answers about a different same-named file — ambiguity, stale index, or symlink confusion.

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. Usually not hallucination — either the @ picker landed on the wrong same-named file, the index lags reality, or a symlink made Cursor think two paths are one.

Fix by disambiguating + forcing a reindex.

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: Settings → Features → Codebase Indexing → “Last indexed” — older than your rename = 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 / Cmd+K. Cmd+K binds to cursor position and won’t pick the wrong file.
  • Commit before reproducing so rename / unlink changes stay tracked.
  • Note Cursor version, active model, whether you’re in a monorepo.

Info to collect

  • File you @-ed + what the model’s reply references.
  • fd <filename> . output (every same-named file).
  • Settings → Features → Codebase Indexing → “Last indexed.”
  • Screenshot of 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 @ uses the full path rather than just filename. Still ambiguous? Go deeper:

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

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: Trigger reindex

Cmd+Shift+P → “Cursor: Resync Index.” Wait 5-30 minutes. For just a file or two:

Cmd+Shift+P → "Cursor: Reindex Current File"

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 creates duplicates:

echo "packages/shared-link" >> .cursorignore
# Or move to native npm/pnpm workspaces, not symlinks

How to verify the fix

  • After re-@, have the model echo the file path — verify it’s the one you wanted.
  • Repro the same prompt on a different machine with the synced repo — confirms it’s a path-layer fix.
  • The code snippets in the model’s answer can be grep-ed in the file you intended.

If it still fails

  • Reduce prompt to “what’s in this file?” with one fully-pathed @.
  • Roll back the most recent rename / .cursorignore change.
  • Search forum.cursor.com for “wrong file context”; include fd output + screenshots.
  • Grab View → Output → Cursor indexing logs and post to Bug Reports.

Prevention

  • Give important files unique names; avoid utils.ts / types.ts / index.ts.
  • Right after big renames, run Cmd+Shift+P → Resync Index — don’t wait.
  • Always @ with a full path; build muscle memory so you don’t pick the wrong row.
  • Replace symlinks with native workspaces (npm / pnpm / yarn).
  • For cross-OS projects use a case-sensitive filesystem (macOS supports a case-sensitive APFS volume).

Tags: #Troubleshooting #Cursor #Debug #Wrong edit