Context

Codebase Indexing

Indexing Your Codebase

To get better and more accurate codebase answers using @codebase or Ctrl/⌘ Enter, you can index your codebase. In the background, Cursor computes embedding vectors for each file in your codebase and uses these vectors to improve the accuracy of codebase answers.

Your codebase index automatically stays in sync with the latest codebase changes.

You can check the status of your codebase indexing under Cursor Settings > Features > Codebase Indexing.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/chat/codebase-indexing.png

Advanced Settings

By default, Cursor indexes all files in your codebase.

You can also access more advanced options by expanding the Show Settings section. Here, you can decide whether to enable automatic indexing for new repositories and configure which files Cursor should ignore during repository indexing, in addition to .gitignore settings.

If you have large content files in your project that AI absolutely doesn't need to read, ignoring these files can improve answer accuracy.

AI Rules

You can add custom instructions for Cursor by modifying the Rules for AI section under Cursor Settings > General > Rules for AI.

These custom instructions will be used for features like Cursor Chat and Ctrl/⌘ K.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/rules-for-ai.png

.cursorrules

For project-specific instructions, you can include them in a .cursorrules file in your project's root directory.

Like the "Rules for AI" section, instructions in the .cursorrules file will be used for features like Cursor Chat and Ctrl/⌘ K.

@ Symbols

Basic Usage

In Cursor's AI input boxes, such as Cmd K, Chat, or Terminal Cmd K, you can use @ symbols by typing @. A popup menu with suggestions will appear, which automatically filters based on your input to show only the most relevant suggestions.

Keyboard Shortcuts

You can navigate through the suggestions list using the up/down arrow keys. You can select a suggestion by pressing Enter. If the suggestion is a category, like Files, the suggestions will be filtered to show only the most relevant items in that category.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@-symbols-basics.png

Cmd K Keyboard Shortcuts

You can navigate through the selected Cmd K @ symbols list using up/down arrow keys, and use Enter to expand/collapse selected context items. For file references, you can use Ctrl/⌘ M to toggle the file reading strategy. Read more about file reading strategies here.

@Files

@Files

In AI input boxes like Cursor Chat and Cmd K, you can use @Files to reference entire files. Additionally, if you continue typing after @, you'll see your file search results after the @Code strategy.

To ensure you're referencing the correct file, Cursor shows a preview of the file path. This is especially useful when you have multiple files with the same name in different folders.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@file.png

Long File References in Chat

In Cursor's chat, if the file content is too long, Cursor will break the file into smaller chunks and reorder them based on relevance to the query.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@file-long-file.png

Cmd K Chunking Strategy

For Cmd K, Cursor also uses file references differently based on content length.

  • auto
    • Automatically selects one of three reading strategies based on file size
  • full file
    • The entire file is used as context.
  • outline
    • Cursor parses the file's outline and uses the information as context.
  • chunks
    • Cursor breaks the file into smaller chunks and selects the most relevant one.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@file-cmdk.png

Drag and Drop

You can also drag and drop files from the main sidebar into Chat or Cmd K to add them as context.

@Folders

Currently, @Folders is only supported in Cursor Chat.

@Folders

You can also reference entire folders as context in Cursor. @Folders is particularly useful for long context chat where you want to provide the AI with a large amount of context.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@folder.png

@Code

@Code

To reference specific sections of code, you can use the @Code symbol.

Code Preview

Similar to the @Files symbol, Cursor shows a preview of the code content so you can verify you're referencing the correct code.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@code.png

From Editor

Another way to add code snippets as context is to select the code you want to reference and click "Add to Chat" (Ctrl/⌘ Shift L) or "Add to Edit" (Ctrl/⌘ Shift K).

These actions will add the selected code snippet to the chat input box or the currently active Cmd K prompt bar.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@code-select.png

To add the selected code to a new chat, you can press Ctrl/⌘ L.

@Docs

@Docs

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@docs.png

Cursor comes with a set of third-party documentation that has been crawled, indexed, and is ready to use as context. You can access them using the @Docs symbol.

Adding Custom Documentation

If you want to crawl and index custom documentation that isn't already provided, you can do so through @Docs > Add new doc. After you paste the URL of the documentation you want, the following modal will appear:

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@docs-add.png

Cursor will then index and learn the documentation, and you can use it as context just like other documentation. If you want to index all subpages and subdirectories, make sure to add a slash at the end of the URL.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@docs-learning.png

Managing Custom Documentation

Under Cursor Settings > Features > Docs, you'll see the documentation you've added. You can edit, delete, or add new documentation here.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@docs-manage.png

@Git

Currently, @Git is only supported in Cursor Chat.

@Git

In Cursor's chat, you can use @Git to add git commits, diffs, or pull requests to your prompt.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@git.png

Common Use Cases

A common use case for @Git is to have Cursor's AI scan diffs and look for potential errors or issues that might be caused by the diff.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@git-usecase1.png

You can also use @Diff of Working State to generate commit messages from the current diff.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@git-commit-message.png

@Codebase

@Codebase

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/chat/@codebase.png

With @Codebase, Cursor Chat goes through these steps until it finds the most important code snippets to use.

  • Collect: Scans your codebase to find important files/code blocks
  • Reorder: Reorders context items based on relevance to the query
  • Reason: Thinks about the plan for using the context
  • Generate: Proposes a response

Another way to submit advanced codebase queries is to click the dropdown next to the Ctrl/⌘ + Enter button and select reranker for the search behavior. This is only available when @Codebase is not used, otherwise @Codebase takes precedence.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/chat/codebase-dropdown.png

@Web

@Web

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@web.png

With @Web, Cursor constructs search queries based on your provided query and context, and searches the web to find relevant information as additional context.

This is useful for having Cursor find the latest information online, or having Cursor scrape multiple websites in seconds to find the best answer without users having to manually search anywhere.

@Chat

This feature is currently only available for Cmd K.

@Chat

You can use @Chat in Cmd K to add current chat messages as context. This is useful when you have an AI conversation that you want to apply to editing or generating code.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@chat.png

@Definitions

This feature is currently only available for Cmd K.

@Definitions

The @Definitions symbol adds all nearby definitions to Cmd K as context.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@definitions.png

Pasting Links

@https://your-link.com

To have Cursor visit a link before responding, type @ and then paste the link.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@link.png

Removing Links

By default, we automatically parse links and convert them to @Links in Cursor Chat. If you prefer to have links as plain text, click the link and then click Unlink.

https://mintlify.s3.us-west-1.amazonaws.com/cursor/images/context/@link-unlink.png

Ignoring Files

The .cursorignore file allows you to exclude files and directories from Cursor's codebase indexing

About .cursorignore

To ignore files from codebase indexing, you can use a .cursorignore file in your project's root directory. It works the same way as git's .gitignore.

.cursorignore follows .gitignore. If you already have a .gitignore, files are ignored by default. If you want to ignore additional files, you can add them to the .cursorignore file.

You can read more about how this works on our security page.

Chat and Composer Context

Currently, Cursor Chat and Composer can access all files in their context without being affected by .cursorignore settings.

More information about how we handle AI requests can be found on our security page.

.cursorignore File Example

Ignoring Specific Files

# Ignore all files in the `dist` directory
dist/

# Ignore all `.log` files
*.log

# Ignore specific file `config.json`
config.json