The quality of Copilot's responses in VS Code scales directly with the quality of the context it receives. VS Code gives you multiple mechanisms — implicit signals, #-mentions, @-mentions, vision input, browser elements, and workspace indexing — to ensure the model always has exactly the right information before generating an answer.
Availability: All GitHub Copilot plans including Free.
Workspace indexing
Before your first #codebase query, VS Code builds an index of your repository so it
can surface the most relevant snippets quickly. Three indexing modes are available depending on
your setup:
| Mode | Where the index lives | Best for |
|---|---|---|
| Remote index | GitHub (requires repo to be hosted there) | Large codebases — fast semantic search even on very big repos |
| Local index | Your machine | Accurate results offline; uses advanced semantic algorithms |
| Basic index | Your machine (fallback) | Larger repos when local indexing is unavailable; simpler algorithms |
Implicit context
VS Code automatically passes context to the model based on what you are currently doing. You do not need to mention anything explicitly for these signals to take effect:
- The currently selected text in the active editor.
- The file name or notebook name of the active editor.
- When using the Ask agent, the active file is always included as context.
- When using Agent mode, the model autonomously decides whether to include the active file based on your prompt.
#-mentions — explicit context items
Type # in the chat input to see a picker of all available context items, or
use Add Context in the Chat view. Supported types:
Files, folders, and symbols
Type # followed by the name of a file, folder, or symbol to attach it.
For symbols, the containing file must already be open in the editor.
You can also drag files and folders from the Explorer or Search view directly onto the Chat view.
VS Code includes the full file contents when possible. If the file is too large for the context window, it falls back to a function-level outline. If even that exceeds the limit, the file is omitted.
Codebase search — #codebase
Add #codebase to let VS Code find the right files automatically instead of
picking them manually. Useful when you are not sure which files are relevant:
"Explain how authentication works in #codebase""Where is the database connection string configured? #codebase""Add a new API route for updating the address #codebase"
Agents automatically trigger codebase search when they need more context. You can still
add #codebase explicitly for ambiguous prompts.
Web content — #fetch and #githubRepo
Reference live content outside your local workspace:
-
#fetch <URL>— retrieves the content of a specific web page. VS Code caches the page temporarily; restart VS Code to force a refresh. You will be prompted to approve external URLs the first time to protect privacy. -
#githubRepo <owner/repo>— performs a semantic code search within any public GitHub repository, e.g."How does routing work? #githubRepo vercel/next.js".
Tools
When using agents, tools are invoked automatically. You can also reference a tool explicitly
with its # name, for example "what are my open issues #github-mcp"
to invoke a specific MCP server tool. Referencing a tool set by name makes all tools in that
set available for the current prompt.
@-mentions — chat participants
Chat participants are domain-specific assistants you invoke with @.
Unlike tools (which perform tasks), participants own the entire response for their domain.
VS Code includes three built-in participants:
| Participant | Domain | Example prompt |
|---|---|---|
@vscode |
VS Code settings & UI | "@vscode how to enable word wrapping" |
@terminal |
Shell commands & terminal output | "@terminal what are the top 5 largest files in the current directory" |
@workspace |
Project-level questions | "@workspace where is the main entry point?" |
Extensions can also contribute their own chat participants via the VS Code extension API.
Vision (Preview)
Attach an image as context — a screenshot of code, an error dialog, or a UI sketch — and ask Copilot to explain, debug, or implement it. Drag an image from your browser directly onto the Chat view to attach it.
Add browser elements (Experimental)
VS Code's integrated browser lets you select specific page elements and attach them as context. This is useful for targeting a particular HTML element, CSS rule, or JavaScript component without pasting the entire source:
- Start your web application and open the Integrated Browser from the Command Palette (
Browser: Open Integrated Browser). - Enter the URL of the page.
- Select Add Element to Chat, then hover and click any element to attach it.
Two settings control what is included: chat.sendElementsToChat.attachCSS and
chat.sendElementsToChat.attachImages.
Interact with browser pages (Experimental)
With workbench.browser.enableChatTools set to true, agents can directly
drive the integrated browser: navigate to URLs, read page content and console errors, take
screenshots, click elements, and type text — no external MCP server required. You can also
select Share with Agent in the browser toolbar to hand off an already-open
page, including your existing session and login state.
Monitor context window usage
The chat input box shows a context window control — a shaded bar indicating how much of the model's token budget is currently in use. Hover over it to see the exact count (e.g. 15K / 128K) and a breakdown by category. The denominator changes when you switch models, since different models have different context window sizes.
Context compaction
As a conversation grows, accumulated messages eventually fill the context window. Compaction summarizes earlier messages to free up space while preserving important decisions and details.
| Mode | How it works |
|---|---|
| Automatic | VS Code compacts silently in the background when the window is nearly full — no action needed. |
| Manual |
Type /compact in the chat input (optionally add instructions, e.g.
/compact focus on the database schema decisions), or select
Compact Conversation from the context window control.
Available for local, background, and Claude agent sessions.
|
To reset context entirely, start a new chat session instead of compacting.