If Content is King, Then Context is God
Context Variables as Explicit Context Markers
In the previous examples, whenever we wanted to interact with Copilot in a specific way, we prefixed our command with a slash (e.g., /explain, /github...), but we also made sure that we either selected the code snippet we wanted to interact with, opened the file(s) where our code was, or at least had them in a VS Code workspace. This can be seen as implicit context provision, and it helps Copilot understand the context of our request as we've already discussed.
Another way to provide this context is by using the # syntax like #file, #search, and more. These are explicit context markers that tell Copilot exactly what context to consider. It's worth noting that these variables have changed significantly over time. Some were removed, some were renamed, and some were added. I expect more changes to come as Copilot evolves. The following table lists the currently supported context variables:
| Context Variable / Tool | What It Does |
|---|---|
#changes | Provides a list of version control modifications made in the workspace. |
#codebase | Triggers a code search within the current project to automatically gather context relevant to the chat prompt. |
#editFiles | Grants the ability to create or modify files directly within your project. |
#extensions | Lets you explore and inquire about installed or available VS Code extensions. E.g., "How do I start with Python? #extensions" |
#fetch | Pulls the HTML content from a given URL for analysis or reference. |
#findTestFiles | Scans the project to locate test files. |
#githubRepo | Performs a code search across a public GitHub repository. Example: "What’s a global snippet? #githubRepo microsoft/vscode" |
#new | Starts a brand-new VS Code workspace from scratch. |
#openSimpleBrowser | Opens the built-in Simple Browser to preview a locally hosted app. |
#problems | Pulls current problems from the VS Code Problems panel as context for troubleshooting or debugging. |
#readCellOutput | Captures the output from a specific notebook cell. |
#runCommands | Executes a terminal command and uses the output as context. |
#runNotebooks | Runs notebook cells and collects the resulting output for use in chat. |
#runTasks | Executes predefined tasks in the workspace and retrieves their outputs. |
#runTests | Launches test suites in the current project and fetches results to inform the conversation. |
#search | Searches for files across your project directory. |
#searchResults | Includes file search results as context for chat interactions. |
#selection | Sends your currently selected code from the editor to Copilot Chat as context. |
#terminalSelection | Uses the currently highlighted text in the terminal window as context for a prompt. |
#terminalLastCommand | Provides the most recent terminal command run, adding it to the chat context. |
#testFailure | Brings in details of failed test runs, helping with root cause analysis and debugging. |
#usages | Adds insights from "Find References", "Find Implementations", and "Go to Definition" features. |
#VSCodeAPI | Allows you to ask questions or get information about the Visual Studio Code Extension API for building extensions. |
Here are some practical examples of how to use some of them:
Fetching and Searching Online Resources (Web & GitHub Repositories)
Examples with #fetch and #githubRepo:
#fetch https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance and summarize how to provision an EC2 instance
Explore the structure of #githubRepo remix-run/remix and outline how it handles routing and data loading
#fetch https://docs.docker.com/compose/environment-variables/ and list three ways to pass environment variables to Docker Compose
Use #githubRepo firebase/quickstart-js to extract a basic setup for Firebase Authentication in a web app
#fetch https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise and explain how `Promise.allSettled` differs from `Promise.all`
Building with GitHub Copilot
From Autocomplete to Autonomous AgentsEnroll now to unlock all content and receive all future updates for free.
