Skip to content

Commit 7bba64e

Browse files
Learn Build Service GitHub AppLearn Build Service GitHub App
authored andcommitted
Merging changes synced from https://github.com/MicrosoftDocs/visualstudio-docs-pr (branch live)
2 parents 48b9672 + 91cf969 commit 7bba64e

14 files changed

+521
-516
lines changed

.openpublishing.redirection.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
{
22
"redirections": [
3+
{
4+
"source_path": "docs/ide/reference/toolbox-data-tab.md",
5+
"redirect_url": "/visualstudio/ide/reference/toolbox",
6+
"redirect_document_id": false
7+
},
8+
{
9+
"source_path": "docs/ide/reference/toolbox-html-tab.md",
10+
"redirect_url": "/visualstudio/ide/reference/toolbox",
11+
"redirect_document_id": false
12+
},
13+
{
14+
"source_path": "docs/ide/reference/toolbox-components-tab.md",
15+
"redirect_url": "/visualstudio/ide/reference/toolbox",
16+
"redirect_document_id": false
17+
},
318
{
419
"source_path": "docs/msbuild/walkthrough-creating-an-inline-task.md",
520
"redirect_url": "/visualstudio/msbuild/msbuild-roslyncodetaskfactory",
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
title: 'Manage chat context with references'
3+
description: Use references to form better questions and get better answers with scoped context in GitHub Copilot Chat.
4+
ms.date: 7/31/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 chat context with references
17+
18+
Scope your questions to [**GitHub Copilot Chat**](visual-studio-github-copilot-chat.md) by using references, in addition to its implicit contextual knowledge, to get better answers.
19+
20+
In this article, you learn how to get better answers by providing more information to Copilot Chat:
21+
22+
+ Understand the [implicit context](#implicit-context) Copilot leverages behind the scenes
23+
+ Scope the chat to specific files using [references](#reference-context)
24+
+ [Attach images](#attach-images) to your prompt to provide additional context and better illustrate your ideas
25+
+ Review the [source](#find-context) used by Copilot to generate the answer
26+
+ Use different [threads](#threads) for each of your Copilot chats to maintain chat history and different context in each
27+
28+
## Prerequisites
29+
30+
To get started using GitHub Copilot Chat in Visual Studio, you need:
31+
+ Visual Studio 2022 [version 17.10](/visualstudio/releases/2022/release-history) or later
32+
+ [Sign in to Visual Studio using a GitHub account](work-with-github-accounts.md) with [Copilot access](https://docs.github.com/en/copilot/about-github-copilot/what-is-github-copilot#getting-access-to-copilot) <br/>
33+
<sup>**</sup> You can sign up for [GitHub Copilot for Free](copilot-free-plan.md).
34+
35+
## Implicit context
36+
37+
Visual Studio automatically provides context to the chat prompt based on your current activity.
38+
39+
The following information is implicitly included in the chat context:
40+
- The currently selected text in the active editor.
41+
- The current file active in the editor.
42+
43+
Depending on your prompt, Copilot reads the contents of the active file. To explicitly include the contents of another file in the chat context, select the suggested file using the `+` button in the chat view to **Add attachment**.
44+
45+
:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-implicit-context.png" alt-text="Screenshot of implicit context in Copilot Chat.":::
46+
47+
## <a name="reference-context"></a>Reference: scope Copilot results
48+
49+
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.
50+
51+
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.
52+
53+
:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-references.png" alt-text="Screenshot of references in Copilot Chat.":::
54+
55+
### Reference a file
56+
57+
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*.
58+
59+
:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-context-hash-reference.png" alt-text="Screenshot of file reference in Copilot Chat.":::
60+
61+
### Reference a method, class, or function
62+
63+
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.
64+
65+
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*.
66+
67+
:::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.":::
68+
69+
### Reference the entire solution
70+
71+
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.
72+
73+
:::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.":::
74+
75+
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).
76+
77+
:::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.":::
78+
79+
## <a name="attach-images"></a>Reference an image
80+
81+
With vision integration for Copilot Chat in Visual Studio 17.14 and later, you can [attach images](visual-studio-github-copilot-chat.md#attach-images-to-chat-prompts) to your chat prompt, providing Copilot with additional context for improved responses. Use images in combination with [scope](#reference-context) and other contextual features such as [slash commands](copilot-chat-context.md#slash-commands) to generate tailored responses.
82+
83+
In the following example, Copilot interprets the attached image to generate a plan and suggest code to create a colorful Breakout game from scratch.
84+
85+
:::image type="content" source="media/vs-2022/visual-studio-github-copilot-chat/example-attach-image-chat.png" alt-text="Screenshot of an example scenario of adding an image in Copilot Chat." lightbox="media/vs-2022/visual-studio-github-copilot-chat/example-attach-image-chat.png" :::
86+
87+
### Reference output window
88+
89+
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.
90+
91+
Reference output logs in chat in one of the following ways:
92+
93+
- Use *#output* to reference it directly in chat.
94+
- Select the ➕ icon in the chat input and add `Output logs` as context.
95+
- Ask Copilot directly, for example, *Check my output logs and help me fix this error*.
96+
- Right-click in the **Output Window** and select **Explain with Copilot** to attach it.
97+
98+
:::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.":::
99+
100+
### Usage examples
101+
Here are some examples of using references for context control:
102+
103+
| **Example** | **Context used by Copilot to form the question** |
104+
|---------------------------|:--------------------:|
105+
| What is the purpose of #MyFile.cs: 66-72?| Exact section of the file |
106+
| Where are the tests in #BasketService.cs?| BasketService.cs |
107+
| /explain the #AddItemToBasket in #BasketService.cs| AddItemToBasket method in BasketService.cs |
108+
| Is there a delete basket method in this @workspace| Current solution open in the IDE |
109+
| I have a test method named #TestCalculator. How can I ensure that it's being executed correctly?| TestCalculator method |
110+
| Could you explain the differences between classes #BasketService and #OrderService?| BasketService class and OrderService class |
111+
| In my @workspace where is #AddItemToBasket? | Current solution open in the IDE |
112+
| Update my UI in App.tsx to resemble this image | Uploaded image |
113+
114+
## <a name="find-context"></a>Review the sources used by Copilot Chat
115+
116+
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.
117+
118+
:::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":::
119+
120+
## <a name="threads"></a>Organize: manage chat history context with threads
121+
122+
As you iterate and send multiple chat prompts in a chat session, Copilot uses the history of chat prompts and responses as context for your current chat prompt. This means that you can ask follow-up questions or clarify your previous question without having to repeat the context. For example, you can ask "How does this differ from ...", "Now add a test case", "explain in more detail", and more.
123+
124+
To start over with a new chat session and discard the current context, start a [new thread](#new-thread) in the chat view. This is useful when you want to move to a different topic and avoid the previous context and history.
125+
Use threads to keep conversations focused on the task at hand, and keep the context clear so the answers are based on relevant history.
126+
127+
### <a name="new-thread"></a>New chat thread
128+
129+
Select **Create new thread** or <kbd>Ctrl</kbd>+<kbd>N</kbd> in the chat window to start a new thread.
130+
131+
:::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.":::
132+
133+
### <a name="switch-thread"></a>Switch chat thread
134+
135+
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.
136+
137+
:::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.":::
138+
139+
### <a name="promote-inline"></a>Promote inline chat to the chat window
140+
141+
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.
142+
143+
:::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.":::
144+
145+
### Best practices
146+
147+
Copilot Chat uses the chat history to get context about your request. To give Copilot only the relevant history:
148+
149+
* Use threads to start a new conversation for a new task.
150+
* Delete requests that are no longer relevant or that didn’t give you the desired result.
151+
152+
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.
153+
154+
## Next steps
155+
156+
- [GitHub Copilot experience for Visual Studio](visual-studio-github-copilot-extension.md)
157+
- [GitHub Copilot Chat experience for Visual Studio](visual-studio-github-copilot-chat.md)
158+
- [GitHub Copilot Trust Center](https://resources.github.com/copilot-trust-center/)
159+
- [Send us suggestions, feedback, and issues](how-to-report-a-problem-with-visual-studio.md)
160+
- [Support for GitHub Copilot Chat](https://support.github.com)
161+
- [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

Comments
 (0)