Code Faster and Better with GitHub Copilot’s New Features: Slash Commands and Context Variables

Peter Groenewegen

Have you ever wished you had an AI assistant that could help you write code faster and better? That’s what Visual Studio Copilot Chat offers you: an AI-powered pair programmer that can answer your questions, suggest code snippets, explain code logic, and chat with you about your project. You can use Copilot to code faster and better, as it helps you avoid errors and learn new skills.

We have added two new features to the latest Visual Studio Copilot Chat extension: slash commands (/) that allow you to direct Copilot to perform specific tasks, and context Variables (#) that allow you to specify a file for Copilot to focus its answer on. We also have several preview features you can get a sneak peek on.

Download or update Visual Studio Copilot Chat extension to get the latest features


The ultimate conversational AI assistant for your coding tasks, download the Visual Studio extension.

Compatible with Visual Studio 2022 version 17.8 and higher.

GitHub Copilot is free for verified students and for maintainers of popular open source projects on GitHub. If you are not a student or maintainer of a popular open source project, you can try GitHub Copilot for free with a one-time 30-day trial. After the free trial, you will need a paid subscription for continued use.

Slash commands

Slash commands are special commands that you can use in chat to perform specific actions on your code. For example, you can use:

  • /doc to add a documentation comment
  • /explain to explain the code
  • /fix to propose a fix for the problems in the selected code
  • /generate to generate code to answer your question
  • /help to get help on Copilot Chat
  • /optimize to analyze and improve running time of the selected code
  • /tests to create unit tests for the selected code

Image slash commands 1

Context variables

The context variables feature lets you easily add files from your solution to your questions by using the # symbol. When you reference a file, Copilot can access the file content and answer more specific questions about it. For example, you can ask “How does the #file:Main.cs file work?” or “What is the purpose of the #file:Calculator.cs file?” and get relevant answers from Copilot Chat. You can add multiple files to one question. This feature saves you time and effort by allowing you to include content from your project without copying and pasting.

Image references

You can see the referenced files in the chat under the answers. Just look for the link to the references to see what was added to your question. If you click on the links, it will take you to the included content.

Image references used

Tips & Tricks for GitHub Copilot Chat in Visual Studio:


Get better answers by setting the context for GitHub Copilot in Visual Studio.

Preview features

In addition to the main released feature of Visual Studio Copilot Chat, we also have some exciting preview features that you can try out and give us your feedback. These preview features are experimental and may not work as expected, but they can enhance your development experience with Visual Studio Copilot Chat. Here are some of the preview features and their brief descriptions:

  • Exception Assistant in debugger: Copilot helps you diagnose and fix exceptions in your code. Copilot will provide you with relevant information about the exception, such as the cause, the location, the stack trace, and possible solutions. Ask copilot we an exception happens.
  • Suggestions for breakpoint expressions: Copilot helps you set conditional breakpoints in your code. Copilot will suggest expressions that evaluate to true or false based on the current context of your code.
  • Commit message suggestions: Copilot helps you describe your set of changes by generating a Git commit message. You can then refine the message with “why” the change was made and commit. Generated Commit Message
  • Solution reference: Copilot helps you find and navigate to the references of your code elements in your solution. By using #solution you are letting Copilot know to search your solution for relevant code to the question. These will than automatically added to the context of your question so copilot can use those for answering your question.
  • Suggestions in the Performance Profiler: Copilot helps you optimize the performance of your code. Copilot will analyze the performance data collected by the Visual Studio Performance Profiler and suggest ways to improve the speed, memory usage, and responsiveness of your code.
  • Test failure Analysis: Copilot helps you debug and fix the failures of your unit tests. Copilot will provide you with useful information about the test failure, such as the assertion message, the expected and actual values, the source code, and possible solutions. Ask copilot for test failure analysis.

Enable the Preview features


To enable these preview features, you need to go to Options -> GitHub -> Copilot Chat -> Preview features and check the boxes for the features you want to try and let us know how you experience is.

We want to hear from you!

We appreciate all the feedback you’ve provided so far as we’ve been creating Copilot, and are excited to see where this next wave of AI-assisted productivity takes you as you create great software. Please try the new features and share your feedback – just use Visual Studio Visual Studio “Send feedback” to send us your suggestions, feedback and issues for GitHub Copilot in Visual Studio.

AI-assisted content. This article was partially created with the help of AI. An author reviewed and revised the content as needed. Learn more

23 comments

Comments are closed. Login to edit/delete your existing comments

  • Dalibor Čarapić 2

    Is this only for VS Copilot?
    It is not for VS Code Copilot?

    • Peter GroenewegenMicrosoft employee 3

      The features described in this blog are specific for Visual Studio Copilot. Visual Studio Code Copilot does have its own feature set, when possible, we try to sync on how the features can be used.

      • J.P. Duvet 0

        Github Copilot seems to be a single service with a price plan and supported IDEs/tools. Do you mean that as a paid subscriber of this service, I will not get the full features although I use a supported tool like VS Code? Actually are there as many Github Copilot services as supported IDEs/tools with a shared same price plan?

      • Haoyue XueMicrosoft employee 0

        How can I get the feature set of VS code copilot?

  • Douglas Cunha 3

    Fantastic features! Could you consider adding an option to customize the language for generating commit messages? I collaborate with a team that prefers commit messages in Portuguese.

    • Peter GroenewegenMicrosoft employee 1

      Thank you for your feedback. If the editor is in Portuguese, we should give a response in Portuguese. If that is not the case, can you ask them to create a feedback ticket ‘report an issue’. We ask the model to respond in the local of Visual Studio.

  • Antti T. 3

    I love it. This is the future.
    Sometimes it gets lazy and tries to circulate around the question instead giving the answer, but eventually it normally gives up and spits out what is wanted.
    Perhaps next step would be giving it more monitoring abilities and let it comment without asking, if the programmer is stuck. Not just code completions, but in the chat with explanations and bigger concepts. Little bit in a way where co-worker would be watching over your shoulder.

    Also, add emotions to it and make it joke from time to time. Then bring back the famous Office Paper Clip assistant face. That would make it more fun to work with.

    • Peter GroenewegenMicrosoft employee 2

      I’m glad you enjoy using GitHub Copilot and find it helpful for your programming tasks. I appreciate your suggestions for improving my functionalities and adding more personality to my responses. We will keep them in mind for future updates.

  • Andreas Saurwein 2

    If only the in-editor chat would work… already opened a ticket for this issue (https://developercommunity.visualstudio.com/t/AskCopilot-not-working-in-C-code-windo/10560551)
    The #solution reference will be very handy, also using multiple file references, although it would be nice if it would use automatically all “using” references in the current file or in referenced files, by default.

    I find that /doc is very useful, as long as you dont select too much code, tried to /doc an interface declaration with about 30 methods, failed to respond around 60% through and didnt complete.
    /explain often is very generic and doesnt show much more info than already in the code, just with other words.
    /optimize is giving very scary answers most of the time, rarely something that can be used
    Havent had much luck with /fix either so far.

    All this in C# on VS 2022 Enterprise.

    • Peter GroenewegenMicrosoft employee 2

      Thank you for reporting this, we have done a number of fixes for the focus in the latest version. Can you check you have updated to the latest version of the extension. Than if you still see the issue, can you report that in the open feedback ticket and tell us what extensions you have installed so we can check what is taking the focus away.

      • Andreas Saurwein 0

        Am updating right now to VS2022 Preview 4, lets see if anything changes.
        As for the bug – nothing takes focus away – its impossible to put focus onto the Copilot Chat in-editor window, it just doesnt accept it, clicks go through.

        • Andreas Saurwein 2

          Done, updated and culprit found: Visual Assist from Wholetomato. Lets go testing Copilot Chat further.

  • Benjamin Garrard 3

    Just realized I was mixing up Visual Studio with VSCode after writing my thoughts below, oops 😅.

    I’m genuinely enthusiastic about AI tools in development, especially for VSCode. That said, I’ve been noticing some standout features in other tools that seem to edge out Copilot and Copilot Chat in certain areas. Take Tabnine, for example – their chat for slash commands and documentation generation is super slick. CodiumAI impresses with its testing capabilities and its unique angle as an open-source PR agent. Then there’s Cursor editor, which feels like a beefed-up VSCode with its cool features like Documentation Indexing, Site Crawling, and a Langchain-based debug agent, not to mention the super handy @mentions for code snippets.

    Copilot Chat has been great for inline code suggestions, but when it comes to maintaining a conversation, it feels a bit behind the curve compared to these others. I’ve been trying out Tabnine’s inline suggestions and they’re just as good, if not better, at times. So, I find myself at a crossroads with Copilot. It’s still part of my toolkit because it’s useful in certain scenarios and helps keep my OpenAI API usage down for the simpler stuff. Tabnine is even looking to fine tune custom models on codebases.

    • Rhea PatelMicrosoft employee 2

      Hi Benjamin!
      Thank you for the feedback. I would love to learn more about your experience using Copilot and the conversational aspects. Would you be interested in jumping on a call? If, so please reply with your email and I will organize something.

      Thanks,
      Rhea Patel
      Product Manager for GitHub Copilot in Visual Studio

  • Arman Espiar 5

    Add natural languages other than English to it, such as ChatGPT.

    • cathy Choi 1

      still think I would prefer use ChatGPT, its real smarter

    • Peter GroenewegenMicrosoft employee 1

      Hi Arman,
      The model is instructed to use the language your IDE is in (locale). If you have any thoughts about this or specific case, can you make a feedback ticket in VS and show us how you would like it to work so we can improve on this.
      Thanks Peter [MSFT]

  • Pedersen, Lars 2

    Great stuff.
    Consider adding buttons “Fix, Document, Test” instead of commands.

    Aslo add links to Microsoft docs in the answers.

    Why is ChatGPT often smarter? Sometimes Copilot Chat will just return the code you asked about without comment. ChatGPT never does that.

    • Peter GroenewegenMicrosoft employee 1

      Good that you like it! If you have any examples where we do something else than you have request, can you share those with us in feedback tickets? That enables us to tune our instruction on real examples and adjust it better to your needs.

      Thanks,
      Peter [MSFT]

  • Asher Vaughn Kadmiel 0

    welp i guess skill just got thrown out the window, and this is where i get replaced.

  • Iwan van Ee 0

    Commit message suggestions:

    Is that only working on GitHub repositories?
    I have a repository in DevOps where I want to use this feature as well.

    Using Visual Studio 17.8.6
    And Extension version 0.2.393.21236

    I see those options:
    – Enable AI Exception Assistant in the debugger
    – Enable AI suggestions for breakpoint expressions
    – Enable referencing your #Solutions (currently C# only)
    – Enable suggestions in the Performance Profiler

    But I don’t see an option in the Tools\Options to enable Commit message suggestions.

    • Peter GroenewegenMicrosoft employee 1

      The commit messages are on by default in 0.2.393.21236 (released Feb 2). Check if you see the button when you create a commit message in Visual Studio. If that is not the case, can you create a Feedback Ticket so we can investigate what is going.

      They should work on any git repository.

Feedback usabilla icon