Ignore files (.cursorignore)

Cursor · Advanced · 10 min

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 like cat config/secrets.yml can 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 file

Remember

  • .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 cat them through the terminal.

Check yourself

  1. A file is listed in .cursorignore. Which can still read it?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: cursor.com/docs/reference/ignore-file