AI & Agents

Cursor Ignore File (.cursorignore): Syntax, Setup and Context Optimization

A .cursorignore file instructs Cursor's indexing engine and AI agents to exclude specific files, directories, and binary assets from codebase indexing and prompt context. Without proper ignore rules, background embedding pipelines stall on generated artifacts, vendor libraries, and credentials, degrading semantic search accuracy. Configuring root and global ignore patterns keeps repository context focused while external documentation moves to searchable MCP workspaces.

Derek Labian 14 min read Updated
Optimizing Cursor codebase indexing and AI agent context with .cursorignore syntax rules.

What Is a .cursorignore File and How Codebase Indexing Uses It

A .cursorignore file is a configuration file placed in the root of a project that instructs Cursor's indexing engine and AI agents to exclude specific files, directories, and binary assets from codebase indexing and prompt context. When developers open a repository in Cursor without defining exclusion rules, the editor attempts to chunk and compute vector embeddings for every non-ignored file across the project tree. In projects containing large build directories, generated client stubs, vendor dependencies, or heavy binary assets, background indexing stalls, consumes local CPU cycles, and contaminates semantic search retrieval with minified noise.

Cursor parses source files locally, dividing code into semantic chunks and generating vector embeddings that power features like codebase search, Chat, Composer, and the @Codebase context reference. When developers submit a prompt, Cursor queries this vector index to retrieve relevant code snippets, injecting only the top matching fragments into the language model's prompt. If indexing is bogged down by build artifacts, package lockfiles, or minified JavaScript bundles, retrieval accuracy drops because noisy tokens crowd out core business logic.

Different AI developer platforms approach file boundaries with distinct constraints. For example, in chat-based assistants, file ingestion is bounded strictly by upload quotas; Anthropic file upload documentation specifies that Claude chats accept up to 20 files at up to 500 MB per file, while Claude Projects accept files up to 30 MB each with unlimited file count bounded by the model context window. In contrast, Cursor relies on background repository indexing where the primary ceiling is not single-prompt attachment size, but the indexing throughput, vector store quality, and token efficiency of your local project tree. Understanding Cursor codebase indexing limits helps teams avoid stalled embedding queues. While Cursor does not impose a rigid numerical file cap on local repositories, indexing performance degrades when scanning tens of thousands of files or heavy binary artifacts. To make Cursor ignore files from indexing, developers configure ignore files that keep vector stores focused exclusively on active source code.

How Cursor Blocks Files Across AI Features

Placing a pattern in .cursorignore creates a barrier across Cursor's primary AI features. According to Cursor ignore file documentation, files matched by .cursorignore are blocked from three specific surfaces:

  • Code accessible by Cursor Agent and Tab autocomplete.
  • Code accessible through manual @ mention references in chat and composer.
  • Background semantic search and vector codebase indexing.

When a file is ignored, Cursor's language models will not read its contents during inline code generation, will not index it into the semantic search database, and will block users from attaching it via @filename. However, an important boundary exists: the integrated terminal and Model Context Protocol tools used by Cursor Agent run outside native editor file filters. If an agent is instructed to run a shell command like cat .env or execute an MCP tool against an absolute path, the terminal process can still read the underlying disk contents. True secret isolation requires keeping sensitive credentials entirely outside the repository boundary.

The Difference Between .cursorignore and .gitignore

Developers often ask whether a separate .cursorignore file is necessary when a comprehensive .gitignore is already present. Cursor automatically respects .gitignore rules by default. If a directory like node_modules/ or dist/ is listed in .gitignore, Cursor excludes it from codebase indexing without additional configuration.

The primary purpose of .cursorignore is defining exclusions that apply exclusively to Cursor's AI features while keeping those files tracked in Git. Common examples include:

  • Static fixtures and mock JSON payloads needed for unit test suites but too verbose for AI prompts.
  • Third-party SDK vendor bundles checked into the repository for deterministic builds.
  • Generated database migration histories containing thousands of repetitive schema snapshots.
  • Proprietary intellectual property, internal customer datasets, or compliance documents that developers want committed to source control but shielded from third-party model inference.

By separating Git tracking from AI indexing, teams maintain full version control without polluting the vector store used by Cursor's code generation models.

Differences Between .cursorignore and .cursorindexingignore

Cursor also supports a specialized configuration file named .cursorindexingignore. While .cursorignore creates a universal block across all AI capabilities (disabling Agent inspection, Tab autocomplete, chat mentions, and vector embeddings), .cursorindexingignore restricts files exclusively from background codebase indexing.

