Version 1.84 is now available! Read about the new features and fixes from October.
Dismiss this update
The GitHub Copilot extension is an AI pair programmer tool that helps you write code faster and smarter. You can use the Copilot extension in VS Code to generate code, learn from the code it generates, and even configure your editor.
You'll use the GitHub Copilot extension to power your artificial intelligence (AI) suggestions in VS Code.
To use GitHub Copilot, you need an active GitHub Copilot subscription. In the content below, you'll learn how VS Code will help you activate your free trial directly from VS Code. You can also activate your trial starting from the GitHub Copilot signup page.
If you have not previously authorized VS Code in your GitHub account, you will be prompted to sign in to GitHub in VS Code:
In your browser, GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, select Authorize Visual Studio Code.
If you haven't yet activated your free trial for Copilot, the extension will notify you in VS Code. Select Signup for GitHub Copilot to activate your trial.
You can learn more about billing for Copilot in the GitHub Copilot documentation.
Now that you've signed up for Copilot and activated the extension, let's see its assistance in action!
GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, and it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++.
Copilot presents suggestions automatically to help you code more efficiently. There are just 3 steps to harnessing these suggestions:
Copilot provides suggestions for a variety of languages and frameworks. For any given input, Copilot may offer multiple suggestions. You can select which suggestion to use or reject all suggestions.
Ghost text is placeholder text that will be replaced by input you type or select from Copilot.
As an example, a JavaScript file, you can type the following function header:
function calculateDaysBetweenDates(begin, end) {
Copilot will provide a suggestion like the following:
For any given input, Copilot may offer multiple suggestions. When Copilot offers a suggestion, you can use accept it with the Tab key, or hover over the suggestion to see the inline suggestion toolbar:
In the image above, Copilot presents three suggestions. You can accept the entire suggestion with Tab, or only part of the suggestion with Ctrl+RightArrow. You can switch between suggestions in the suggestion toolbar, or use the keyboard shortcut ⌥] (Windows, Linux Alt+]) instead.
If you don't want to accept any of the suggestions, you can continue typing, and Copilot will continue providing suggestions as you work.
There are things you can do to help ("prompt") Copilot give you the best possible suggestions. And the good news is that you are probably already doing these right now since they help you and your colleagues understand your code.
Copilot suggestions work best when Copilot has sufficient context to know what you're doing and what you want help with. Just as you would provide a colleague with the context when asking for help with a specific programming task, you can do the same with Copilot.
Note: "Prompt engineering" is a common phrase you'll hear when discussing AI and refers to how and what information is packaged and sent to an AI API endpoint. The Copilot extension does this "prompt engineering" for you but you can help by providing hints to guide the extension.
Copilot looks at the current and open files in your editor to analyze the context and create appropriate suggestions. Having related files open in VS Code while using Copilot helps set this context and lets the Copilot see a bigger picture of your project.
Just as you would give a brief, high-level introduction to a coworker, a top level comment in the file you're working in can help Copilot understand the overall context of the pieces you will be creating.
It's best to manually set the includes or module references you need for your work. Copilot can make suggestions, but you likely know best what dependencies you'll need to include. This can also help let Copilot know what frameworks, libraries, and their versions you'd like it to use when crafting suggestions.
Just as a method called fetchData()
won't mean much to a coworker (or you after several months), fetchData()
won't help Copilot either. Using meaningful function names will help Copilot provide a body that does what you want.
A function name can only be so descriptive without being overly long so function comments can help fill in details that Copilot might need to know.
One trick to get Copilot on the right page is to copy and paste sample code that is close to what you are looking for. Providing a small example can help Copilot generate suggestions that match the language and tasks you want to achieve. Once Copilot begins providing you with the code you want and will actually use, you can delete the sample code from the file. This can be especially helpful to jump start Copilot to a newer library version when it defaults to the providing older code suggestions.
Copilot is going to latch on to your code to generate suggestions that follow the existing pattern so the adage "garbage in, garbage out" applies.
Keeping a high quality bar can take discipline when you're coding fast and loose to get something working and you might want to disable Copilot completions while in "hacking" mode. You can temporarily disable completions from the Copilot status menu. Bring up the Copilot status menu dropdown by selecting the Copilot status bar item.
From the dropdown, you can disable completions entirely or just for the active file type, for example Markdown files.
If you'd like to learn more about productively using GitHub Copilot, you can follow up with these videos and blog posts:
In addition to inline suggestions, you can also get assistance from Copilot via a chat interface. This is supported in several ways:
The Chat features are available by installing the additional GitHub Copilot Chat extension.
When developing a project or learning something new, it can be a big help to get AI assistance on your questions, big or small. Copilot enables an interactive Chat experience that understands the context of your code, workspace, extensions, settings, and more.
You can access the Chat view via the Activity Bar:
Like other views in VS Code, you can move it anywhere. For example, you can move it to the Secondary side bar so that you can use other views like the Explorer at the same time:
Copilot will suggest potential questions to get started. You can select any of these questions or use the chat box to type your own:
As you continue asking questions, Copilot maintains the history of your conversation, and it'll provide related follow-up questions or commands in its response too.
You can help Copilot provide better answers by upvoting or downvoting responses with the thumbs up and down icons in the upper right of its response. This provides Copilot feedback on how much it helped with your scenario so that it can help you even better in the future.
To make it easy to work with the Chat view, there are several keyboard shortcuts:
To further help Copilot give you more relevant answers, you can indicate the scope and intent of your question through agents and slash commands.
Agents are like experts who have a specialty that they can help you with, and you can talk to them in the chat by mentioning them with the @
symbol. Currently, there are two agents:
@workspace
has context about the code in your workspace and can help you navigate it, finding relevant files or classes.@vscode
knows about commands and features in the VS Code editor itself, and can help you use them.You can prepend your chat inputs with a specific agent to help Copilot give you a more relevant response.
Agent can also support slash commands for specific types of questions or tasks. For example, @workspace /explain
can be used to ask Copilot to explain a file or code selection in the context of your open workspace. To see the available agents and slash commands, type /
for a list.
In addition to agent and slash command combinations, there are general purpose slash commands for actions such as clearing the chat session or getting help.
Depending on your question, Copilot Chat may return source code in a code block.
Hovering over the code block presents options to Copy and Insert at Cursor (⌃Enter (Windows, Linux Ctrl+Enter)).
The More Actions (...
) button also displays options to Insert Into New File and Insert into Terminal (⌃/ (Windows, Linux Ctrl+/)).
If Copilot Chat detects that a code block contains a command, you can run it directly in the integrated terminal with Run in Terminal ⌃/ (Windows, Linux Ctrl+/). This option will create or open the active terminal and insert the command text, ready for you to run.
By default, the Chat view is displayed in the Primary side bar but like other views in VS Code, you can drag and drop it anywhere. For example, you could drag and drop the Chat view into the Panel region:
You can also open the Chat view in the editor region for a larger display area. From the Chat view title bar More Actions (...
) menu, select Open Session in Editor.
Just like any open editor, you can move editor-hosted Chat views into separate Editor Groups and use display customizations such as Grid layout to have multiple chat sessions open in the editor region.
To move the Chat view back to the side bar, use the Open Session in Side Bar command in the editor title bar when the Chat view is the active editor.
An additional key functionality of Copilot is answering questions inline as you're coding. This allows you to harness the power of AI while staying in your existing editor workflow.
In any file, you can press ⌘I (Windows, Linux Ctrl+I) on your keyboard to bring up Copilot inline chat:
You can ask Copilot questions that emerge as you write and iterate on code, such as "Explain this piece of code" or "How do I add functionality to do X?" If you have code selected in the editor, Copilot will scope your question to the selection.
Several slash commands also work in inline chat such as /explain
to ask Copilot to explain a block of code or /test
to generate unit tests.
A useful command is /fix
, which analyzes the error line or selected code and proposes a fix in a diff view for your review. After reviewing and possibly modifying the generated code, you can choose to Accept or Discard the fix.
If you want to ask Copilot a quick question and don't want to start a full Chat view session or have inline Chat open in your editor, you can use the Quick Chat dropdown. To open Quick Chat, you can run Chat: Open Quick Chat or use the ⇧⌘I (Windows Ctrl+Shift+I, Linux Ctrl+Shift+Alt+I) keyboard shortcut.
You can type questions, scope your questions with agents and slash commands such as @workspace /explain
and @vscode
, and promote the discussion to a full Chat view session with the Open in Chat View button in the upper right of the dropdown.
To make it easier to use Copilot Chat features, there is a Copilot menu group in the editor context menu. Right-click in the editor and navigate to Copilot to see the available options:
You can apply these smart actions on the current file or a selection in the file. Choosing an action, brings up the appropriate agent and/or slash command in the Chat view or inline chat. For example, selecting Generate Docs for a function will open the inline chat with a proposed documentation comment:
In addition to inline completions and chat, GitHub Copilot can help with other development tasks and workflows. For example, Copilot can help with writing commit messages, fixing errors, and finding commands.
When Copilot can help with a task or workflow, VS Code displays a sparkle icon. Hovering over the sparkle icon will describe the Copilot action.
Copilot can help you write GitHub commit messages. In the Source Control message input box, select the sparkle button at the right and Copilot will create a commit message based on your pending changes.
If you using the GitHub Pull Request and Issues extension, there is a sparkle button to fill in both the title and description in the Pull Request Create view.
When a command fails to run in the terminal, Copilot displays a sparkle in the gutter that offers a Quick Fix to explain what happened.
Selecting Explain using Copilot will populate the Chat view with the @workspace /explain
agent and slash command to help correct the last terminal command error.
When trying to find a command in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), if you don't think you see the command you want, you can run Ask GitHub Copilot with your search term.
The Ask GitHub Copilot command will open the Chat view and input your search term.
Congratulations, you've now used artificial intelligence to enhance your coding!
You can read more about 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 as well as programming-specific videos for using Copilot with Python, C#, Java, PowerShell, and more.
Check each requirement if Copilot Chat doesn't work:
If you've moved the Chat view out of the Primary side bar, for example, you dragged the view to the Secondary side bar, the Chat view icon will no longer be displayed on the Activity bar. If you close the Secondary side bar, the Chat view won't be visible and it may appear that you've lost access to the Chat view.
There are several ways to display the Chat view or restore it back to the Activity bar:
As with any view, you can drag and drop the Chat view back to the Activity bar or use Reset Location from the view title bar context menu.
You can temporarily deactivate Copilot from the Status bar. You will be prompted whether you want to disable Copilot for all code (globally) or just the programming language detected in the active editor (for example, Python).
You can give feedback on Copilot inline suggestions and responses in the GitHub Copilot Discussions.
If you would like to provide feedback on the Copilot Chat features, you can create issues in the vscode-copilot-release repository.
Yes, you can switch to the pre-release (nightly) version of a Copilot extension to try the latest features and fixes. From the Extensions view, right-click or select the gear icon to bring up the context menu and select Switch to Pre-Release Version:
You can tell if you're running a pre-release version by the "Pre-release" badge in the extension details: