How to Use Copilot Chat with Files, Folders, Symbols, and Terminal Context

Add files, folders, code symbols, terminal output, and web content as context in Copilot Chat with the context picker, mentions, and drag and drop.

6 min read

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

ChoiceWhat it adds
Files & FoldersSelected workspace files or a folder
SymbolsA function, class, variable, or other code symbol
#codebaseA workspace-wide search for relevant context
#terminalSelectionText currently selected in the integrated terminal
#fetchContent 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.

ParticipantUse for
@vscodeQuestions about VS Code itself, settings, and features
@terminalQuestions 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

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.
RunePowered by Rune AI

Frequently Asked Questions

What is the difference between #-mentions and @-mentions in chat?

#-mentions add context such as files, folders, symbols, terminal output, or tools. @-mentions invoke a specialized participant such as @vscode or @terminal. Type either character in chat to see what is currently available.

How many files can I add as context to one chat message?

VS Code does not publish one fixed file count because the usable context depends on the selected model and file sizes. Watch the context window control and add only material that helps answer the request.

What context does VS Code include automatically?

VS Code includes the active file, current selection, and file name as implicit context. Workspace indexing can also find relevant files. Add explicit context when a particular file, folder, symbol, or terminal selection must be considered.

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.