This distinction is valuable when developers maintain large reference scripts, utility helpers, or schema definitions that should not consume embedding resources during background scans, but may still need to be referenced manually during Chat or Composer sessions via @filename. When you want complete isolation, use .cursorignore; when you want to reduce vector indexing overhead while preserving on-demand AI access, use .cursorindexingignore.

Syntax Rules and Pattern Examples for .cursorignore Configuration

The .cursorignore file uses standard Git glob syntax, making pattern authoring familiar to software engineers. Rules are evaluated line by line, with empty lines and comment lines prefixed with # ignored. Trailing whitespace is stripped unless escaped with a backslash.

Key glob syntax operators include:

  • Asterisk *: Matches any sequence of characters within a single directory level, excluding path separators.
  • Double asterisk **: Matches zero or more directories, enabling recursive matching across nested folder trees.
  • Question mark ?: Matches exactly one character.
  • Slash /: When placed at the start of a pattern, anchors the match to the project root directory. When placed at the end, specifies that the pattern matches only directories.
  • Exclamation mark !: Negates a previous exclusion rule, re-including a file that would otherwise be ignored.

Sample Production .cursorignore Template

Below is a production-ready .cursorignore template suitable for modern full-stack web and backend applications:

# environment variables and secret stores
.env
.env.*
*.pem
*.key
**/secrets.json
**/credentials.json

# build artifacts and compiled outputs
dist/
build/
out/
.next/
.nuxt/
target/
*.tsbuildinfo

# package manager locks and dependency caches
node_modules/
.venv/
__pycache__/
package-lock.json
yarn.lock
pnpm-lock.yaml
bun.lockb

# large datasets, logs, and database dumps
*.log
*.sqlite
*.csv
*.parquet
tests/fixtures/large_payloads/
assets/raw_recordings/

# generated code and documentation builds
generated/graphql-client.ts
docs/_build/
coverage/
.nyc_output/

Negation Rules and the Nested Directory Trap

A frequent pitfall when configuring .cursorignore involves negation patterns. When you use the ! prefix, you cannot re-include a file if its parent directory was already matched and skipped by a wildcard directory pattern. This limitation mirrors Git's underlying directory traversal architecture.

Consider this broken configuration:

# broken configuration: attempts to ignore public but keep style.css
public/*
!public/assets/style.css

In this example, public/* matches the assets/ subfolder. For performance reasons, Cursor's file scanner stops traversing excluded directories immediately. Because the scanner never opens public/assets/, it never evaluates the negation rule !public/assets/style.css. The CSS file remains ignored.

To fix this issue, avoid broad wildcard directory matches when specific nested files must remain accessible. Instead, target nested folders explicitly:

# working configuration: exclude assets folder contents while preserving specific files
public/assets/*
!public/assets/style.css

By targeting public/assets/* rather than public/*, Cursor walks down into the assets folder, discovers style.css, and honors the negation rule.

Files Cursor Automatically Excludes by Default

Cursor ships with an extensive built-in default ignore list designed to protect system stability. Even if your .gitignore and .cursorignore files are empty, Cursor's background indexer skips common binary formats, package lockfiles, and virtual environment directories.

The default ignore list includes:

  • Package lockfiles: package-lock.json, pnpm-lock.yaml, yarn.lock, composer.lock, Gemfile.lock, bun.lockb.
  • Version control folders: .git/, .svn/, .hg/.
  • Binary executables and libraries: *.bin, *.exe, *.dll, *.so, *.dylib, *.vsix.
  • Documents and media: *.pdf, *.doc, *.docx, *.xls, *.xlsx, *.ppt, *.pptx, *.jpg, *.jpeg, *.png, *.gif, *.mp4, *.mov, *.zip, *.tar.gz, *.parquet.
  • Virtual environments and caches: node_modules/, .venv/, .egg-info/, __pycache__/, .next/, .nuxt/, .pytest_cache/, .mypy_cache/, .DS_Store.

If you genuinely need Cursor to index a file that falls into the default list, such as a reference data.csv or a specific documentation guide.pdf, you can override the default exclusion by adding an explicit negation pattern in your project's .cursorignore file, such as !data/reference.csv.

How to Configure Local, Hierarchical, and Global Ignore Rules

Configuring ignore patterns can occur at multiple scopes: within a single repository, hierarchically across nested subprojects, or globally across your entire development environment. Understanding how to use cursorignore effectively across these tiers keeps editor performance consistent without breaking monorepo workflows.

Setting Up a Repository-Level .cursorignore File

Setting up .cursorignore in a repository requires three direct steps:

  1. In the root directory of your workspace, create a new file named .cursorignore.
  2. Populate the file with glob patterns matching unwanted build artifacts, local mocks, and sensitive configuration paths.
  3. In Cursor Settings, open the Features panel and inspect Codebase Indexing. Review the indexed file count and trigger an index resync to confirm that excluded files are dropped from the vector store.

Enabling Hierarchical Cursor Ignore for Monorepos

In monorepos containing multiple independent packages or microservices, placing a single .cursorignore file in the repository root can become unwieldy. Cursor supports hierarchical ignore resolution.

To enable this behavior, open Cursor Settings, go to Indexing, open the Ignore Files section, and toggle Hierarchical Cursor Ignore. When enabled, Cursor searches every parent and subproject folder for local .cursorignore files. A package located at apps/web/.cursorignore can define frontend-specific exclusions without modifying rules for backend services located in services/api/.

Configuring Global Ignore Files

To prevent private credentials or personal machine files from entering AI context across any project you open, configure global ignore patterns in Cursor user settings. The global ignore list is empty by default.

Recommended global patterns to configure in User Settings include:

  • Sensitive environment files: **/.env, **/.env.*, **/.env.local
  • Cloud credentials and keys: **/credentials.json, **/secrets.json, **/*.pem, **/*.key, **/id_rsa
  • Operating system and IDE metadata: **/.DS_Store, **/Thumbs.db, **/.idea/

