Secrets and irrelevant files shouldn't end up in prompts; ignore files are the first layer, not the only one.
A .cursorignore file in the project root lists files Cursor's AI features should not use. It uses the same pattern syntax as .gitignore:
*matches within a path segment,**across folders,?one character,!re-includes something an earlier pattern excluded,#starts a comment.
Ignored files are blocked from Agent, Tab and Inline Edit, and can't be pulled in with @-mentions. Cursor already ignores everything in your .gitignore plus a built-in list (environment files, lock files, dependency and build folders, logs, binaries, media and archives); a ! pattern in .cursorignore can override those defaults. You can also set a global ignore list in user settings that applies to all projects, a good home for patterns like *.pem, .env* and credential files. An optional Hierarchical Cursor Ignore setting makes Cursor also respect .cursorignore files in parent folders.
The important limits:
- The agent's terminal and MCP tools can't be blocked by
.cursorignore. A command likecat config/secrets.ymlcan still read an ignored file. - Cursor itself says complete protection isn't guaranteed because model behavior is unpredictable.
So treat it as one layer. Keep real secrets out of the repository (use a secrets manager or environment variables), protect them with run-mode settings and sandboxing, and don't paste them into chat.
Ignoring also improves quality: large generated files, fixtures and vendored code waste index space and context. To debug a pattern, git check-ignore -v <file> tests gitignore-style rules.
Example
# .cursorignore (gitignore syntax)
# secrets and credentials
.env*
*.pem
config/secrets.*
# big generated or vendored stuff that only adds noise
src/generated/
vendor/
fixtures/large/*.json
!fixtures/large/schema.json # re-include one small fileRemember
- .cursorignore uses gitignore syntax and blocks Agent, Tab, Inline Edit and @-mentions
- .gitignore and a built-in list are ignored by default; add a global list for secrets
- Terminal and MCP tools can still reach ignored files; it's not a guarantee
Watch out for
- Assuming .cursorignore keeps secrets safe while the agent can still
catthem through the terminal.