Understanding Unfamiliar Code with Cursor
Every codebase has knowledge locked inside it: how authentication works, why that API is shaped the way it is, and what breaks if you change a function. Cursor lets you ask these questions directly and get answers grounded in your code. See how Agent searches your codebase for details.
Asking questions about your codebase
Think of Cursor as a teammate who has read every file in the project. You can ask the same questions you would ask a senior engineer who knows the codebase well.
When you want to understand without making changes, use Ask mode. Cursor explores and explains without editing files. Press Shift+Tab and select Ask to switch modes. This is the right choice when you are building mental models, not shipping code.
Cursor maintains context within a conversation, so you can start broad and drill into specifics with follow-up questions. If you are looking at a specific file and want to understand it better, reference it directly: "Explain what @src/services/PaymentProcessor.ts does and what calls it."
Visualizing with diagrams
Complex systems are often easier to understand visually. Cursor can generate Mermaid diagrams to show how components interact, how data flows, or how requests move through your system.
Diagrams render directly in Cursor and are useful for onboarding, documentation, and debugging. They help you and your team see the bigger picture.
Tracing how code connects
Understanding individual files is one thing. Understanding how data flows through a system requires seeing the whole picture: what calls what, what depends on what, what breaks if you change something.
For microservices architectures, open multiple repositories in the same workspace. Cursor indexes them together and can trace dependencies across service boundaries. This makes understanding upstream and downstream impacts practical when working across multiple services.
Context beyond the codebase
Sometimes understanding code requires context that is not in your repository: API documentation, framework guides, or information from external systems.
Web search lets Cursor look up current documentation when it encounters unfamiliar APIs or needs to understand how a library works. This is automatic when the agent needs external information.
MCP integrations connect Cursor to external tools and data sources. If you need to understand how your code interacts with production data, a connected database MCP can provide that context. If you need to reference design specs, a Figma MCP can pull in relevant frames. Browse the Marketplace for available integrations.
Understanding why code is the way it is
Sometimes you inherit code that seems strange and want to know if there is a reason before changing it. Git history provides context about how code evolved and why decisions were made.
This is about understanding intent and history, not just current state. Code that looks wrong often has a reason: a bug it fixed, a constraint it worked around, or a migration it supported. Knowing that history helps you decide whether to preserve the behavior or safely change it.
Onboarding to a new codebase
When you join a team or start working with an unfamiliar project, the first days are often spent hunting through files and asking teammates basic questions. Cursor compresses this ramp-up time.
Get the big picture first, then drill into specifics about common tasks, testing strategies, and configuration.
Capture what you learn in rules files
As you learn things about your codebase, add them to rules files so Cursor has that context in future sessions and for other team members.
Create a .cursor/rules/codebase-context.mdc file:
# Codebase Context## Architecture- This is a monorepo with three main packages: api, web, and shared- The API uses Express with TypeORM- The web client is Next.js## Common patterns- To add a new API endpoint, see src/api/routes/users.ts as an example- Database migrations are in src/api/migrations- Services handle business logic, repositories handle data access## Gotchas- The legacy auth system is in src/api/auth/legacy. Don't modify it.- Some older services use callbacks instead of async/await- The UserDAO exists for backwards compatibility; prefer UserRepositoryThis file serves double duty: it helps Cursor give better answers, and it is documentation that new team members can read directly.
Deep investigations with Cloud Agents
Some questions require extended exploration: understanding a complex subsystem, mapping all the places a pattern is used, or tracing an issue through multiple services. For these, Cloud Agents can run longer investigations while you do other work.
Cloud Agents run autonomously in isolated environments. You can check their progress, send follow-up questions, or take over at any point. This is useful for thorough investigations that would take too long interactively.
Getting started
-
Open your project and let Cursor index it. Indexing happens automatically. For large codebases, give it a few minutes.
-
Start with broad questions. Ask about architecture, main modules, and how things connect. Build a mental model before diving into specifics.
-
Use Ask mode for exploration. When you are trying to understand rather than change, Ask mode keeps Cursor focused on explaining. Press
Shift+Tabto switch. -
Generate diagrams for complex flows. Visual representations help you understand systems faster. Ask Cursor to create Mermaid diagrams of architectures and data flows.
-
Capture what you learn. Add useful context to rules files so it persists across sessions and benefits your team.