How Do You Keep Files Out of Cursor With .cursorignore?
Create a .cursorignore file in your project root, using .gitignore syntax. Listed files are blocked from Agent, Tab and @ mentions. Cursor already ignores whatever is in .gitignore, plus a long default list that includes .env*, .git/, node_modules/, lock files and many binary types, so add only what's left.
# .cursorignore (gitignore syntax) # Generated or vendored code that isn't already in .gitignore generated/ vendor/ *.min.js coverage/ [your large data folder]/ # Secret-looking files beyond the default .env* /credentials.json /*.pem # Re-include something on the default list, such as a fixture !tests/fixtures/sample.csv
- Agent
- Tab
- @ mentions
- Terminal tools
- MCP tools
Try it now
- 1Create
.cursorignorein your project root and add one folder you never want quoted. - 2Type
@in the Agent input and start typing a file from that folder. It should no longer appear. - 3Test a tricky pattern in a terminal with
git check-ignore -v [file], which Cursor's docs recommend. It worked if the file is hidden and Agent can no longer read it.
Use it when
Large generated files, build output not already in .gitignore, vendored code, big data files, and folders in a monorepo that have nothing to do with your work. Add secret-looking paths too, as a layer rather than your only defense.
Skip it when
Don't list files that Agent needs to read to do its job, such as generated API types it should import from. Don't rely on it to protect production secrets either. Keep those off the machine or out of the repo, and use Run Modes and the sandbox to control commands.
Why it works
Fewer irrelevant files mean more accurate file discovery, which is the performance reason Cursor gives. Excluding generated types or a vendored library means they can't be quoted as if you wrote them. The other reason is security, with a limit. Cursor's docs say complete protection isn't guaranteed due to LLM unpredictability, and that terminal and MCP tools used by Agent can't be blocked by this file. An agent can still run a command that reads an ignored file.
Example
Say a 40,000-line generated GraphQL types file keeps appearing in answers. You add src/generated/ to .cursorignore. Then you notice Agent isn't picking up docs/spec.pdf or tests/data.csv. That fits the default ignore list, which includes *.pdf and *.csv. If it needs that CSV, add !tests/data.csv, since the ! prefix is how you re-include a file.
Going further
Negation has a limit: you can't re-include a file if a parent directory is excluded, because excluded directories aren't traversed. With public/*, !public/assets/style.css fails, so also add public/assets/* first. For patterns across every project, such as **/*.key, set global ignore patterns in user settings, which are empty by default. In a monorepo, turn on Cursor Settings > Indexing > Ignore Files > Hierarchical Cursor Ignore to also read parent folders' files. Old guides mention .cursorindexingignore, but the current ignore pages don't.
Common mistakes
- Treating it as a security boundary. Terminal and MCP tools aren't covered.
- Listing
node_modules/and.env, which are already ignored by default. - Hiding a file you'll later ask about, then wondering why Agent can't find it. Cursor's troubleshooting page lists this first.
- Adding a
!line under an excluded parent folder, which has no effect.
Sources
- Ignore file, Cursor Docs
- Ignore files, Cursor Help
- Agent troubleshooting, Cursor Help
- Run Modes, Cursor Docs
Checked 6 November 2026. Products change often, so confirm details with the vendor.