Troubleshooting and Verifying Patterns

Because .cursorignore shares pattern semantics with Git, you can test whether a pattern matches a specific file path using your local terminal. Run the Git check command:

git check-ignore -v path/to/suspicious-file.json

This command outputs the exact file and line number responsible for matching the path, allowing you to debug misbehaving wildcards or unintended negations before rebuilding your Cursor codebase index.

Fastio features

Keep Heavy Reference Assets Out of Your Cursor Repository

Store large technical documentation, API specifications, and datasets in an intelligent Fast.io workspace. Connect Cursor directly through the Fast.io MCP server to query files on demand without slowing down local indexing. Monthly plans start with a 14-day free trial, which requires a credit card.

Why and When to Move Large Reference Files to External Workspaces

While .cursorignore cleanly removes unnecessary local files from Cursor's vector store, development teams frequently encounter a secondary bottleneck: heavy reference documentation. Software projects often depend on extensive API specifications, architecture decision records, third-party vendor documentation, and regulatory compliance guidelines. Storing these large assets directly inside the Git repository inflates clone times, degrades local indexing speed, and introduces irrelevant context into local code generation prompts.

Developers often respond by adding docs/ or specs/ to .cursorignore. While this speeds up local indexing, it deprives Cursor's AI agents of the technical specifications they need to implement accurate code. The effective solution is separating your active code repository from your reference knowledge base by connecting Cursor to an external workspace using the Model Context Protocol.

When to Exclude Files Versus Moving Them to Remote Storage

Deciding whether an asset belongs in .cursorignore or in a remote workspace depends on its role in the development lifecycle:

  • Exclude via .cursorignore: Transient build outputs, compiled binaries, minified packages, package manager lockfiles, coverage reports, and local environment files. These files change constantly, offer no semantic value to code generation, and should never be indexed.
  • Move to a remote workspace: Technical architecture documents, API schemas, product requirements, database schema documentation, and reference PDFs. These assets contain essential specifications that AI coding agents must query, but storing them as raw text in the Git tree degrades local editor performance.

By storing external documentation in a dedicated cloud workspace such as Fast.io storage for agents, your local Git repository remains lightweight and responsive.

Connecting Cursor to Fast.io Workspaces via MCP

Fast.io provides intelligent workspaces designed for human and AI collaboration. Files can be uploaded directly or brought in through Cloud Sync. Cloud Sync connects Google Drive, Dropbox, Box and OneDrive folders to a workspace, one-way or two-way, on a schedule or on demand. Once you create a workspace and store your project documentation, you can enable Intelligence Mode. Intelligence Mode automatically indexes your uploaded files for hybrid search, combining full-text search, semantic vector search, and metadata filtering. Instead of forcing Cursor to embed hundreds of megabytes of documentation locally, Cursor connects to Fast.io over Streamable HTTP using a remote MCP server.

For coding agents like Cursor, Fast.io serves a dedicated MCP endpoint at https://mcp.fast.io/mcp/code. You can configure Cursor to connect to your Fast.io workspace by adding an entry to your project's .cursor/mcp.json file or your user-level ~/.cursor/mcp.json configuration:

{
  "mcpServers": {
    "fast-io": {
      "url": "https://mcp.fast.io/mcp/code"
    }
  }
}

