You ask Cursor to fix a React component, and it cites prop names from dist/components/Foo.js (the compiled old version), producing a patch that’s totally wrong. Or you ask “how do we implement rate limiting?” and it answers from vendor/express-rate-limit/ rather than your own middleware. In both cases Cursor pulled the wrong files into context: build output, vendored third-party code, backup files, generated artifacts.
Fastest fix: add the contaminating folders to a root .cursorignore, run Reindex Codebase from the Command Palette, then re-ask your question while pinning the real source with @File / @Folder. The rest of this article diagnoses which bucket you’re in and locks Cursor to your actual code for good.
Which bucket are you in?
Open the contributing files under your last reply (expand the context chips shown above the answer, or run the verification prompt in Step 5) and match what you see:
| What shows up in context | Bucket | Primary fix |
|---|---|---|
dist/, build/, .next/, out/, .astro/, coverage/ | Generated files indexed | .cursorignore build dirs + reindex |
vendor/, public/vendor/, third_party/, a big *.min.js | Vendored libraries dominate retrieval | .cursorignore vendored paths + reindex |
.env.local, scratch.md, old-backup-2024.tsx (untracked) | No .cursorignore, only .gitignore | Create .cursorignore (gitignore is not enough) |
Foo.tsx.orig, Foo.tsx~, Foo-old.tsx | Backup / merge-conflict leftovers | Delete the junk + ignore the patterns |
__snapshots__/, *.snap, fixtures/, mocks/ | Test artifacts steal context | .cursorindexingignore (keep @-mentionable) |
Common causes
Ordered by frequency, highest first.
1. Generated files live next to source
dist/, build/, .next/, coverage/ aren’t ignored, so Cursor indexes them. Compiled JS often beats the real src/ files in embedding retrieval because it shares keywords with the source.
How to spot it: open the context chips above Cursor’s reply. Any of dist/, build/, .next/, out/, .astro/ showing up is a hit.
2. Vendored third-party libraries in the repo
Old Node / PHP projects commit vendor/ directly; frontends sometimes ship public/vendor/jquery-3.5.1.min.js. These are large and dominate retrieval, crowding out real code.
How to spot it: du -sh vendor/ public/vendor/ third_party/ 2>/dev/null. Any indexed directory larger than 5MB is suspect.
3. No .cursorignore at all
People assume .gitignore is enough. Cursor does honor .gitignore plus a built-in default ignore list, but neither covers local-only files that were never committed: .env.local, scratch.md, old-backup-2024.tsx. Cursor sees and indexes them.
How to spot it: at repo root, ls -la | grep -E "(scratch|backup|old|\.bak|\.orig)". Anything that’s not in .cursorignore is a potential contaminant.
4. Backup and .bak / .orig files
Merge-conflict leftovers like Foo.tsx.orig, editor autosaves like Foo.tsx~, or hand-copied Foo-old.tsx. They differ from the current version by a few lines, so embeddings rank them as highly relevant and the agent ports old logic back in.
How to spot it: find . -type f \( -name "*.orig" -o -name "*.bak" -o -name "*~" -o -name "*-old.*" \) | head -20.
5. Test fixtures / snapshots steal context
__snapshots__/, fixtures/, mocks/ are often “semantically similar but behaviorally different” from real code. When you edit business logic, the agent treats snapshot strings as source of truth.
How to spot it: the context chips show __snapshots__ or .snap files when your prompt has nothing to do with tests.
Shortest path to fix
Step 1: Build a .cursorignore that blocks the usual contaminants
At repo root, create or expand .cursorignore. The syntax is gitignore-style (*, **, ?, ! negation, # comments):
# Build output
dist/
build/
out/
.next/
.astro/
.svelte-kit/
.nuxt/
# Dependencies and vendored
node_modules/
vendor/
public/vendor/
third_party/
# Caches, coverage, logs
.cache/
.turbo/
.parcel-cache/
coverage/
*.log
# Backups and editor temp
*.bak
*.orig
*~
*-old.*
*.swp
# Minified / bundled
*.min.js
*.min.css
*.bundle.js
*.bundle.css
# Local scratch
scratch.md
TODO.local.md
Tune per stack; the rule is “if the AI would be misled or wasted on it, hide it.”
One caveat worth knowing (per Cursor’s docs as of June 2026): .cursorignore blocks the file from semantic search, Tab, Agent, Inline Edit, and @-mention references, but the terminal and MCP server tools the Agent runs can still touch those paths. So .cursorignore controls what the model reads, not what a shell command can see.
Step 1b: Use .cursorindexingignore for files you still want to @-mention
.cursorignore is a hard block. For test fixtures, large snapshots, or generated docs that you occasionally do want to pull in by hand, use .cursorindexingignore instead. It removes the files from the codebase index (so they stop polluting automatic retrieval) but keeps them readable when you explicitly @File them.
# Drop from the index, but keep @-mentionable
**/__snapshots__/
**/*.snap
fixtures/
mocks/
Rule of thumb: .cursorignore for “never read this,” .cursorindexingignore for “stop auto-pulling this, but let me reference it on demand.”
Step 2: Force Cursor to rebuild the index
Changes to either ignore file don’t take effect until you re-index. The reliable trigger is the Command Palette:
Cmd+Shift+P (macOS) / Ctrl+Shift+P (Windows/Linux)
→ "Reindex Codebase"
You can also do it from Cursor Settings → Indexing (the indexing controls moved out of the old Features page). To confirm what survived the cleanup, open Cursor Settings → Indexing & Docs → View included files: the contaminating directories should no longer be listed.
For a hard reset when the index seems stuck, quit Cursor and delete the per-workspace index cache, then relaunch:
# Quit Cursor first, then:
rm -rf ~/Library/Application\ Support/Cursor/User/workspaceStorage/*/cursorIndex
# Relaunch Cursor; it re-indexes from scratch
Note that Cursor only auto-reindexes changed files on a roughly 10-minute polling cycle (via a Merkle-tree diff), so after editing ignore files a manual reindex is the only way to apply them immediately.
Step 3: Pin source of truth with @File / @Folder in the prompt
Even with a clean ignore list, long chats occasionally mis-retrieve. The safest move is to pin explicitly:
@Folder src/components/auth @File src/lib/auth.ts
Modify AuthForm's onSubmit. Read and edit only the files I @-ed.
Do not reference anything in dist/, build/, or any *.min.js.
Adding a negative constraint (“don’t reference X”) is usually more effective than positive constraints alone. Only @-mention files you’re sure are relevant; tagging extra files dilutes what the agent treats as important.
Step 4: Sweep the repo’s “archaeology” periodically
Once a month (or in a pre-commit hook), run a cleanup pass:
# List anything the agent might mis-read
find . -type f \( \
-name "*.bak" -o -name "*.orig" -o -name "*~" \
-o -name "*-old.*" -o -name "*-backup.*" \
-o -name "*.swp" \
\) -not -path "./node_modules/*" -not -path "./.git/*"
# Confirm they're junk, then delete
find . -type f \( -name "*.bak" -o -name "*.orig" -o -name "*~" \) \
-not -path "./node_modules/*" -delete
After every merge conflict, run git status to catch new .orig files and delete them immediately.
Step 5: Verify the agent reads only the right files
Have Cursor list what it just read:
List every file you read to answer my last prompt, full paths, in
the order you read them. Exclude dist / vendor / *.min.js. If any
of those appear, tell me which @ pulled them in.
How to confirm it’s fixed
You’re done when all three hold:
Cursor Settings → Indexing & Docs → View included filesno longer lists any path from the buckets above.- The context chips on a fresh reply contain only files under
src/(or your real source root). - The Step 5 verification prompt returns clean paths. If dirty paths still appear, the ignore list is incomplete: note which directory leaked and add it back in Step 1, then reindex again.
FAQ
Why does Cursor still read a file I put in .cursorignore?
Two common reasons. First, you didn’t reindex: .cursorignore changes only apply after a Reindex Codebase. Second, the file was reached through a terminal command or MCP tool rather than the model’s own retrieval. .cursorignore blocks reading, Tab, Agent, Inline Edit, and @-mentions, but it cannot stop a shell command the Agent runs from listing or catting that path.
.cursorignore vs .cursorindexingignore: which one do I use?
Use .cursorignore for files the AI should never read (secrets, build artifacts, vendored code). Use .cursorindexingignore for files you want out of automatic search but still want to reference by hand with @File (test fixtures, big snapshots). About 90% of repos only need .cursorignore.
Do I still need .cursorignore if I already have a .gitignore?
Yes. Cursor honors .gitignore plus a default ignore list, so committed build output is usually skipped already. But untracked local files (.env.local, scratch.md, hand-made backups) are not in .gitignore, so only .cursorignore keeps them out of context.
The “Reindex Codebase” command isn’t doing anything. What now?
Quit Cursor, delete the workspace index cache (Step 2’s rm -rf line on macOS; the equivalent under %APPDATA%\Cursor on Windows), and relaunch. Cursor rebuilds from scratch. Also check Cursor Settings → Indexing to confirm indexing is enabled for the repo.
Can I stop this from coming back automatically?
Yes. Commit .cursorignore with the repo, keep build output and vendored code in dedicated top-level directories, and delete .orig files right after every merge. See Prevention below.
Prevention
- Commit
.cursorignorewhen you create a new repo, and keep it aligned with your.gitignorepatterns. - Always put build output (
dist/,build/,coverage/) in dedicated top-level directories, never scattered undersrc/. - Put vendored third-party code under
third_party/and add it to.cursorignore; never dump it in the repo root orpublic/. - After resolving merge conflicts, run
find . -name "*.orig" -deleteimmediately to prevent index pollution. - Add a line to
.cursorrules/CLAUDE.md: “Treat dist/, build/, vendor/, and .min. as build artifacts. Never read them.”
Related
- Cursor missed the full project context
- Cursor stuck indexing
- Multiple AI agents created conflicts
- AI pre-commit review workflow
- AI dependency upgrade workflow
External references: Cursor: Ignore Files and Cursor: Codebase Indexing.