|
| 1 | +--- |
| 2 | +title: 'Scope context with references' |
| 3 | +description: Use references to set context and get better answers in GitHub Copilot Chat. |
| 4 | +ms.date: 7/16/2025 |
| 5 | +ms.topic: how-to |
| 6 | +author: anandmeg |
| 7 | +ms.author: meghaanand |
| 8 | +ms.manager: mijacobs |
| 9 | +ms.subservice: ai-tools |
| 10 | +ms.collection: ce-skilling-ai-copilot |
| 11 | +helpviewer_keywords: |
| 12 | + - copilot chat context |
| 13 | + - context, copilot chat |
| 14 | +monikerRange: '>= vs-2022' |
| 15 | +--- |
| 16 | +# Manage context with references |
| 17 | + |
| 18 | +You can ask [**GitHub Copilot Chat**](visual-studio-github-copilot-chat.md) to give you code suggestions, explain code, generate unit tests, and suggest code fixes. In addition to your prompt, Copilot uses additional context, like the code in your current file and the chat history, to generate a response. |
| 19 | + |
| 20 | +In this article, you learn how to get better answers by providing more information to Copilot Chat: |
| 21 | ++ Scope the chat to specific files using [references](#reference). |
| 22 | ++ Review the [source used](#find-context) by Copilot to generate the answer. |
| 23 | ++ Use different [threads](#threads) for each of your Copilot chats so you can maintain different contexts in each. |
| 24 | + |
| 25 | +## <a name="reference"></a>Reference: scope Copilot results to a particular file or entire solution |
| 26 | + |
| 27 | +You can ask your coding related questions in natural language and GitHub Copilot Chat will answer these in the context of the codebase open in Visual Studio. With references you can get more specific about the information you want Copilot to consider when answering your question. |
| 28 | + |
| 29 | +By selecting a specific context in your codebase, you're able to form better questions easily without having to write out or paste long pieces of information. Specifying the context also enables Copilot to provide you with more relevant answers. |
| 30 | + |
| 31 | +### Reference a file |
| 32 | + |
| 33 | +To easily reference a file in GitHub Copilot Chat, simply add a *#* symbol at the beginning of the file name. For example, if you have a file named *BasketService.cs*, refer to it in the chat as *#BasketService.cs*. |
| 34 | + |
| 35 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-context-hash-reference.png" alt-text="Screenshot of references in Copilot Chat."::: |
| 36 | + |
| 37 | +### Reference a method, class, or function |
| 38 | + |
| 39 | +With [Visual Studio 2022 version 17.11](/visualstudio/releases/2022/release-notes), you can now reference a specific method, class, or function in GitHub Copilot Chat. |
| 40 | + |
| 41 | +To easily reference a method, class, or function in GitHub Copilot Chat, simply add a *#* symbol at the beginning of the method, class, or function name. For example, if you have a method named *BasketAddItem*, refer to it in the chat as *#BasketAddItem*. |
| 42 | + |
| 43 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-references-methods.png" alt-text="Screenshot of references to methods in GitHub Copilot Chat in Visual Studio."::: |
| 44 | + |
| 45 | +### Reference the entire solution |
| 46 | + |
| 47 | +Use *@workspace* to refer to the solution active in the IDE for context. When using *@workspace* for context, Copilot Chat leverages the information about the files, projects, and configurations that are currently open and being worked on within your IDE. This enables Copilot Chat to provide more relevant and context-aware suggestions and answers. |
| 48 | + |
| 49 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-context-at-workspace.gif" alt-text="Screenshot of referencing solution context in Copilot Chat."::: |
| 50 | + |
| 51 | +With Visual Studio 2022 version 17.11, [GitHub Copilot Enterprise](https://docs.github.com/en/enterprise-cloud@latest/copilot/about-github-copilot/subscription-plans-for-github-copilot) subscribers can now use `@github` in chat to include context from their entire repository and to search the web (if [search is enabled by your admin](https://docs.github.com/en/enterprise-cloud@latest/copilot/managing-copilot/managing-copilot-for-your-enterprise/managing-policies-and-features-for-copilot-in-your-enterprise#give-copilot-access-to-bing)). To learn more about the collection of GitHub-specific skills that Copilot can use to answer your question when using `@github`, see [Using GitHub skills for Copilot](https://docs.github.com/en/enterprise-cloud@latest/copilot/using-github-copilot/asking-github-copilot-questions-in-your-ide?tool=visualstudio#using-github-skills-for-copilot-preview). |
| 52 | + |
| 53 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-context-at-github.png" alt-text="Screenshot of using GitHub skills in Copilot Chat."::: |
| 54 | + |
| 55 | +### Reference output window |
| 56 | + |
| 57 | +You can now use the output window as context in chat to ask questions and get help with output logs. Supported output windows include Build, Debug, Tests, Source Control, Package Manager, or any other active output window pane. |
| 58 | + |
| 59 | +Reference output logs in chat in one of the following ways: |
| 60 | + |
| 61 | +- Use *#output* to reference it directly in chat. |
| 62 | +- Select the ➕ icon in the chat input and add `Output logs` as context. |
| 63 | +- Ask Copilot directly, for example, *Check my output logs and help me fix this error*. |
| 64 | +- Right-click in the **Output Window** and select **Explain with Copilot** to attach it. |
| 65 | + |
| 66 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-context-output-window.png" alt-text="Screenshot of output window as context in Copilot Chat."::: |
| 67 | + |
| 68 | +### Usage examples |
| 69 | +Here are some examples of using references for context control: |
| 70 | + |
| 71 | +| **Example** | **Context used by Copilot to form the question** | |
| 72 | +|---------------------------|:--------------------:| |
| 73 | +| What is the purpose of #MyFile.cs: 66-72?| Exact section of the file | |
| 74 | +| Where are the tests in #BasketService.cs?| BasketService.cs | |
| 75 | +| /explain the #AddItemToBasket in #BasketService.cs| AddItemToBasket method in BasketService.cs | |
| 76 | +| Is there a delete basket method in this @workspace| Current solution open in the IDE | |
| 77 | +| I have a test method named #TestCalculator. How can I ensure that it's being executed correctly?| TestCalculator method | |
| 78 | +| Could you explain the differences between classes #BasketService and #OrderService?| BasketService class and OrderService class | |
| 79 | +| In my @workspace where is #AddItemToBasket? | Current solution open in the IDE | |
| 80 | + |
| 81 | +## <a name="find-context"></a>Review the sources used by Copilot Chat |
| 82 | + |
| 83 | +Copilot Chat displays the context it used after every result, so that you can tell what was taken into account when answering your question. When you ask a Copilot Chat a question and get a response in the chat window, a **References** dropdown appears below the response. The entries in the **References** dropdown list show you the context referenced by Copilot Chat to generate that response. This information can help you modify your question to get better and more relevant answers. |
| 84 | + |
| 85 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-references-used-dropdown.png" alt-text="Screenshot of References used dropdown in Copilot Chat." lightbox="media/vs-2022/copilot-chat-context/copilot-chat-references-used-dropdown.png"::: |
| 86 | + |
| 87 | +## <a name="threads"></a>Organize: isolate chats with Copilot into threads |
| 88 | + |
| 89 | +If you’re using Copilot Chat extensively to ask questions as you code, you can organize your conversations in a way that keeps them on-topic. Copilot Chat for Visual Studio now provides an easy way to start new conversations (threads) to keep them focused on the task at hand, and keep the context clear so the answers are based on relevant history. |
| 90 | + |
| 91 | +### <a name="new-thread"></a>New chat thread |
| 92 | + |
| 93 | +Select **Create new thread** or <kbd>Ctrl</kbd>+<kbd>N</kbd> in the chat window to start a new thread. |
| 94 | + |
| 95 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-new-thread-conversation.png" alt-text="Screenshot of Create new thread icon in Copilot Chat."::: |
| 96 | + |
| 97 | +### <a name="switch-thread"></a>Switch chat thread |
| 98 | + |
| 99 | +You can select between multiple ongoing threads to provide the right historical context for your question. You can use <kbd>Ctrl</kbd>+<kbd>PgDown</kbd> for previous thread or <kbd>Ctrl</kbd>+<kbd>PgUp</kbd> for next thread in the chat window. <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>T</kbd> expands the thread dropdown. |
| 100 | + |
| 101 | +:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-switch-threads.png" alt-text="Screenshot of switching between ongoing threads in Copilot Chat."::: |
| 102 | + |
| 103 | +### <a name="promote-inline"></a>Promote inline chat to the chat window |
| 104 | + |
| 105 | +With [Visual Studio 2022 version 17.11](/visualstudio/releases/2022/release-notes), you can now preserve the history of your [inline chat](visual-studio-github-copilot-chat.md#ask-questions-in-the-inline-chat-view) by promoting it to the [chat window](visual-studio-github-copilot-chat.md#ask-questions-in-the-chat-window). Select **Continue in chat window...** to maintain a record and context of the conversation, and continue in the chat window. |
| 106 | + |
| 107 | +:::image type="content" source="media/vs-2022/copilot-chat-context/promote-inline-chat-to-chat-window.png" alt-text="Screenshot of promoting ongoing thread in inline chat to the chat window."::: |
| 108 | + |
| 109 | +### Best practices |
| 110 | + |
| 111 | +Copilot Chat uses the chat history to get context about your request. To give Copilot only the relevant history: |
| 112 | + |
| 113 | +* Use threads to start a new conversation for a new task. |
| 114 | +* Delete requests that are no longer relevant or that didn’t give you the desired result. |
| 115 | + |
| 116 | +Keep the chat conversation open and continue to iterate and prompt Copilot to improve the suggested solution. Copilot has both the context of the generated code and your current conversation history. As you keep asking additional questions, Copilot further refines the response according to your requirements. See [Prompt engineering for GitHub Copilot](https://docs.github.com/en/copilot/using-github-copilot/prompt-engineering-for-github-copilot) for strategies on effective prompting to improve your Copilot results. |
| 117 | + |
| 118 | +## Next steps |
| 119 | + |
| 120 | +- [GitHub Copilot experience for Visual Studio](visual-studio-github-copilot-extension.md) |
| 121 | +- [GitHub Copilot Chat experience for Visual Studio](visual-studio-github-copilot-chat.md) |
| 122 | +- [GitHub Copilot Trust Center](https://resources.github.com/copilot-trust-center/) |
| 123 | +- [Send us suggestions, feedback, and issues](how-to-report-a-problem-with-visual-studio.md) |
| 124 | +- [Support for GitHub Copilot Chat](https://support.github.com) |
| 125 | +- [How to use GitHub Copilot: Prompts, tips, and use cases](https://github.blog/developer-skills/github/how-to-write-better-prompts-for-github-copilot/) |
0 commit comments