When Cursor connects to https://mcp.fast.io/mcp/code, it prompts you to authenticate via OAuth. During sign-in, you select your organization, choose the workspace containing your project documentation, and grant permissions. Step-by-step setup instructions are detailed in the Fast.io MCP documentation, and agent tooling specifications are described in Fast.io skill guide and Fast.io LLM reference.

Once connected, Cursor Agent can execute search actions against your indexed workspace documents. When you ask Cursor, "What are our rate limit policies according to our API architecture guide?", Cursor queries the Fast.io workspace through MCP, retrieves the exact cited paragraphs, and uses them to complete your code. Your local repository stays unencumbered by heavy documentation, your .cursorignore stays concise, and your AI assistant gains access to company-wide technical knowledge.

Checklist and Best Practices for Maintaining Repository Context

Maintaining high-quality context for Cursor requires ongoing repository hygiene. As projects grow, new libraries, build scripts, and test datasets can quietly inflate the file tree and dilute vector embeddings. Applying the following operational practices keeps repository context fast and accurate:

Commit .cursorignore to Version Control

Treat .cursorignore as a shared team configuration asset. Checking .cursorignore into your Git repository guarantees that every engineer on your team benefits from identical indexing rules. This prevents scenarios where one developer experiences fast, accurate AI suggestions while another struggles with indexing lag and noisy completions.

Audit Ignored Paths After Adding Build Tools

Whenever you add new frameworks, testing harnesses, or code generation utilities to your project, inspect the directories they generate. Tools like Prisma, GraphQL Code Generator, Storybook, and Playwright produce substantial artifact trees. Add their output folders to .cursorignore promptly to prevent Cursor from indexing thousands of auto-generated TypeScript declarations.

Keep Secrets Out of the Repository

While .cursorignore stops Cursor's AI models from reading sensitive files directly, it does not sandbox the integrated terminal or external MCP processes. Always store production keys, database credentials, and access tokens in secure secret managers rather than local workspace files.

Monitor Indexing Metrics in Cursor Settings

Periodically open Cursor Settings and check the Codebase Indexing status under Features. If your project contains several thousand files but the indexer reports a unexpectedly inflated count, your repository is indexing hidden dependencies or generated assets. Review your file tree, update .cursorignore, and trigger an index resync to restore optimal editor performance.

Sources

References used to verify factual claims in this guide.

  1. Claude chats accept up to 20 files at up to 500 MB per file, while Claude Projects accept files up to 30 MB each with unlimited file count bounded by the model context window.

Frequently Asked Questions

How do I create a .cursorignore file in Cursor?

Create a new file named .cursorignore in your project root directory, matching the location of your .gitignore file. Add file paths, directories, and glob patterns line by line to exclude matching files from Cursor's AI features and codebase indexing.

Does Cursor support .cursorignore syntax like .gitignore?

Yes. Cursor's .cursorignore implementation adheres directly to standard Git glob syntax. It supports wildcard asterisks, recursive directory patterns, single-character matching, comments, and negation rules prefixed with an exclamation mark.

What files should be excluded in .cursorignore to speed up indexing?

Exclude build artifact directories like dist, build, and .next, package manager lockfiles, coverage reports, large test fixture datasets, minified third-party libraries, and generated code stubs. Excluding these assets prevents unneeded files from cluttering vector embeddings and reduces indexing overhead.

Why is my negated pattern with an exclamation mark not un-ignoring a file?

In Git and Cursor ignore syntax, if a parent directory is excluded with a wildcard pattern like public/*, the file scanner does not traverse into subdirectories. Consequently, negation patterns like !public/assets/style.css are never reached. To un-ignore nested files, exclude the parent subdirectory explicitly, such as public/assets/*.

Does .cursorignore prevent Cursor Agent from reading files via the terminal?

No. The .cursorignore file blocks Cursor's native AI features, including Tab autocomplete, inline edits, and semantic indexing. However, shell commands executed in the integrated terminal and external MCP tools run outside native file filters and can still access disk contents.

Can Cursor search external reference documentation excluded from the local repository?

Yes. You can store large technical manuals, API documentation, and architecture specifications in an intelligent Fast.io workspace and connect Cursor via its remote MCP endpoint at `https://mcp.fast.io/mcp/code`. Cursor Agent can query the remote workspace semantically through [Fast.io agent storage](/storage-for-agents/) without storing heavy files locally.

Related Resources

Fastio features

Keep Heavy Reference Assets Out of Your Cursor Repository

Store large technical documentation, API specifications, and datasets in an intelligent Fast.io workspace. Connect Cursor directly through the Fast.io MCP server to query files on demand without slowing down local indexing. Monthly plans start with a 14-day free trial, which requires a credit card.