.cursorignore Not Working? Why node_modules Still Shows Up in Cursor
Last verified: 2026-11-16 · Cursor 3.23.x · git 2.47.3
node_modules/ is already on Cursor's default ignore list, so adding it to .cursorignore does nothing. If it still shows, the cause is a stale index, the git-only Instant Grep index, a shell tool, or a ! pattern blocked by an excluded parent.
You added node_modules/ to .cursorignore, reloaded, asked the agent about a component, and it answered with the internals of a dependency. Nothing looks wrong with the file. That is the problem: .cursorignore is not one switch but five paths through Cursor, and only some of them read that file.
Order matters here.
1. You probably did not need the line at all
Cursor's ignore reference lists node_modules/, .env*, .git/ and every lock file under Files ignored by default, and says those are ignored “in addition to files in your .gitignore and .cursorignore.” The help page repeats it: Cursor “already ignores .env files, .git/, and lock files by default.”
So a node_modules/ line is a no-op, and any page selling you that line as the fix is describing an older Cursor. If the folder still reaches the model, the ignore file is not the lever.
2. git check-ignore -v — and the blind spot nobody mentions
The docs' own troubleshooting line is git check-ignore -v [file]. Run it on a real file inside the folder, not on the folder name:
$ git check-ignore -v node_modules/pkg/index.js
.gitignore:1:node_modules/ node_modules/pkg/index.js
That output is real (git 2.47.3, a scratch repo with node_modules/ in .gitignore and !node_modules/pkg/index.js in .cursorignore). Read the left column: it names .gitignore. The command never reads .cursorignore, so your negating line cannot appear there and the file stays ignored. “check-ignore says ignored” is not evidence that .cursorignore failed.
3. The negation that quietly eats your ! lines
Cursor uses gitignore syntax, which means it inherits gitignore's cruellest rule: you cannot re-include a file whose parent directory is excluded, and excluded directories are never traversed. Two patterns, one character apart, behave in opposite ways:
# .gitignore
dist/*
!dist/app.min.js -> .gitignore:2:!dist/app.min.js dist/app.min.js works
!dist/sub/keep.js -> .gitignore:1:dist/* dist/sub/keep.js never matches
# .gitignore
dist/
!dist/sub/keep.js -> .gitignore:1:dist/ dist/sub/keep.js never matches
Both failures are the same trap, and Cursor documents it as “Negation pattern limitations” with the same public/* example. Exclude the nested directory explicitly (dist/sub/*) instead of rescuing one file from inside an excluded tree. A ! line pointing deeper than one level into an excluded folder was never going to apply.
A dependency folder is not a directory you prune. It is a warehouse the indexer still has to decide about.
4. The one that is genuinely broken: Instant Grep
If your case is “keep a gitignored folder out of version control but readable by the agent,” this is not your config. In the Cursor tracker, thread Index Repositories for Instant Grep — .cursorignore regression (opened 2026-08-19 on 3.15.19) reports that !testfile in .cursorignore does not restore a file that .gitignore excludes, and the agent's Grep and Glob tools miss it.
Cursor staff confirmed it a day later: “this isn't intended behavior… when ‘Index Repositories for Instant Grep’ is enabled, the indexing path doesn't respect it yet.” The October reply gives the reason: “the Instant Grep index is built from files that git can see.” A file git cannot see never enters the index, so no negation brings it back. No ETA as of 2026-10-11.
Two workarounds are on record: turn off Index Repositories for Instant Grep and reload the window, or add that folder as a separate workspace folder. A third route was reported working in the same thread — an allowlist .cursorignore (*, then !*/, then per-extension allows, then **/node_modules/ denials) — because it narrows inside the git-visible tree instead of pulling files out of git's blind spot.
5. A shell reads the folder anyway
One sentence in the reference decides half of these reports: “The terminal and MCP server tools used by Agent cannot block access to code governed by .cursorignore.” The same page says the blocks apply to Agent and Tab code access and to @ mentions, “complete protection isn't guaranteed due to LLM unpredictability.”
If the transcript shows rg, grep, find or cat, the ignore file was never in the path. Treat it as context hygiene, not a secret boundary, and read the tool call before you touch the pattern.
6. Two settings that decide whether the file is read
In a monorepo, a .cursorignore one directory above the folder you opened is only found when Settings → Indexing → Ignore Files → Hierarchical Cursor Ignore is on. Keep secrets in the global ignore list, which covers every project. And if the folder is still listed under a correct pattern, force a rebuild from the Command Palette before blaming the pattern.
Check your own repo in five lines
git check-ignore -v node_modules/pkg/index.js # which .gitignore rule catches it
git ls-files node_modules | head -3 # empty = git-invisible = index-invisible
grep -n node_modules .cursorignore .gitignore # is the line even needed?
git config --get core.ignorecase # pattern case sensitivity
rg --files-with-matches foo node_modules | head -3 # what a shell tool can still see
The last two lines change verdicts. If rg finds the file, your ignore configuration is fine and the agent is simply allowed to shell out — the same distinction behind why Cursor AI stops reading your local codebase.
- More IDE and CLI fixes in the Developer label.
- Token and API cost calculator to price what a bloated context actually costs.
- Every article by topic, newest first.
Comments
Post a Comment