Skip to main content
RapidDev - Software Development Agency
cursor-tutorial

How to Use Cursor in a Monorepo

Use Cursor effectively in a monorepo by configuring .cursorignore to exclude irrelevant packages, opening separate Cursor windows for different sub-projects, using @folder and @file to scope context precisely, and creating per-package .cursor/rules/ that auto-attach. Strategic context management prevents the AI from filling its context window with irrelevant code.

What you'll learn

  • How to configure .cursorignore for monorepo-specific exclusions
  • How to use separate Cursor windows for independent sub-projects
  • How to scope @context references to avoid context window overflow
  • How to create per-package rules that auto-attach in monorepos
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Advanced7 min read15-20 minCursor Pro+, any monorepo tool (Turborepo, Nx, Lerna, pnpm workspaces)March 2026RapidDev Engineering Team
TL;DR

Use Cursor effectively in a monorepo by configuring .cursorignore to exclude irrelevant packages, opening separate Cursor windows for different sub-projects, using @folder and @file to scope context precisely, and creating per-package .cursor/rules/ that auto-attach. Strategic context management prevents the AI from filling its context window with irrelevant code.

Managing Cursor's Context in Large Monorepos

Monorepos with hundreds of thousands of files overwhelm Cursor's indexing and context window. When the AI has too much context, it becomes slow, inaccurate, and expensive. The core principle is: only send the model what it truly needs, in the sparsest form possible. This tutorial covers every technique for taming Cursor in large codebases: aggressive file exclusion, separate windows, strategic context scoping, and per-package rules.

Prerequisites

  • Cursor Pro or Business (needed for larger context windows)
  • A monorepo with multiple packages or services
  • Understanding of your monorepo's package structure
  • Git initialized with proper .gitignore

Step-by-step guide

1

Configure aggressive .cursorignore exclusions

Create a comprehensive .cursorignore that excludes build artifacts, dependencies, and unrelated packages from Cursor's indexing. Cursor indexes all files not in .gitignore or .cursorignore. In a monorepo, most packages are irrelevant to your current task.

.cursorignore
1# .cursorignore Monorepo exclusions
2
3# Dependencies (critical these can be millions of files)
4node_modules/
5.pnpm-store/
6vendor/
7
8# Build outputs
9dist/
10build/
11.next/
12.turbo/
13.nx/
14coverage/
15
16# Generated files
17__generated__/
18*.min.js
19*.bundle.js
20*.d.ts.map
21
22# Large data files
23*.csv
24*.sql.gz
25fixtures/large/
26
27# Unrelated packages (uncomment when focused on specific packages)
28# packages/legacy-app/
29# packages/docs-site/
30# packages/admin-dashboard/

Pro tip: Use .cursorindexingignore instead of .cursorignore for packages you occasionally need. They are excluded from search but still accessible via explicit @file references.

Expected result: Cursor's indexing is limited to relevant source files, dramatically improving performance and context quality.

2

Open separate Cursor windows for sub-projects

For large monorepos, open separate Cursor windows rooted at the package level rather than the monorepo root. Each window indexes independently and has its own context scope. This is the single most effective technique for monorepo performance.

Terminal commands
1// Open terminal and launch Cursor for specific packages:
2// cursor packages/frontend/
3// cursor packages/backend-api/
4//
5// Each window:
6// - Has its own independent index
7// - Only sees files in that package
8// - Loads .cursor/rules/ from that package
9// - Does not waste context on other packages
10//
11// To reference shared packages, use @file with relative paths:
12// @../../packages/shared/types/user.ts

Pro tip: Create shell aliases for your most-used packages: alias cf='cursor packages/frontend/' and alias cb='cursor packages/backend-api/'

Expected result: Each Cursor window operates on a smaller codebase with faster indexing and more relevant AI suggestions.

3

Use precise @context scoping in prompts

In monorepo prompts, never use @codebase which searches the entire project. Instead, use @folder to scope searches to specific packages and @file for precise file references. This keeps context focused and prevents irrelevant code from consuming the context window.

Cursor Chat prompt
1// BAD — searches entire monorepo:
2// @codebase How does our auth system work?
3
4// GOOD — scoped to specific package:
5// @packages/backend-api/src/auth/ How does our auth system work?
6
7// BEST — precise file references:
8// @packages/backend-api/src/auth/authService.ts
9// @packages/shared/types/auth.ts
10// Explain how the auth service validates JWT tokens.

Pro tip: When you must search broadly, use Chat (Cmd+L) in Ask mode first to identify the relevant files, then reference those specific files in a follow-up Composer session.

Expected result: AI responses are faster and more accurate because context is limited to relevant files.

4

Create per-package auto-attaching rules

Place .cursor/rules/ directories inside each package with rules specific to that package's technology, conventions, and dependencies. These rules auto-attach based on file location, ensuring the correct context regardless of which monorepo window you use.

packages/frontend/.cursor/rules/context.mdc
1---
2description: Frontend package context
3globs: "packages/frontend/**"
4alwaysApply: false
5---
6
7- Framework: Next.js 15 with App Router
8- UI: shadcn/ui + Tailwind CSS
9- State: Zustand for client state, React Query for server state
10- Types: import shared types from @company/shared-types
11- Tests: Vitest + React Testing Library
12- Do NOT import from packages/backend-api/ directly use API client
13- API client: packages/frontend/src/lib/api.ts

