The Chat Interface and Ask Mode
The Chat Interface and Ask Mode
One of the most immediately useful features in Cursor is the Chat panel. It gives you an AI assistant that is not sitting in a separate browser tab but is embedded directly inside your editor, reading the exact file you have open and understanding the code you have selected. This lesson covers how to open the Chat panel, how Ask mode works, and how to get the most out of it.
What You'll Learn
- How to open and navigate the Chat panel with Cmd+L
- The difference between Ask mode and Agent mode
- How Chat reads your current file and selection as context
- Using Chat to explain unfamiliar code
- Generating code snippets directly from Chat
- Managing chat history and starting fresh conversations
- Tips and patterns for writing prompts that produce useful answers
Opening the Chat Panel
To open the Chat panel in Cursor, press Cmd+L on macOS (or Ctrl+L on Windows and Linux). The panel slides in on the right side of your editor, giving you a conversation interface without leaving your workspace.
You can also open it by clicking the chat icon in the sidebar, but the keyboard shortcut is worth learning immediately. Once the Chat panel is open, you can move between it and your code with a single keystroke, keeping your focus tight.
The Chat panel persists across the session. If you close it and reopen it, your previous conversation is still there. This is useful for referring back to something the AI explained earlier, or for building on a previous response.
Pinning the Panel
If you prefer the Chat panel to stay visible while you write code, you can drag it into a split-view layout alongside your editor. This works well on wider monitors where you have room for both. For narrower screens, the default behavior of toggling it open and closed with Cmd+L tends to be more comfortable.
Ask Mode vs Agent Mode
When you open Chat, the first thing to understand is the mode selector at the top of the panel. Cursor gives you two primary modes: Ask and Agent. They look similar but behave very differently.
Ask Mode
Ask mode is conversational and non-destructive. You ask a question or make a request, and the AI responds with text and code suggestions. Crucially, Ask mode does not automatically make changes to your files. If the AI generates a code snippet, it appears in the chat as a block you can copy or apply manually.
Ask mode is best for:
- Understanding what existing code does
- Getting a second opinion on an approach
- Exploring options before committing to one
- Asking questions about APIs, libraries, or language features
- Getting a code snippet you will review before using
Think of Ask mode as a knowledgeable colleague you can talk to. It will explain, suggest, and generate -- but it waits for you to decide what to do with the output.
Agent Mode
Agent mode is autonomous and action-oriented. When you switch to Agent mode, Cursor can directly create files, edit multiple files in your project, run terminal commands, and take a sequence of actions to complete a larger task. Agent mode is the topic of a dedicated later lesson, but it is worth understanding the distinction from the start: Ask mode talks, Agent mode acts.
For now, when you are in the Chat panel and want to stay in control of what changes happen to your code, make sure Ask mode is selected.
How Chat Reads Your Code
One of the biggest advantages of Cursor's Chat over a standalone AI chatbot is that it already knows what you are working on. It pulls context automatically from two sources: your current file and any selected code.
Your Current File
When you open Chat with Cmd+L while a file is open in your editor, Cursor automatically includes that file as context. You can see this indicated at the top of the chat input as an attached file reference. This means you do not need to paste your entire file into the chat to ask questions about it.
For example, if you have a 200-line React component open and you ask "what does this component do?", the AI has already read the file and can give you a specific answer -- not a generic explanation of React components in general.
Selected Code
If you highlight a specific section of code before opening Chat, that selection becomes the primary context. This is useful when you want to ask about a specific function or block rather than the whole file.
// Select this function, then press Cmd+L
function calculateDiscount(price, userTier) {
if (userTier === 'premium') return price * 0.8;
if (userTier === 'standard') return price * 0.9;
return price;
}
With this selection active, you could ask: "Can this function handle edge cases like null prices or invalid user tiers?" and the AI will analyze exactly that function without needing any additional context from you.
Adding More Context Manually
Sometimes the file you have open is not enough. If your question involves types defined in another file, a database schema, or a configuration file, you can add those manually using the @ mention syntax. Type @ in the chat input and Cursor will show you a list of files in your project to attach. This is covered in detail in the context and multi-file editing module.
Using Chat for Code Explanations
Ask mode excels at explaining code you did not write or have not touched in a while. Rather than reading through unfamiliar logic line by line, you can ask Cursor to walk you through it.
Useful explanation prompts:
- "Explain what this function does step by step"
- "What is the purpose of this middleware?"
- "Why would this code use a closure here instead of a regular function?"
- "What are the potential side effects of calling this?"
- "Walk me through this SQL query"
The key is to be specific about what aspect you want explained. "Explain this code" works, but "explain why this code uses debounce instead of throttle" will get you a more targeted and useful answer.
Following Up
Chat maintains conversation history, so you can ask follow-up questions naturally. If the first explanation is too high-level, say "can you go deeper on the caching logic?" If a term is unfamiliar, ask "what does memoization mean in this context?" The AI remembers what was just discussed and builds on it.
Generating Code Snippets from Chat
Ask mode is not only for reading code -- it is an efficient way to generate new code before you decide where to put it. Rather than starting with a blank file and immediately writing, you can use Chat to sketch out an approach first.
Example: Generating a Utility Function
Suppose you need a function that formats a date for display in your UI. Instead of looking up the Date API or reaching for a library, you can ask:
Write a TypeScript function that takes a Date object and returns a
human-readable string like "March 16, 2026". Handle null gracefully.
Cursor will generate the function in the chat. You review it, and if it looks right, you apply it to your file with one click using the "Apply" button that appears on code blocks.
Generating Boilerplate
Chat is particularly efficient for generating boilerplate structures you already know the shape of but do not want to type out. Examples:
- "Generate a zod schema for a user profile with name, email, and optional avatar"
- "Write a basic Express route handler for POST /api/login"
- "Give me a Jest test skeleton for a function that processes payment data"
These are cases where you know what you want but the typing is tedious. Chat handles the boilerplate so you can focus on the meaningful parts.
Applying Generated Code
When Chat produces a code block, you have a few options:
- Copy: Click the copy icon on the code block to copy it to your clipboard
- Apply: Click "Apply" to have Cursor insert the code into your current file at the cursor position or as a new block
- Insert at cursor: Some versions of Cursor show an explicit "Insert at cursor" option
Always read generated code before applying it. The AI is good at producing plausible-looking code, but it does not always know your project's specific conventions or requirements without guidance.
Chat History and New Conversations
As you use Chat throughout a work session, the conversation history accumulates. This is useful for continuity -- you can scroll back to see what was discussed, what approaches were explored, and what code was generated.
Starting a New Conversation
When you switch to a new task or a completely different part of your codebase, it is often better to start a fresh conversation. The AI uses the entire conversation history as context when generating responses, and an old conversation about an unrelated feature can confuse or dilute its answers about your new task.
To start a new conversation, click the "New Chat" button (usually a pencil icon or a plus button) at the top of the Chat panel. This clears the history and starts fresh.
A good habit: start a new chat when you start a new task. It keeps conversations focused and responses more relevant.
Referencing Previous Conversations
Cursor stores your chat history so you can revisit older conversations. If you remember discussing something useful earlier and want to find it again, you can browse through past sessions from the chat history list. This is more useful as a reference than as an active context -- for active use, a fresh focused conversation generally works better.
Tips for Writing Good Prompts in Chat
The quality of your prompts directly affects the quality of Chat's responses. A few habits that consistently lead to better results:
Be Specific About What You Want
Instead of: "fix this"
Try: "this function throws a TypeError when user is undefined -- add a null check and return an empty array in that case"
Specific prompts give the AI less to interpret and leave less room for unhelpful responses.
Include the Relevant Constraints
The AI does not automatically know your project's conventions. If you have rules about error handling, naming, or code style, mention them:
- "Add error handling using our standard pattern: try/catch that logs to our logger and throws a custom AppError"
- "Write this in the functional style we use elsewhere, no classes"
Ask for One Thing at a Time
Multi-part requests are possible, but they increase the chance of one part being handled poorly. If you need several changes, consider breaking them into separate follow-up messages. Ask mode is a conversation -- you do not need to front-load everything into one prompt.
Request Explanations Alongside Code
If you want to understand what was generated, ask for it:
- "Show me the function and explain why you structured it that way"
- "Add inline comments explaining the non-obvious parts"
This turns Chat from a code-generation tool into a learning tool at the same time.
Use Chat to Sanity-Check Your Own Code
Before committing, you can ask the AI to review what you wrote:
- "Does this look correct to you? Are there any edge cases I am missing?"
- "Is there a more idiomatic way to write this in TypeScript?"
- "Would this function handle concurrent calls correctly?"
Summary
The Chat panel (Cmd+L) is your always-available AI collaborator inside Cursor. Ask mode gives you a safe, non-destructive way to explore code, ask questions, generate snippets, and build understanding -- without worrying about unwanted changes to your files. It reads your current file and selection automatically, so you rarely need to provide context from scratch.
The most important habits to build: open Chat with a specific question, give it the context it needs, read generated code before applying it, and start fresh conversations when you switch tasks.
Key Takeaways
- Press Cmd+L (or Ctrl+L on Windows/Linux) to open the Chat panel without leaving your editor
- Ask mode is conversational and non-destructive -- it generates and explains but does not automatically edit your files
- Agent mode is autonomous and action-oriented -- it is covered separately in a later lesson
- Chat automatically reads your current open file and any selected code as context, so you rarely need to paste code manually
- Use Chat to explain unfamiliar code, generate boilerplate, sketch functions before writing them, and sanity-check your own code
- Start a new conversation when switching tasks to keep the AI's context clean and focused
- Better prompts = better answers: be specific, include constraints, ask for one thing at a time, and request explanations alongside generated code
Quiz
Discussion
Sign in to join the discussion.

