Codebase indexing

Cursor · Practical · 10 min

A healthy index is what lets the agent find the right code in a large project without you pointing at every file.

When you open a project, Cursor scans and indexes your source files. Indexing turns chunks of code into embeddings, numeric fingerprints of meaning, so the agent can run semantic search: "where do we check user permissions?" finds the right functions even if they never use the word "permissions". Ordinary text search still exists too; the agent uses both.

Practical details:

  • Indexing runs automatically on open and then re-syncs periodically (roughly every five minutes) to pick up changes.
  • The status bar shows progress while a scan runs; until the first index finishes, search results are weaker.
  • To rebuild from scratch, open the Command Palette and run Reindex. Do this if search seems to miss code that clearly exists, for example after a huge refactor or branch switch.

What gets indexed matters. Files in your .gitignore (like node_modules or dist) are excluded, plus a built-in list of things such as lock files and binaries. Add large generated files, vendored code or data dumps to .cursorignore so they don't slow indexing or pollute results. A later lesson covers ignore files and what they do and don't protect.

How this helps your prompts: with a good index you can describe behavior instead of locations, "fix the bug where archived projects still appear in search", and Agent will find candidates. In a very large or unfamiliar repo, still point at an example file or folder when you can; semantic search narrows things down, but it can surface similar-looking code from the wrong module.

Remember

  • Indexing enables meaning-based search across your codebase
  • It runs on open and re-syncs periodically; run Reindex if results look stale
  • Exclude generated and vendored files with .gitignore or .cursorignore

Watch out for

  • Letting huge generated files or data dumps get indexed, which slows indexing and pollutes search results.

Check yourself

  1. Agent can't find a function you know exists after a large refactor. What's a sensible first step?

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

Official docs: cursor.com/help/customization/indexing