Skip to content

Copilot Chat Commands

This page will go over the high-level overview of Copilot Chat commands and context variables. Take a look at the available commands and how to use them to interact with Copilot Chat.

Highly encouraged to use them in your own prompts in the workshop and in your daily use of Copilot Chat.

copilot-chat-commands

Agents

In CoPilot Chat, there are different agents that you can interact with. These agents are used to perform specific actions or provide information to the user. The agents are @workspace, @terminal, and @vscode.

  • @workspace - used to grab context from the workspace. It will scan through the current workspace files and directories to for relevant information to provide an answer based on the prompt given.
  • @terminal - used to grab context from the terminal in VS Code. Useful for asking questions about running commands in the terminal and asking for clarification on an error when executing a command.
  • @vscode - used to grab context from VS Code settings and API. Useful for developing extensions and asking questions about the VS Code API.

Now that that we explained briefly about agents, we can dive into further command that can further help us interact with CoPilot.

Slash Commands

For CoPilot chat there are commands you can use to interact with CoPilot. These commands are prefixed with a / and are used to perform specific actions or get information from CoPilot.

Slash commands use the context of agents to perform actions. Below is a list of agents and the slash commands they support:

Agent Slash Commands
@workspace /new, /explain, /fix, /newNoteBook, /tests
@terminal /explain
@vscode /api, /search
General Use /clear, /help

In the dropdowns below, we will explain the commands listed in the table.

@workspace Slash Commands

The following Slash Commands use the context of the @workspace agent to perform actions. Below is a list of the commands and their descriptions:

/new command is used to scaffold a new project based on prompt created.

For example we can ask CoPilot to create a new golang project like so: basics-new-command

As a note, you can interact with the prompt to look at the files generated by CoPilot before you create a new workspace to develop your project.

The last component of the command response is the button Create Workspace. Clicking on this button will have you select the location on your machine where you want the generated files to be saved.

Once you have selected the location, you will switch over to the new workspace so you can start developing your project.

/explain uses the context of a selected code snippet or file currently opened to provide an explanation on how the code works.

Here is an example showing off the explain command:

basics-explain-command

/fix can be utilized to fix problems with the selected code. It uses the context of the selected code snippet or files currently opened and provides solutions to fix the problems.

For example, we can ask CoPilot to fix the selected code snippet like so:

basics-fix-command

/newNoteBook will create a new Jupyter notebook based on the prompt created.

When generating a new Jupyter notebook, you will receive an outline of the notebook that will be generated.

basics-newNoteBook-command

Once you have reviewed the outline of the notebook, you can click on the Create Notebook button to generate the notebook. Copilot will template the code blocks using Python for the code snippets. The notebook will be generated in the same directory as the file you are working on.

basics-newNoteBook-command-2

/tests will generate test cases for the selected code snippet or file currently opened.

Here is an example showing off the tests command:

basics-tests-command

From there you can take the generated test cases and place them in your test file for testing the code snippet or file you are working on.


@terminal Slash Commands

The following slash commands use the context of the @terminal agent to perform actions.

There is only one command that uses the context of the @terminal agent which is /explain.

/explain will explain anything in context to the terminal. This can be useful for asking questions about running commands in the terminal and asking for clarification on an error when executing a command.

Here is an example showing off the tests command:

basics-terminal-explain-command


@vscode Slash Commands

The following slash commands use the context of the @vscode agent to perform actions.

There is only one command that uses the context of the @vscode agent which is /api. Below is a description of the command:

The /api command is used for asking questions about VS Code extension development.

Here is a snippet response from CoPilot after asking:

@vscode /api How can I start developing an extension for vscode?

basics-api-command

The /search command to generate a query for searching keywords in VS Code.

Here is an example prompt for searching for keywords in VS Code:

basics-search-command

Query search after pushing Search button:

basics-search-query


General Use Slash Commands

/clear command will generate a conversation session with CoPilot. This allows you to quickly start from scratch if the current conversation is not going as expected.

Should you want to refer back to a conversation you can go to the top of the chat and click on the clock icon to view previous conversations.

basics-clear-command

/help is an important command as it will help you reference back to possible commands you can do with CoPilot Chat.

Here is an snippet that CoPilot outputs when prompt /help:

basics-help-command


Context Variables

CoPilot Chat has a feature called context variables that enables you to add more context to help CoPilot understand the prompt better. Context Variables can also be used in inclusion of Slash commands to help bring more context to your prompt.

Here are some of the context variables that can be used in CoPilot Chat:

The #editor context variable is used to point CoPilot to the content of the editor in order to provide context to the prompt for CoPilot to understand better.

By default CoPilot should already have context of the editor from the file opened, but you can use the #editor context variable to point CoPilot to the content of the editor specifically.

basics-editor-variable

The #file context variable is used to point CoPilot to the content of the file. This is useful when you want to get information from the file and ask questions about the file.

For example I can ask CoPilot to explain the content of the file like so:

basics-file-variable

The #selection context variable is used to point CoPilot to the selected text in the editor.

For example, I can ask CoPilot to explain the selected text like so:

basics-selection-variable

The terminalLastCommand context variable is used to point CoPilot to the last command executed in the terminal.

Can be used to ask context on the last command if it errored out or what the command did.

basics-last-command-variable

The TerminalSelection context variable is used to point CoPilot to the selected text in the terminal. For usage of this context variable, you select the text in the terminal via highlighting the text and asking a question based on the context selected.

For example, I can ask CoPilot to explain the selected text in the terminal like so for a ping command ran in the terminal:

basics-terminal-selection-variable