Skip to main content

Command Palette

Search for a command to run...

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.

Ask mode example: Understanding infrastructure
How does logging work in this project? Where are logs configured and where do they go?
Ask mode example: Tracing a flow
What happens when a user submits a payment? Trace the flow from the frontend to the database.
Ask mode example: Summarizing large files
The PaymentGateway class has 2000 lines. Give me a summary of its responsibilities and main methods.

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.

Agent example: Generate sequence diagram
Create a sequence diagram showing what happens when a user logs in. Include the frontend, API, auth service, and database.
Agent example: Generate flowchart
Draw a flowchart of the order processing pipeline, from order creation to fulfillment.

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.

Ask mode example: Request tracing
Trace a request from the /api/orders endpoint to the database. What middleware does it pass through? What validations happen along the way?
Ask mode example: Impact analysis
I want to rename the Customer class to Account. Find everywhere this would affect and list the files that would need to change.

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.

Ask mode example: External documentation
Look up the Web Stripe API documentation for payment intents. How does our TypeScriptsrc/services/PaymentService.ts implementation compare to their recommended patterns?

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.

Ask mode example: Understanding evolution
Why is the PaymentGateway API shaped this way? Look through git history and summarize how it evolved.
Ask mode example: Finding intent
This function has a weird edge case handler. Check git blame to find when it was added and look at the commit message or related commits for context.

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.

Ask mode example: Architecture overview
Give me an overview of this codebase. What are the main modules and how do they interact?
Ask mode example: Learning patterns
How do I add a new API endpoint? Show me an example of an existing one I can follow as a pattern.

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:

Rules example: Codebase Context
# 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 UserRepository

This 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.

Agent example: Extended investigation
Map out our entire authentication system. Document every auth-related file, how they connect, what tokens we use, how sessions are managed, and any security concerns you identify.

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

  1. Open your project and let Cursor index it. Indexing happens automatically. For large codebases, give it a few minutes.

  2. Start with broad questions. Ask about architecture, main modules, and how things connect. Build a mental model before diving into specifics.

  3. Use Ask mode for exploration. When you are trying to understand rather than change, Ask mode keeps Cursor focused on explaining. Press Shift+Tab to switch.

  4. Generate diagrams for complex flows. Visual representations help you understand systems faster. Ask Cursor to create Mermaid diagrams of architectures and data flows.

  5. Capture what you learn. Add useful context to rules files so it persists across sessions and benefits your team.