Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Try in VS Code!

Use chat in VS Code

Use chat in Visual Studio Code to ask about your codebase or make edits across your project by using natural language. Chat can operate in different modes, optimized for your use case, from asking questions to making multi-file edits or starting an agentic coding workflow.

You might want to use chat in VS Code when you need to:

  • Understand code - "Explain how this authentication middleware works"
  • Debug issues - "Why am I getting a null reference in this loop?"
  • Get code suggestions - "Show me how to implement a binary search tree in Python"
  • Optimize performance - "Help me improve the efficiency of this database query"
  • Learn best practices - "What's the recommended way to handle errors in async functions?"
  • Get VS Code tips - "How do I customize keyboard shortcuts?"

Prerequisites

Chat mode

Chat in VS Code can operate in different modes, each optimized for a specific use case. You can change between the different chat modes at any time in the Chat view.

Mode Description
Ask Ask mode is optimized for answering questions about your codebase, coding, and general technology concepts.
Use ask mode to understand how a piece of code works, brainstorm software design ideas, or explore new technologies.
Open in Stable | Insiders.
Edit Edit mode is optimized for making code edits across multiple files in your project. VS Code directly applies the code changes in the editor, where you can review them in-place. Use edit mode for coding tasks when you have a good understanding of the changes that you want to make, and which files you want to edit.
Open in Stable | Insiders.
Agent Agent mode is optimized for making autonomous edits across multiple files in your project. Use agent mode for coding tasks when you have a less well-defined task that might also require running terminal commands and tools.
Open in Stable | Insiders.

Switch between the different chat modes by using the Mode dropdown in the Chat view.

Screenshot showing the Copilot Chat view, highlighting the mode dropdown.

Access chat in VS Code

You can access chat in VS Code in several ways:

  • Chat view (⌃⌘I (Windows, Linux Ctrl+Alt+I)): have an ongoing, multi-turn chat conversation in a dedicated view. Switch between different chat modes at any time. By default, the Chat view is located in the Secondary Side Bar in VS Code.

  • Inline chat (⌘I (Windows, Linux Ctrl+I)): start a chat conversation directly from the editor (editor inline chat) or integrated terminal (terminal inline chat) to get suggestions in-place.

  • Quick Chat (⇧⌥⌘L (Windows, Linux Ctrl+Shift+Alt+L)): ask a quick question and get back into what you were doing.

Quickly access chat by using the corresponding keyboard shortcuts or via the Copilot menu in the VS Code title bar.

Screenshot of the Copilot Chat menu in the VS Code Command Center

Submit a chat prompt

You can use natural language to make chat requests. You can ask questions about your codebase, get code suggestions, or brainstorm ideas.

Open the Chat view (⌃⌘I (Windows, Linux Ctrl+Alt+I)) and enter your prompt in the chat input field. Notice that the response might rich content such as Markdown text, code blocks, buttons, file trees, and more.

Copilot Chat view in the Secondary Side Bar and Explorer view in the Primary Side Bar.

Here are some example prompts you can experiment with:

  • Ask questions about coding and technology concepts ("What is a linked list?", "top 10 popular web frameworks")
  • Brainstorm ideas on how to best solve a coding problem ("How to add auth to my project?")
  • Explain a block of code ("@workspace /explain", "What does this code do?")
  • Propose code fixes ("@workspace /fix", "This method gives a FileNotFoundException")
  • Generate unit test cases or code documentation ("@workspace /tests", "@workspace /doc")
  • Ask about VS Code settings (@vscode how do I disable the minimap?)

For more prompt examples, see the Copilot Chat Cookbook in the GitHub documentation.

Tip

Type /help in the chat input field to get help about GitHub Copilot and how to interact with Copilot Chat.

Change the language model

Copilot offers different built-in language models to choose from. Some models are optimized for fast coding tasks, while others are better suited for slower planning and reasoning tasks. Use the model picker in the chat input field to change the model that Copilot uses for generating a response.

Screenshot of the Copilot Chat model picker

You can also add models from other model providers (preview) and use them in chat. Get more details about how to use models from other providers.

Note

The list of available models might vary based on your Copilot subscription and might change over time. See the GitHub Copilot documentation for more information about the available language models.

Add chat context

VS Code tries to determine the intent and scope of your chat request based on your natural language prompt. To help get more relevant responses, provide additional context in your chat prompt, such as files, test results, terminal output, and more.

Use the Add Context button in the Chat view or type #-mentions to add context to your chat prompt. For example, #codebase to refer to the entire codebase, or #<file | folder | symbol> to refer to a specific file, folder, or symbol in your workspace. Type # in the chat input field to view the list of context items. Learn more about adding context to your chat prompt.