Expected result: Package-specific rules auto-attach when editing files in that package.

5

Use Notepads for cross-package architecture context

Create Cursor Notepads for architectural documentation that spans multiple packages. Notepads serve as reusable context containers that you reference with @notepad-name when working on cross-cutting concerns. This is more efficient than loading multiple package files.

Cursor Notepad
1// Create a Notepad in Cursor (Ctrl+Shift+J or via sidebar):
2// Name: monorepo-architecture
3//
4// Content:
5// ## Package Dependencies
6// frontend → shared-types, api-client
7// backend-api → shared-types, database
8// workers → shared-types, database, queue
9//
10// ## Shared Contracts
11// API types: packages/shared-types/src/api/
12// Database models: packages/shared-types/src/models/
13// Event types: packages/shared-types/src/events/
14//
15// ## Inter-Package Communication
16// Frontend → Backend: REST API via api-client package
17// Backend → Workers: Message queue (BullMQ)
18// Workers → Backend: Database writes + event bus
19
20// Reference in prompts:
21// @monorepo-architecture Generate a new API endpoint...

Pro tip: Notepads persist across sessions and are referenced on demand with @notepad-name. They are ideal for architecture context that does not change frequently.

Expected result: Cross-package context is available on demand without loading large file trees into the context window.

Complete working example

.cursorignore
1# ===========================================
2# Monorepo .cursorignore
3# Only index source code relevant to current work
4# ===========================================
5
6# Dependencies CRITICAL for monorepo performance
7node_modules/
8.pnpm-store/
9.yarn/
10vendor/
11
12# Build and cache
13dist/
14build/
15.next/
16.turbo/
17.nx/
18.cache/
19coverage/
20.eslintcache
21
22# Generated files
23__generated__/
24*.min.js
25*.min.css
26*.bundle.js
27*.chunk.js
28*.d.ts.map
29src/**/*.generated.ts
30
31# Large data files
32*.csv
33*.sql.gz
34*.sqlite
35fixtures/large/
36seeds/data/
37
38# DevOps (move to .cursorindexingignore if sometimes needed)
39terraform/.terraform/
40terraform/state/
41helm/charts/
42
43# Package-specific exclusions
44# Uncomment packages you are NOT working on:
45# packages/legacy-app/
46# packages/docs-site/
47# packages/mobile-app/
48# packages/admin-panel/
49
50# Logs and temp
51logs/
52tmp/
53*.log

Common mistakes when using Cursor in a Monorepo

Why it's a problem: Using @codebase in a monorepo

How to avoid: Use @folder scoped to the specific package or @file for precise references. Save @codebase for small, focused projects only.

Why it's a problem: Opening the monorepo root as a single Cursor window

How to avoid: Open separate Cursor windows for each active package: cursor packages/frontend/ and cursor packages/backend/.

Why it's a problem: Not updating .cursorignore as focus shifts between packages

How to avoid: Comment/uncomment package exclusions in .cursorignore as you shift focus. Use .cursorindexingignore for packages you occasionally need.

Best practices

  • Open separate Cursor windows for different monorepo packages for independent indexing
  • Use .cursorignore aggressively: node_modules, build outputs, generated files, unrelated packages
  • Use .cursorindexingignore for packages excluded from search but still accessible via @file
  • Scope context with @folder and @file instead of @codebase in monorepo prompts
  • Create per-package .cursor/rules/ that auto-attach based on file location
  • Use Notepads for cross-package architecture context referenced with @notepad-name
  • Start new chat sessions when switching between packages to reset context
  • Create shell aliases for quick package-level Cursor window launching

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I have a monorepo with packages: frontend (Next.js), backend-api (Express), shared-types, workers (BullMQ). Generate a .cursorignore file and per-package .cursor/rules/ files that optimize AI code generation for each package independently.

Cursor Prompt

@packages/frontend/src/auth/ @packages/shared-types/src/api/auth.ts Generate an auth middleware for the frontend package. Only use imports available in the frontend package and shared-types. Do not import from backend-api or workers packages.

Frequently asked questions

What is Cursor's context window size?

It depends on the model. Claude 3.5 Sonnet has ~200K tokens (~150K words). In practice, 3-4 large code files plus conversation history fills the window. MAX mode provides larger context but costs more credits. Strategic @file references are more effective than loading entire packages.

How does Cursor handle large codebases efficiently?

Cursor creates embeddings of your codebase for semantic search. Files in .gitignore and .cursorignore are excluded. For monorepos, open separate windows per package, use aggressive .cursorignore, and scope @context to specific folders.

Should I use one Cursor window or multiple for a monorepo?

Multiple. Open separate windows for each active package. Each window indexes independently with its own rules. This is the single most effective monorepo optimization.

How long does Cursor take to index a large monorepo?

A monorepo with 8,800+ files can take 7-12 hours. Reducing indexed files with .cursorignore and opening package-level windows can cut this to minutes. Cursor only auto-indexes folders with fewer than 10,000 files.

Can Cursor search across monorepo packages?

Yes, if you open from the root and all packages are indexed. But this is usually counterproductive. Use precise @file references to specific files in other packages instead of broad cross-package searches.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.