Large Codebase Strategies
You joined a team working on a 300,000-line TypeScript monolith. You open Cursor, ask it to explain the authentication flow, and it comes back with a vague answer that misses half the middleware chain. You try Agent mode for a feature, and it creates a new file from scratch instead of integrating with the existing service layer three directories deep. The codebase is too large for the AI to hold in context all at once, and without guidance, it makes assumptions that do not match your architecture.
Large codebases require a fundamentally different approach to AI-assisted development. You need to guide the AI to the right parts of the codebase, document the patterns it cannot infer, and structure your prompts around scoped, incremental changes.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- A rules-based approach to encoding domain knowledge the AI cannot infer from code alone
- Context management strategies that point the agent at the right files without burning your token budget
- Prompt patterns designed for scoped, incremental changes in large codebases
- Indexing and workspace configuration for optimal performance
Write Rules for Domain-Specific Knowledge
Section titled “Write Rules for Domain-Specific Knowledge”Think about what you would tell a new hire on their first day. What context would they need to start making meaningful contributions? That same context is valuable for Cursor.
Create .cursor/rules/ files that capture knowledge not obvious from reading the code:
---description: Add a new API endpointalwaysApply: false---
When creating new API endpoints:
1. Define the route in src/routes/[domain]/index.ts2. Create the controller in src/controllers/[domain]/3. Add validation schemas in src/schemas/[domain].ts using Zod4. Register the route in src/app.ts under the appropriate middleware group5. All endpoints must use the withAuth middleware unless explicitly public6. Error responses use our standard format: { error: string, code: string, details?: unknown }
See @src/routes/users/index.ts for a complete example.Auto-Attach Rules with Glob Patterns
Section titled “Auto-Attach Rules with Glob Patterns”Rules matching specific file patterns are automatically included when the agent works with matching files. Your backend conventions only load for backend files, frontend conventions only load for frontend work:
---globs: "src/api/**/*.ts"---
Backend API conventions:- All handlers receive (req: Request, res: Response, next: NextFunction)- Use the logger from @src/lib/logger, never console.log- Database queries go through the repository layer, never raw SQL in handlers- All mutations must be wrapped in transactionsScope Down Every Prompt
Section titled “Scope Down Every Prompt”The single most important habit for large codebases: never ask Agent to do too much at once. Instead of “add role-based access control to the application,” break it down:
- “Add a
rolecolumn to the users table and create the migration” (1-2 files) - “Create a
withRolemiddleware that checks user roles, following the pattern in @src/middleware/auth.ts” (1-2 files) - “Apply the
withRole('admin')middleware to the admin routes in @src/routes/admin/index.ts” (1 file) - “Add tests for the role middleware in @src/middleware/tests/role.test.ts” (1 file)
Each step is small enough for the agent to hold all relevant context and produce accurate output. Each step builds on committed, verified work from the previous step.
Use Chat to Get Up to Speed
Section titled “Use Chat to Get Up to Speed”When navigating an unfamiliar part of a large codebase, use Ask mode before making any changes:
Trace the request lifecycle for POST /api/orders/create.
Start from the route definition, through all middleware, into the controller,through the service layer, and into the database queries. List every filein the call chain and explain what each one does.
Include error handling paths -- what happens when validation fails,when the database is unavailable, and when the payment provider rejects.This kind of exploration in Ask mode takes 30 seconds and saves 15 minutes of manual file navigation.
Pick the Right Tool for Each Edit
Section titled “Pick the Right Tool for Each Edit”| Tool | Best For | Scope | Speed |
|---|---|---|---|
| Tab | Quick manual edits with AI suggestions | Single cursor position | Instant |
Inline Edit (Cmd/Ctrl+K) | Focused changes to selected code | Single file | Fast |
Agent (Cmd/Ctrl+I) | Multi-file features and refactoring | Multiple files | Thorough |
In large codebases, Tab and Inline Edit handle 60-70% of your changes. They are faster, more predictable, and do not require the AI to understand the entire project. Save Agent for changes that genuinely span multiple files.
Context Management at Scale
Section titled “Context Management at Scale”Use @-Mentions Liberally
Section titled “Use @-Mentions Liberally”In large codebases, the agent needs your help finding the right files:
Add a new user notification preferences endpoint.
Follow the patterns in:- @src/routes/users/index.ts (route definition)- @src/controllers/users/profile.ts (controller pattern)- @src/schemas/user.ts (validation schema)- @src/services/user-service.ts (service layer)
The new endpoint should be PATCH /api/users/notification-preferencesUse .cursorignore for Noise Reduction
Section titled “Use .cursorignore for Noise Reduction”Exclude directories that add noise without value:
node_modules/dist/build/.next/coverage/*.min.js*.mapvendor/__generated__/This reduces indexing time, keeps the context window clean, and prevents the agent from referencing generated or vendored code.
Start New Chats Often
Section titled “Start New Chats Often”Long conversations in large codebases are a recipe for confusion. The agent accumulates context from earlier messages and may reference outdated information.
Start a new chat when:
- You move to a different part of the codebase
- You have committed a set of changes and are starting the next piece
- The agent references files or code that no longer exists
- You have been going back and forth for more than 5-6 exchanges
When This Breaks
Section titled “When This Breaks”Agent creates files from scratch instead of integrating with existing patterns. Your rules are not detailed enough. Add a rule that describes the file structure and references canonical examples with @file mentions.
Agent loses context partway through a large change. The change is too big for one prompt. Break it into smaller, committed steps.
Indexing takes too long or uses too much memory. Ensure .cursorignore excludes generated files, build artifacts, and large vendor directories. See Performance Optimization.
Agent follows the wrong conventions. Create glob-scoped rules that auto-attach when editing specific directories. A backend rule that loads for src/api/**/*.ts ensures correct conventions without repeating them in every prompt.
What’s Next
Section titled “What’s Next”- Custom Rules and Templates — Deep dive into building a comprehensive rules library
- Performance Optimization — Tuning indexing and memory for large projects
- Token Management — Managing costs when context windows are large