You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ide/copilot-chat-context.md
-93Lines changed: 0 additions & 93 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,99 +94,6 @@ In the following example, Copilot interprets the attached image to generate a pl
94
94
95
95
:::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" :::
96
96
97
-
## <aname="reference"></a>Reference: scope Copilot results to a particular file or entire solution
98
-
99
-
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.
100
-
101
-
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.
102
-
103
-
### Reference a file
104
-
105
-
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*.
106
-
107
-
:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-context-hash-reference.png" alt-text="Screenshot of references in Copilot Chat.":::
108
-
109
-
### Reference a method, class, or function
110
-
111
-
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.
112
-
113
-
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*.
114
-
115
-
:::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.":::
116
-
117
-
### Reference the entire solution
118
-
119
-
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.
120
-
121
-
:::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.":::
122
-
123
-
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).
124
-
125
-
:::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.":::
126
-
127
-
### Reference output window
128
-
129
-
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.
130
-
131
-
Reference output logs in chat in one of the following ways:
132
-
133
-
- Use *#output* to reference it directly in chat.
134
-
- Select the ➕ icon in the chat input and add `Output logs` as context.
135
-
- Ask Copilot directly, for example, *Check my output logs and help me fix this error*.
136
-
- Right-click in the **Output Window** and select **Explain with Copilot** to attach it.
137
-
138
-
:::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.":::
139
-
140
-
### Usage examples
141
-
Here are some examples of using references for context control:
142
-
143
-
|**Example**|**Context used by Copilot to form the question**|
| What is the purpose of #MyFile.cs: 66-72?| Exact section of the file |
146
-
| Where are the tests in #BasketService.cs?| BasketService.cs |
147
-
| /explain the #AddItemToBasket in #BasketService.cs| AddItemToBasket method in BasketService.cs |
148
-
| Is there a delete basket method in this @workspace| Current solution open in the IDE |
149
-
| I have a test method named #TestCalculator. How can I ensure that it's being executed correctly?| TestCalculator method |
150
-
| Could you explain the differences between classes #BasketService and #OrderService?| BasketService class and OrderService class |
151
-
| In my @workspace where is #AddItemToBasket? | Current solution open in the IDE |
152
-
153
-
## <aname="find-context"></a>Review the sources used by Copilot Chat
154
-
155
-
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.
156
-
157
-
:::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":::
158
-
159
-
## <aname="threads"></a>Organize: isolate chats with Copilot into threads
160
-
161
-
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.
162
-
163
-
### <aname="new-thread"></a>New chat thread
164
-
165
-
Select **Create new thread** or <kbd>Ctrl</kbd>+<kbd>N</kbd> in the chat window to start a new thread.
166
-
167
-
:::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.":::
168
-
169
-
### <aname="switch-thread"></a>Switch chat thread
170
-
171
-
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.
172
-
173
-
:::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.":::
174
-
175
-
### <aname="promote-inline"></a>Promote inline chat to the chat window
176
-
177
-
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.
178
-
179
-
:::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.":::
180
-
181
-
### Best practices
182
-
183
-
Copilot Chat uses the chat history to get context about your request. To give Copilot only the relevant history:
184
-
185
-
* Use threads to start a new conversation for a new task.
186
-
* Delete requests that are no longer relevant or that didn’t give you the desired result.
187
-
188
-
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.
189
-
190
97
## Next steps
191
98
192
99
-[GitHub Copilot experience for Visual Studio](visual-studio-github-copilot-extension.md)
Copy file name to clipboardExpand all lines: docs/ide/copilot-chat-referencing-context.md
+30-11Lines changed: 30 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: 'Scope context with references'
2
+
title: 'Manage chat context with references'
3
3
description: Use references to set context and get better answers in GitHub Copilot Chat.
4
-
ms.date: 7/16/2025
4
+
ms.date: 7/31/2025
5
5
ms.topic: how-to
6
6
author: anandmeg
7
7
ms.author: meghaanand
@@ -13,26 +13,42 @@ helpviewer_keywords:
13
13
- context, copilot chat
14
14
monikerRange: '>= vs-2022'
15
15
---
16
-
# Manage context with references
16
+
# Manage chat context with references
17
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.
18
+
Scope your questions to [**GitHub Copilot Chat**](visual-studio-github-copilot-chat.md)by using references to get better answer, in addition to its implicit contextual knowledge.
19
19
20
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
21
25
-
## <aname="reference"></a>Reference: scope Copilot results to a particular file or entire solution
22
+
- Understand the implicit context Copilot leverages behind the scenes
23
+
- Scope the chat to specific files using references
24
+
- Review the source used by Copilot to generate the answer
25
+
- Use different threads for each of your Copilot chats so you can maintain different contexts in each
26
+
27
+
## Implicit context
28
+
29
+
Visual Studio automatically provides context to the chat prompt based on your current activity.
30
+
31
+
The following information is implicitly included in the chat context:
32
+
- The currently selected text in the active editor.
33
+
- The file name or notebook name of the active editor.
34
+
35
+
The actual contents of the active file are not included in the context, but are shown as a suggested context item in the chat input box (indicated with italic text and a dotted outline). Depending on your prompt, Visual Studio might decide to read the contents of the active file. To explicitly include the contents of the active file in the chat context, select the suggested file in the chat input box.
36
+
37
+
:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-implicit-context.png" alt-text="Screenshot of implicit context in Copilot Chat.":::
38
+
39
+
## Reference: scope Copilot results
26
40
27
41
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
42
29
43
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
44
45
+
:::image type="content" source="media/vs-2022/copilot-chat-context/copilot-chat-references.png" alt-text="Screenshot of references in Copilot Chat.":::
46
+
31
47
### Reference a file
32
48
33
49
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
50
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.":::
51
+
:::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.":::
36
52
37
53
### Reference a method, class, or function
38
54
@@ -84,9 +100,12 @@ Copilot Chat displays the context it used after every result, so that you can te
84
100
85
101
:::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
102
87
-
## <aname="threads"></a>Organize: isolate chats with Copilot into threads
103
+
## <aname="threads"></a>Organize: manage chat history context with threads
104
+
105
+
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.
88
106
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.
107
+
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.
108
+
Use threads to keep conversations focused on the task at hand, and keep the context clear so the answers are based on relevant history.
0 commit comments