Chapter 5

Cursor Chat Complete Guide — @ References, Context Control, and Prompt Templates

Chapter 5: Cursor Chat Complete Guide — @ References, Context Control, and Prompt Templates

Cursor Chat's power comes from the @ reference system. @filename pins the exact code the AI sees. @Codebase runs semantic search across your whole project. @Web fetches real-time information. @Git connects your questions to commit history. Without @ references, you're asking the AI to answer with a blindfold on. This chapter covers every @ type, explains why context quality determines answer quality, and provides 20 copy-paste prompt templates for the most common dev scenarios.

Pick the Right Tool First: Chat vs Cmd+K vs Composer

Using the wrong tool and blaming poor AI output is a common trap. The decision is mechanical once you know the rules.

Scenario Use Why
Understand complex code logic Chat Needs explanation and follow-up questions
Rewrite a few lines of the current function Cmd+K Select the code, state the change — fastest path
Add JSDoc to a function Cmd+K Select function, describe requirement — done
Add a feature spanning multiple files Composer Cross-file changes need coordinated diffs, not suggestions
Debug a bug Chat to understand → Cmd+K to fix Use Chat + @ references to understand root cause first, then Cmd+K for the precise fix
Learn an unfamiliar API Chat + @Docs Needs documentation grounding and multi-turn dialogue
Migrate an entire module to a new stack Composer or Claude Code Requires agent-level execution across many files

The @ Reference System: Complete Guide

Type @ in the Chat input to open the reference menu. This is the fundamental difference between Cursor Chat and plain ChatGPT — you control exactly what information the AI sees.

@filename (most common)

Sends the complete content of a specific file to the AI. Far more precise than hoping the AI guesses the right file.

@src/auth/middleware.ts Why does this middleware return 401 for every request?
I've verified the token is valid, but every request gets intercepted.

@prisma/schema.prisma @src/repositories/UserRepository.ts
Are the User model fields consistent between these two files?
I suspect they've gotten out of sync.

You can @ multiple files simultaneously. When a question involves the relationship between files, you must include both — the AI cannot reason about cross-file interactions from one side only.

@Codebase (semantic search across the project)

Does not stuff the entire codebase into context. Instead performs vector semantic search and retrieves the most relevant code snippets. Use when you don't know which file contains the relevant code.

@Codebase Is there duplicate database connection initialization code?
I've seen new PrismaClient() in several places and want to centralize it.

@Codebase Where is the JWT token generated and where is it validated?
List all related files and approximate line numbers.

@Codebase vs @filename: When you know which file, use @filename (more precise, fewer wasted tokens). When you don't know, use @Codebase.

Lets the AI search for current information — essential for library versions, APIs, and best practices published after the model's training cutoff.

@Web How does React 19's use() hook combine with Suspense?
What are the known gotchas?

@Web What's different about Bun 1.x's HTTP server API vs Node.js?
I want to migrate an Express app to Bun.

Web search quality varies — verify important findings against official docs before using them.

@Docs (official documentation)

Cursor has built-in documentation indexes for React, Next.js, Tailwind CSS, and others. In Cursor Settings → Features → Docs you can add custom URLs — your internal API docs, third-party library docs — so the AI reasons from authoritative sources.

@Docs/Next.js How does generateMetadata handle dynamic route parameters in App Router?
Show a complete SEO configuration example for a blog post page.

@Docs/Prisma Under what conditions does Prisma's upsert fail?
How does its concurrency safety compare to a read-then-update pattern?

@Git (analyze commit history)

References Git commit history and diffs. Especially useful for "when was this bug introduced?" investigations.

@Git What changed in the last 5 commits? Could any of those changes cause login failures?

@Git When was this file last modified and what was the intent of the change?

@Git Summarize the last two weeks of commits into a CHANGELOG draft
written for a non-technical audience.

Context Control — The Factor That Determines Answer Quality

90% of poor AI answers come from insufficient or wrong context. The AI isn't failing — you gave it too little to work with.

Bad example:

This function has a bug, fix it

The AI doesn't know which function. It will guess or produce a generic template response — zero value.

Good example:

@src/payment/stripe.ts lines 45–67, the createPaymentIntent function.
When processing orders with amount = 0, it throws:
  StripeInvalidRequestError: amount must be at least 50 cents

