Add a .cursorignore So Cursor Stops Indexing Your node_modules

10-30% on context-heavy chats Beginner 1 min read

By default, Cursor indexes your whole workspace for features like @codebase and automatic context retrieval. If you haven't told it otherwise, that index can include node_modules, dist/, build/, .next/, minified bundles, lockfiles, and large fixtures. When Cursor retrieves "relevant" chunks to attach to a prompt, those files compete for slots, and a 40,000-token minified vendor bundle can crowd out the three source files you actually care about.

Before (no ignore file): you ask "where do we validate the login form?" Cursor's retrieval attaches a chunk from dist/bundle.min.js because it textually matches validate. You burn tokens on machine-generated gibberish and get a worse answer.

After: create a .cursorignore at the repo root:

node_modules/
dist/
build/
.next/
*.min.js
*.lock
package-lock.json
fixtures/large/

Now retrieval and @codebase only see real source. Same question, fewer attached tokens, sharper answer.

Why it saves tokens: Every chunk Cursor attaches to a request is billed as input tokens on each turn it stays in context. Minified and generated files are dense (few newlines, long lines) so they tokenize into a lot of tokens per kilobyte. Excluding them shrinks both the retrieval candidate pool and the payload actually sent to the model.

Two notes so you don't overdo it. First, .cursorignore blocks files from AI features and (in current versions) from being opened/edited by the agent, so don't ignore files you still want Cursor to touch. If you only want to exclude from indexing but keep them editable, use .cursorindexingignore instead. Second, Cursor already respects .gitignore, so often the win is just confirming your build artifacts are git-ignored. The explicit ignore file matters most for paths you commit (vendored code, generated clients, big JSON fixtures) that .gitignore doesn't cover.

Applies to: Cursor
Don't just read it — build the habit

Get a fresh tip every morning

You're reading a free Beginner tip. Pro unlocks all 38 advanced tactics and sends a new one daily — $9/mo, cancel anytime.