Sub topic 6
Ask questions in the Chat view
This chapter assumes you have installed the Copilot extension and signed in with GitHub, and that you know how to open the Command Palette and the Side Bar in VS Code. Inline suggestions appear as you type. The Chat view works differently: you write a request in plain language and read a reply in a dedicated panel.
What the Chat view is
The Chat view is a panel where you hold a conversation with Copilot. Each message you send is a prompt. Copilot's reply can include explanations, code blocks, and links to files. The conversation keeps its history, so a follow-up such as "now do the same for the second function" refers to what came before.
You can open the view in three ways:
- Select the Copilot icon in the title bar and choose to open Chat.
- Press
Ctrl+Alt+Ion Windows and Linux, orCtrl+Cmd+Ion macOS. - Run Chat: Open Chat from the Command Palette.
Menu names and shortcuts change between VS Code releases. If one does not work, search the Command Palette for "Chat: Open".
How a conversation flows
Treat the loop as the normal way to work. A first reply is often close but not exact. A short follow-up that names what is wrong usually gets a better result than rewriting the whole prompt.
Write a first prompt
Open a project, then open the Chat view and type a question. Good prompts state the task, the language, and any constraint.
Explain what #file:utils.ts does and suggest one way to simplify it.The #file:utils.ts part is a reference. It attaches that file to the request, so Copilot answers from the file's actual contents instead of guessing. Later chapters cover context in more detail. For now, remember that a prompt which names its target gets a more specific answer than one which does not.
Compare these two prompts:
| Weak prompt | Stronger prompt |
|---|---|
| Fix this | Explain why the loop in #file:utils.ts never ends, and show a corrected version |
| Write tests | Write Vitest unit tests for the exported functions in #file:utils.ts |
| How does this work? | Summarize what the selected function does in three sentences |
Work with the reply
Code blocks in a reply have buttons along the top. The exact set depends on your version, but you will usually see these actions:
- Copy places the code on your clipboard.
- Insert at Cursor puts the code where your cursor is in the active editor.
- Insert into New File creates a file from the block.
- Apply in Editor merges the code into the file it refers to, when Copilot knows which file that is.
Read the code before you insert it. Copilot can produce code that looks right but calls functions that do not exist or ignores an edge case. Run your tests or the program after you accept a change.
Use slash commands and selections
If you select code in the editor before you send a prompt, Copilot treats the selection as the subject of the question. This is the fastest way to ask about one function.
Slash commands are shortcuts that start with /. Type / in the chat input to see the list. Common ones include:
/explaindescribes how the selected code works./fixproposes a fix for a problem in the selected code./testsgenerates tests for the selected code./clearstarts a fresh conversation.
Common errors
- No reply or an error message. Check that you are still signed in and that your network allows the connection. The troubleshooting chapter covers this.
- A generic answer that ignores your code. The prompt had no context. Select the code or attach a file with
#file. - An answer about the wrong file. The active editor can change what Copilot sees. Click the file you mean, or reference it by name.
- Code that does not match your project style. Add a follow-up that states the rule. A custom instructions file, covered later, applies such rules every time.
Exercise
You select a function in your editor and type "Why is this slow?" in the Chat view. The answer is vague and talks about performance in general terms. Name two changes to the prompt that would make the answer more specific.
Show answer
State the constraints and the goal, for example the input size and the target time, and make sure the code is attached as context, either by keeping the function selected or by adding a reference such as #file:utils.ts. A stronger prompt is "Explain why this function is slow for arrays of 100,000 items and suggest a faster approach."
Exercise
A reply contains a code block you want in your project. Why should you run your tests after using Insert at Cursor or Apply in Editor?
Show answer
Copilot can return code that looks correct but uses functions that do not exist or misses an edge case. The insert actions do not check the code, so tests are the way to confirm it works.