Context: our platform allows free orders (100% coupon applied), where the amount is 0.
Fix requirements:
1. When amount is 0, skip the Stripe call and mark the order as paid directly
2. When amount > 0, use the normal Stripe flow unchanged
3. Do not change the function signature (many callers depend on it)

The structural formula for high-quality prompts

[@relevant files] + [current state / problem symptom] + [desired outcome] + [constraints]

20 Copy-Paste Templates for Common Scenarios

Understanding Code (1-5)

# Scenario Template
1 Understand an unfamiliar function @filename Explain how [function_name] works. Cover: (1) inputs/outputs; (2) key logic steps; (3) possible edge cases.
2 Understand an entire module @directory/ What is this module responsible for? What are the dependencies between files? Sketch a simple call flow.
3 Understand a design decision @filename Why is [pattern/method] used here instead of [alternative]? Is there any documented reason?
4 Find duplicate code @Codebase Is there duplicate implementation of [feature]? List all related files and function names.
5 Understand data flow @route @service @repository When a user places an order, how does data flow from the HTTP request to the database? What does each layer do?

Debugging (6-10)

# Scenario Template
6 Analyze an error @relevant_file Getting this error: [full error message]. Analyze: (1) root cause; (2) trigger conditions; (3) best fix (solve the root problem, not just the symptom).
7 Find a logic bug @filename lines [X-Y]. Input [value], expected [expected], got [actual]. Find the logic error.
8 Performance problem @filename This function takes [time] on [N] records. Analyze bottlenecks — especially N+1 queries, unnecessary loops, missing index conditions.
9 Memory leak @filename This component/service shows growing memory over time. Check: event listener cleanup, timer disposal, closures holding large object references.
10 Analyze error logs @Codebase Analyze this error log: [paste log]. Find: (1) the call chain that produced the error; (2) which file is most likely the source; (3) fix recommendation.

Refactoring (11-15)

# Scenario Template
11 Extract a function @filename Can lines [X-Y] be extracted into a standalone function? Give the suggested name, parameter list, return type, and the complete extracted code.
12 Eliminate duplication @fileA @fileB Both files implement [feature] with nearly identical code. Give a deduplication plan: where to put the shared code, how to parameterize the differences, what callers need to change.
13 Improve naming @filename These variables/functions have unclear names: [list]. Based on their actual purpose, suggest better names and explain why.
14 Simplify complex logic @filename Lines [X-Y] have deeply nested if/else that's hard to read. Rewrite it to be cleaner while preserving exactly the same behavior.
15 Assess refactoring risk @Codebase If I change [function/interface], what callers will be affected? List all files that need updates and rate the risk of each change.

Learning New Technology (16-20)

# Scenario Template
16 Analogy-based learning @Web I know [technologyA], now learning [technologyB]. Explain [technologyB]'s core concepts using [technologyA] analogies, with side-by-side code examples for the same feature.
17 Evaluate whether to adopt @Web My project is [description]. Considering [new tech] vs my current [existing solution] — what specific advantages does it offer? When would migration not be worth it?
18 Learn common pitfalls @Web @Docs/framework What are common mistakes when using [feature/API]? Give a wrong example and the correct version for each.
19 Practice in-project @existing_file Following the style in this file, rewrite [target function] using [new tech/pattern]. Keep tests passing. Give the complete rewritten code.
20 Best practices check @filename Against current [framework/library] best practices, are there outdated or deprecated patterns in this implementation? List specific issues and modern alternatives.

Multi-Turn Conversation Techniques

When to start a new Chat

How to persist important information

Chapter Key Points

  1. Pick the right tool first: Chat for understanding and multi-file questions, Cmd+K for precise changes to selected code, Composer for cross-file feature development. Don't blame AI for poor output from the wrong tool.
  2. @ references determine answer quality: Know the file → @filename; don't know → @Codebase; need current info → @Web; need doc support → @Docs; investigating history → @Git.
  3. More precise context = more useful answers: The formula is "relevant files + problem symptom + desired outcome + constraints." Missing any component degrades the answer.
  4. Context pollution is real: After 20+ turns or topic switches, start a new Chat. Don't try to solve everything in one session.
  5. Persist important information: Architectural conventions in .cursorrules, API decisions in docs. Don't rely on AI's non-existent cross-conversation memory.
Rate this chapter
4.9  / 5  (58 ratings)

💬 Comments