CoreMesh

GitHub Copilot Chat Commands: A Cheat Sheet With Examples

Every GitHub Copilot Chat slash command, chat variable and participant from the official cheat sheet, with examples of when each one helps.

GitHub Copilot Chat Commands: A Cheat Sheet With Examples

GitHub Copilot Chat has three kinds of commands. Slash commands (/) run a common task like /tests or /fix. Chat variables (#) attach context such as #file or #selection. Chat participants (@) hand your question to a specialist such as @terminal or @vscode.

Which ones you get depends on where you use Chat: the GitHub website, Visual Studio Code, Visual Studio, JetBrains or Xcode. GitHub's docs say the available slash commands vary with your environment and the context of the chat. Type / in the prompt box to see the live list for your setup.

GitHub Copilot Chat commands at a glance#

Prefix What it is Example Where the cheat sheet lists it
/ Slash command for a common task /tests All environments
# Chat variable that adds context #selection VS Code (variables), Visual Studio (file references)
@ Chat participant (a domain expert) @terminal VS Code
@ Mention that attaches items @ then pick an issue GitHub website

The @ symbol does two jobs depending on the environment. On the GitHub website it attaches items such as discussions, extensions, files, issues, pull requests and repositories. In VS Code it picks a participant.

Copilot Chat slash commands list by environment#

Slash commands exist so you don't have to write a long prompt for a routine job. Type / followed by the command name. Here is what the official cheat sheet lists for each environment.

Visual Studio Code#

Command What it does
/clear Start a new chat session
/explain Explain how the code in your active editor works
/fix Propose a fix for problems in the selected code
/fixTestFailure Find and fix a failing test
/help Quick reference and basics of using GitHub Copilot
/new Create a new project
/tests Generate unit tests for the selected code

Visual Studio#

Command What it does
/doc Add a documentation comment for this symbol
/explain Explain how the code in your active editor works
/fix Propose a fix for problems in the selected code
/help Quick reference and basics of using GitHub Copilot
/optimize Analyze and improve running time of the selected code
/tests Generate unit tests for the selected code

JetBrains#

Command What it does
/explain Explain how the code in your active editor works
/fix Propose a fix for problems in the selected code
/help Quick reference and basics of using GitHub Copilot
/tests Generate unit tests for the selected code
/chronicle Review and analyze your session history. Subcommands: standup, tips, search, improve
/compact Manually compress the current Copilot CLI session context
/remote Copilot CLI session only: enable or manage remote control so you can reach the session from GitHub.com or GitHub Mobile

The last three only apply if you run interactive Copilot CLI sessions inside JetBrains.

Xcode#

Command What it does
/doc Generate documentation for this symbol
/explain Provide an explanation for the selected code
/fix Suggest fixes for code errors and typos
/simplify Simplify the current code selection
/tests Create a unit test for the current code selection

GitHub website#

Command What it does
/clear Clear conversation
/delete Delete a conversation
/new Start a new conversation
/rename Rename a conversation

Notice that /new and /clear mean different things on the website and in VS Code. On the website /new starts a new conversation. In VS Code it creates a new project. Check the table for your environment before you rely on a name you remember from somewhere else.

Which slash command for which job#

The list is short, so picking is mostly about matching the task to the verb.

  • You don't understand a block of code. Use /explain. Select the code first or keep the file active in the editor.
  • Something is broken in a selection. Use /fix. It proposes a fix for problems in the selected code.
  • A test is red. In VS Code, /fixTestFailure is aimed at exactly that: find and fix a failing test.
  • You need tests. /tests generates unit tests for the selected code. That answers the common search for a slash command to generate unit tests. It's listed in VS Code, Visual Studio, JetBrains and Xcode.
  • Code is slow. In Visual Studio, /optimize analyzes and improves the running time of the selected code.
  • Undocumented symbol. /doc works in Visual Studio and Xcode.
  • Too much code. /simplify is Xcode only in this cheat sheet.

A habit I'd recommend: select the exact code first, then type the command. The test and fix descriptions both say "selected code", so a precise selection gives the command less to guess at.

You can still add your own words after a command. Something like /tests followed by a sentence about which cases you care about is a normal way to steer it. The cheat sheet doesn't document specific arguments, so treat that as a plain prompt addition, not a formal syntax.

Chat variables: add context with#

Chat variables put specific context into your prompt. Type # in the prompt box, then the variable. These are the ones the cheat sheet lists for VS Code:

Variable What it includes
#block The current block of code
#class The current class
#comment The current comment
#file The current file's content
#function The current function or method
#line The current line of code
#path The file path
#project The project context
#selection The currently selected text
#sym The current symbol

Pick the narrowest one that still contains what the question needs. If you're asking about one method, #function says so more precisely than #file. A few examples:

text
Why would #function return null here?
Summarize what #class is responsible for.
What does #selection do when the input is empty?

References in Visual Studio#

Visual Studio uses # differently. By default Chat references the file you have open or the code you selected, and you can add # followed by a file name, file name with line numbers, or solution:

text
Where are the tests in #MyFile.cs?
How are these files related #MyFile.cs #MyFile2.cs
Explain this function #MyFile.cs: 66-72
Is there a delete method in this #solution?

The file-and-lines form is useful when a file is long and only one range matters.

Chat participants: pick a specialist with @#

Participants are described as domain experts. Type @ in the prompt box to see which are available. The cheat sheet lists these for VS Code:

Participant Use it for
@azure Azure services and how to use, deploy and manage them. Public preview and subject to change
@github GitHub-specific Copilot skills
@terminal Context about the VS Code terminal shell and its contents; helps create or debug terminal commands
@vscode VS Code commands and features
text
@terminal how do I list files larger than 100 MB?
@vscode how do I change the default formatter?

This is the nearest thing to a "Copilot chat command line" question the pack answers: @terminal helps you write and debug shell commands, but it's a participant in the editor chat, not a separate CLI. Copilot CLI sessions appear in the pack only through the JetBrains commands above.

Mentions and MCP skills on the GitHub website#

On github.com, @ attaches context to the conversation: discussions, extensions, files, issues, pull requests and repositories. That's handy when you want to ask about a particular pull request without pasting it.

The cheat sheet also lists MCP skills such as create_branch, push_files, merge_pull_request, get_me and search_users. You don't type the skill name. You describe the task and Copilot Chat picks the skill, for example:

text
Create a new branch called [BRANCH-NAME] in the repository [USERNAME/REPO-NAME].

Be careful with prompts that write or merge. merge_pull_request really does what it says, so read the PR number twice before you send it.

Custom commands and what the docs don't cover#

People search for custom slash commands a lot. The cheat sheet only documents the built-in ones, so I won't describe a setup for custom commands here. Check the current GitHub Copilot documentation on docs.github.com for what your editor supports. Options change quickly.

Try it: check a command against your environment#

This small script holds the cheat sheet data and tells you where a command is listed. Edit the ask array to try your own.

javascript
const commands = {
  'VS Code': ['clear', 'explain', 'fix', 'fixTestFailure', 'help', 'new', 'tests'],
  'Visual Studio': ['doc', 'explain', 'fix', 'help', 'optimize', 'tests'],
  'JetBrains': ['chronicle', 'compact', 'explain', 'fix', 'help', 'remote', 'tests'],
  'Xcode': ['doc', 'explain', 'fix', 'simplify', 'tests'],
  'GitHub website': ['clear', 'delete', 'new', 'rename'],
};

const ask = ['tests', 'optimize', 'simplify', 'new', 'refactor'];

for (const name of ask) {
  const where = Object.entries(commands)
    .filter(([, list]) => list.includes(name))
    .map(([env]) => env);
  console.log(`/${name}: ${where.length ? where.join(', ') : 'not in the cheat sheet'}`);
}

And a quick check that the # variables in a prompt are ones the VS Code list knows:

javascript
const known = ['block', 'class', 'comment', 'file', 'function', 'line', 'path', 'project', 'selection', 'sym'];
const prompt = 'Explain #function and compare it with #selection and #scope';

for (const match of prompt.matchAll(/#(\w+)/g)) {
  const ok = known.includes(match[1]);
  console.log(`#${match[1]}: ${ok ? 'listed' : 'not in the VS Code list'}`);
}

Common mistakes and gotchas#

  • Assuming a command exists everywhere. /optimize is listed only for Visual Studio, /simplify only for Xcode, /fixTestFailure only for VS Code. If a command is missing, type / and read the live list.
  • Same name, different meaning. /new and /clear behave differently on the website and in VS Code, as covered above.
  • Forgetting the selection. /fix and /tests act on selected code. Without a selection you're leaving the scope to chance.
  • Over-attaching context. #file when you only mean #function adds noise to the prompt.
  • Mixing up @. On the website it attaches items. In VS Code it picks a participant.
  • Trusting a cached cheat sheet. Command lists change. The source below is the place to confirm.

Quick reference checklist#

  1. Type / to see the commands your environment actually offers.
  2. Select the code, then run /explain, /fix or /tests.
  3. Add #function, #selection or #file when the default context isn't enough.
  4. Type @ to pick a participant (VS Code) or attach an item (GitHub website).
  5. On the website, use /new, /rename, /delete and /clear to manage conversations.
  6. Re-check the official Copilot Chat cheat sheet before you build habits around a command.

Quick answers

What is the slash command to generate unit tests in Copilot Chat?

Use /tests with the code selected. The cheat sheet lists it for VS Code, Visual Studio, JetBrains and Xcode, and describes it as generating unit tests for the selected code.

Where can I see the full list of Copilot slash commands?

Type / in the chat prompt box of the environment you're using. The docs say available commands vary by environment and chat context, so that live list is the accurate one.

Can I create custom Copilot slash commands?

The Copilot Chat cheat sheet only documents built-in commands. Check the current Copilot documentation on docs.github.com for what your editor supports.

What's the difference between /, # and @ in Copilot Chat?

/ runs a slash command for a common task, # adds context such as a file or selection, and @ picks a chat participant in VS Code or attaches items like issues and pull requests on the GitHub website.

Did this solve it?

One tap. No account.

Saved you an hour? Send a tip.

USDC or ETH on Base, Ethereum, Arbitrum and more. Keeps the notes free and the examples running.

Base

Network

0xc783bc5c3fa14cEC3f09A22284bC91C5AF0d59e1
Open in wallet · 5 USDC

On a computer? Scan the code with your phone wallet, or copy the address.

Pick the network your wallet or exchange uses. USDC works on all six; ETH on Base, Ethereum, Arbitrum and Optimism. Don't send on Tron or Solana: this address doesn't exist there. Tips are optional and unlock nothing; every guide stays free.

Discussion

Start the discussion

`code` and ``` blocks work

No account needed. Comments are read before they show up, usually the same day. Your email is never asked for.

Indra Wijaya

Builds and runs AI agents, bots and content pipelines, and writes down what works and what broke.

About · Email · RSS

Keep reading

New notes, no spam.

One post at a time, only when there's something worth reading. Follow in any feed reader.

Subscribe via RSS