Screenshot of the Chat view with the context menu open

You can also directly reference an agent mode tool in your prompt by typing # followed by the tool name. You can do this in all chat modes (ask, edit, and agent mode). For example, use the #fetch tool to add the content of a web page as context to your chat prompt, or use #githubRepo to perform a code search in a GitHub repository.

Get more details about adding context to your chat prompt.

Vision (Preview)

Chat supports vision capabilities, which means you can attach an image as context to your chat prompt and ask questions about it. For example, attach a screenshot of a block of code and ask to explain it, or attach a sketch of a UI and ask agent mode to implement it.

Tip

You can drag and drop an image from a web browser onto the Chat view to add it as context.

Chat history

The Chat view is designed to be a multi-turn conversation. Copilot uses the history of the conversation as context to your current prompt. This means that you can ask follow-up questions or clarify your previous question without having to repeat the context.

At any time, you can create a new chat session by using the New Chat (+) button (⌃L (Windows, Linux Ctrl+L)) in the Chat view. This can be useful if you want to move to a different topic and avoid the previous context and history.

You can access the previous chat sessions by using the Show Chats... button in the Chat view or by using the Chat: Show Chats... command in the Command Palette. Select an entry to open that chat session in the Chat view.

Screenshot of the Chat view with the Show Chats... button highlighted

You can export all prompts and responses for a chat session in a JSON file with the Chat: Export Chat... command in the Command Palette.

Revert previous requests

Within a chat session, you can remove a specific prompt and the corresponding response from the conversation history of that session. Hover over the prompt and select the x control. Removing a request might be useful if you notice that the language model is not providing relevant responses or is taking an unwanted direction.

Chat view with multiple prompts, highlighting the 'x' control to delete a chat prompt and response.

Open chat in an editor tab or separate window

You can open a chat session as a separate editor tab, or even as a separate, floating window. This functionality enables you to have multiple chat sessions open at the same time.

In the Chat view, select the ... icon in the top-right corner, and then select Open Chat in Editor or Open Chat in New Window.

Screenshot of the Chat view, highlighting the three-dot menu that contains the Open in Editor and Open in New Window options.

The following screenshot shows the Chat view running in a floating window:

Screenshot of the Chat view, highlighting the three-dot menu that contains the Open in Editor and Open in New Window options. The desktop shows a floating window with a chat session.

By default, the chat session opens in compact mode, which hides the title bar and other UI elements. Select the compact mode icon in the floating window title bar to toggle between compact and normal mode.

Optionally, enable the Always on Top mode to always keep the Chat view on top of other windows.

Learn more about floating windows in VS Code.

Use voice interactions

With the voice control capabilities in VS Code, provided by the VS Code Speech extension, you can initiate a chat conversation by using your voice:

  • Use your voice to dictate your chat prompt
  • Use the "Hey Code" voice command to start a voice session with Copilot Chat
  • Accelerate voice input for chat by using the "hold to speak" mode

Learn more about how to use voice interactions in VS Code.

Privacy and transparency

To enable more workspace search features for private repositories, we require additional permissions. If we detect that we don't have these permissions already, we will ask for them at startup. Once granted, we'll securely store the session for the future.

Modal window asking for additional authentication for a private repository.

Learn more about security, privacy, and transparency in the GitHub Copilot Trust Center.

Frequently asked questions

How do I choose between the different chat modes?

The different chat modes are optimized for different use cases:

  • Use editor inline chat to ask questions or make edits directly in the active editor. This is useful for making code changes or asking questions that are scoped to the active file.

  • Use ask mode to ask questions about your codebase or technology concepts. The response might include code suggestions, which you can apply manually and individually to your codebase. Changes are not automatically applied to your codebase.

  • Use edit mode to directly apply edits across multiple files in your codebase based on your chat prompt. You provide the relevant context and files for your prompt.

  • Use agent mode to start an agentic coding workflow, whereby Copilot autonomously determines the relevant context and files, determines which tasks need to be performed to complete the request. It then iterates independently to achieve the desired outcome, fixing issues as they come up. Agent mode can invoke tools to perform specialized tasks, such as running terminal commands, validating test cases, or accessing APIs.

Additional resources

You can read more about GitHub Copilot and how to use it in VS Code in the GitHub Copilot documentation.

Or check out the VS Code Copilot Series on YouTube, where you can find more introductory content and programming-specific videos for using Copilot with Python, C#, Java, PowerShell, C++, and more.

Next steps