A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://code.visualstudio.com/docs/copilot/chat/copilot-chat-context below:

Manage context for AI

Manage context for AI

By providing the right context, you can get more relevant and accurate responses from the AI in VS Code. In this article, you learn how to manage context in chat, including how to use #-mentions to reference files, folders, and symbols, how to reference web content, or how you can use custom instructions to guide the AI's responses.

Implicit context

VS Code automatically provides context to the chat prompt based on your current activity. The following information is implicitly included in the chat context:

If you're using agent mode, the agent tools automatically determine if the active file needs to be added to the chat context.

#-mentions

In chat, you can explicitly refer to context by typing # followed by the context item you want to mention. This enables the AI to provide more relevant responses based on the specific context you are referring to.

Type the # symbol in the chat input field to see a list of available context items.

To reference a specific workspace file, folder, or code symbol, type # followed by the file name, folder name, or symbol name. Learn more about referencing files and folders in chat.

Alternatively, choose from the list of available predefined context items like #changes to get the diffs of changed files, or #codebase to perform a codebase search for your workspace.

Make sure to enable the github.copilot.chat.codesearch.enabled (preview) setting to get the best results.

View the full list of supported context items in the Chat Variables section of the cheat sheet.

Prompt examples

The following examples show how to use #-mentions in your chat prompts:

Reference your pending source control changes Understand the codebase Generate code that is consistent with your codebase Fix issues in the workspace Get information about extensions Reference content from the web Add files as context

To let the AI automatically find relevant files and symbols in your workspace, you can use #codebase. To provide specific files, folders, or symbols as context, add them to the chat using the following methods:

Note

If possible, the full contents of the file will be included when you attach a file. If that is too large to fit into the context window, an outline of the file will be included that includes functions and their descriptions without implementations. If the outline is also too large, then the file won't be part of the prompt.

Perform a codebase search

Instead of adding individual files manually, you can let VS Code find the right files from your codebase automatically. This can be useful when you don't know which files are relevant to your question.

Add #codebase in your prompt or select Add Context > Tools > codebase to enable code search for your workspace.

The following prompt examples show how to use codebase search:

Make sure to enable the github.copilot.chat.codesearch.enabled (preview) setting to get the best results.

Reference web content

You can reference content from the web in your chat prompts, for example to get the latest API reference or code examples.

Chat in VS Code has several built-in tools and you can further extend it with tools from MCP servers or extensions. For example, the #fetch tool is a built-in tool that allows you to fetch content from a web page. You can also group tools into tool sets, which you can then reference in your chat prompts.

To reference a tool or tool set directly in your chat prompt, type # followed by the tool (set) name and optional tool parameters. The following prompt examples show how to use tools:

@-mentions

Chat participants are specialized assistants that enable you to ask domain-specific questions in chat. Imagine a chat participant as a domain expert to whom you hand off your chat request and it takes care of the rest.

Chat participants are different from tools that are invoked as part of an agent flow to contribute and perform specific tasks.

You can invoke a chat participant by @-mentioning it: type @ followed by the participant name. VS Code has several built-in chat participants like @vscode, @terminal, or @workspace. They are optimized to answer questions about their respective domains.

The following examples show how to use @-mentions in your chat prompts:

Type @ in the chat input field to see a list of available chat participants.

Extensions can also contribute their own chat participants.

Add elements from the VS Code simple browser (Experimental)

VS Code has a built-in simple browser that you can use to view and interact with a locally-hosted web application, for example to do quick testing and debugging of your web application.

You can add elements from the Simple Browser window as context to your chat prompt. To do this:

  1. Make sure to enable selecting elements from the Simple Browser with the chat.sendElementsToChat.enabled setting.

  2. Run your web application locally.

  3. Open the Simple Browser view by running the Simple Browser: Show command from the Command Palette.

  4. Select the Start button to start selecting elements from the current page.

  5. Hover over the elements of the web page and click to add them to the chat prompt.

    Notice that the selected element is added as context to the current chat prompt.

You can configure which information is included in the context:

Tip

This functionality is also available in the Live Preview extension (pre-release).

Chat history

Chat in VS Code is designed to be a multi-turn conversation. Within a chat session, VS Code uses the history of the conversation as context to your current prompt. This means that you can ask follow-up questions or clarify your previous question without having to repeat the context.

To start over with a new chat session and discard the current context, select the New Chat (+) button (⌘N (Windows, Linux Ctrl+N)) in the Chat view. This can be useful if you want to move to a different topic and avoid the previous context and history.

Learn more about chat history and context management.

Custom instructions

With instruction files, you can provide the AI with common guidelines and rules for generating responses that match your coding style and preferences. Instruction files are Markdown files that you can create in your workspace or in your current profile.

By using instruction files, you can avoid having to repeatedly add common instructions in your chat prompts, and instead have the AI automatically apply these instructions to your chat interactions.

Learn more about using instruction files.

Workspace indexing

VS Code uses an index to quickly and accurately search your codebase for relevant code snippets. This index can either be maintained by GitHub or stored locally on your machine.

The following workspace indexing options are available:

Learn more about workspace indexing.

08/07/2025


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4