Copilot Chat context in VS Code can include your active file, current selection, and file name automatically. When the AI must consider other files, folders, symbols, terminal output, or web content, add them explicitly.
The techniques on this page work in both the Chat view and the /vscode/how-to-use-coding-agents-and-the-agents-window-in-vs-code.
#-mentions: add files, folders, and more
Type # in the chat input box. A menu appears showing the types of context you can add. Pick one, then select the specific item.
Common context choices
| Choice | What it adds |
|---|---|
| Files & Folders | Selected workspace files or a folder |
| Symbols | A function, class, variable, or other code symbol |
#codebase | A workspace-wide search for relevant context |
#terminalSelection | Text currently selected in the integrated terminal |
#fetch | Content retrieved from a web URL after approval |
After you select a context type, VS Code shows a quick pick list of matching items. Start typing to filter.
Reference a file
Type #, start entering the file name, and select the matching file. You can also select Add Context and choose Files & Folders. The selected file appears as a context item in the chat input.
You can add multiple files to the same prompt. Each file increases the token count, so the context window indicator in the chat input fills up as you add more.
Reference a code symbol
To add a specific function, class, or variable, first open the file that contains it. Type # and select the symbol, or choose Add Context > Symbols and select it from the picker.
This is useful when you want to ask about one function in a large file without adding the entire file.
Reference terminal output
Select text in the integrated terminal, then type #terminalSelection in your chat prompt. The selected terminal text is added as context. This is useful for pasting error messages or command output into a chat question.
Terminal output can contain tokens, environment values, private paths, or customer data. Check the selection and remove sensitive text before sending the prompt.
Reference the entire codebase
Type #codebase to tell Copilot to search your entire workspace for relevant context. This uses VS Code's workspace indexing to find related files, symbols, and patterns. Use it when your question spans multiple files and you are not sure which files are relevant.
Reference web content
Include a URL directly or use #fetch with the URL to retrieve web content. For example, Summarize the relevant API changes #fetch https://api.example.com/changelog asks the AI to read that page before answering.
VS Code prompts for confirmation before accessing external URLs. The content is cached for a short time to avoid repeated network requests.
Faster ways to add context
Drag and drop
Drag files or folders from the Explorer view, Search view, or editor tabs directly into the chat input. Each dropped item becomes a context chip.
Add Context button
Select Add Context in the Chat view. A picker opens with available context categories, including Files & Folders and Symbols.
Attach images
Attach or drag an image into the Chat view to use vision capabilities. For example, add a UI mockup and ask for an implementation plan. Remove account details, tokens, notifications, and private paths from screenshots first.
@-mentions: choose who responds
Type @ in the chat input to invoke a chat participant. Participants are specialized assistants for specific domains.
| Participant | Use for |
|---|---|
| @vscode | Questions about VS Code itself, settings, and features |
| @terminal | Questions about terminal commands and output |
| Example: @terminal what are the 5 largest files in the current directory sends a terminal-focused question to the built-in terminal participant. |
Extensions can also contribute their own chat participants.
Monitor context usage
The chat input shows a context window indicator: a small bar that fills up as you add context. Hover over it to see:
- Token usage: the current token count out of the model's total context window (for example, 15K out of 128K).
- Credit cost: the total AI credits consumed in this session.
- Usage breakdown: how many tokens each context category uses.
When the bar fills up, VS Code automatically compacts the conversation by summarizing earlier messages. This is called context compaction and it happens in the background so you can keep chatting.
Manually compact the conversation
Type /compact in the chat input to trigger compaction on demand. Optionally add instructions: /compact focus on the database schema decisions. This is useful when the conversation has drifted and you want to refocus the AI on the most important parts.
Combine context for complex questions
A strong prompt combines multiple context types. For example:
Why does the login function fail when #terminalSelection shows "token expired"? Use the attached auth.ts file and validateToken symbol, then suggest a fix without changing files.
This prompt combines a file, terminal output, and a specific function while setting a safe read-only boundary. It gives the AI more useful evidence than a vague "fix my login" request.
For writing project-wide conventions that apply to every chat automatically, see /vscode/how-to-use-custom-instructions-in-vs-code-with-agents-md-and-instructions-md.
Rune AI
Key Insights
- Type # in chat or select Add Context to see the current context choices.
- Drag files or folders from Explorer, Search, or editor tabs into the Chat view.
- Use #codebase when the AI should search the whole workspace for relevant context.
- Use #terminalSelection only after checking the selected output for secrets.
- Type @ to see available participants such as @vscode or @terminal.
- Use the context window control or /compact when a long conversation needs summarizing.
Frequently Asked Questions
What is the difference between #-mentions and @-mentions in chat?
How many files can I add as context to one chat message?
What context does VS Code include automatically?
Conclusion
Use the context picker or #-mentions to specify what the AI should read, and use @-mentions only for available specialized participants. Watch the context window control, remove unrelated material, and inspect files or terminal output for secrets before attaching them.
More in this topic
How to Use VS Code with WSL 2 on Windows
Run VS Code connected to Windows Subsystem for Linux so you can develop in a full Linux environment with native tools, terminals, and debugging, all from Windows.
20 Best VS Code Extensions for Web Developers in 2026
Twenty carefully chosen VS Code extensions every web developer should know. Covers formatting, linting, frameworks, debugging, Git, and developer experience.
How to Install, Disable, Update, and Uninstall VS Code Extensions
Learn how to install, disable, update, and uninstall VS Code extensions from the Marketplace and the command line. Step-by-step instructions for every action.