Feedback

Chat Icon

Building with GitHub Copilot

From Autocomplete to Autonomous Agents

If Content is King, Then Context is God
59%

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 / ToolWhat It Does
#changesProvides a list of version control modifications made in the workspace.
#codebaseTriggers a code search within the current project to automatically gather context relevant to the chat prompt.
#editFilesGrants the ability to create or modify files directly within your project.
#extensionsLets you explore and inquire about installed or available VS Code extensions. E.g., "How do I start with Python? #extensions"
#fetchPulls the HTML content from a given URL for analysis or reference.
#findTestFilesScans the project to locate test files.
#githubRepoPerforms a code search across a public GitHub repository. Example: "What’s a global snippet? #githubRepo microsoft/vscode"
#newStarts a brand-new VS Code workspace from scratch.
#openSimpleBrowserOpens the built-in Simple Browser to preview a locally hosted app.
#problemsPulls current problems from the VS Code Problems panel as context for troubleshooting or debugging.
#readCellOutputCaptures the output from a specific notebook cell.
#runCommandsExecutes a terminal command and uses the output as context.
#runNotebooksRuns notebook cells and collects the resulting output for use in chat.
#runTasksExecutes predefined tasks in the workspace and retrieves their outputs.
#runTestsLaunches test suites in the current project and fetches results to inform the conversation.
#searchSearches for files across your project directory.
#searchResultsIncludes file search results as context for chat interactions.
#selectionSends your currently selected code from the editor to Copilot Chat as context.
#terminalSelectionUses the currently highlighted text in the terminal window as context for a prompt.
#terminalLastCommandProvides the most recent terminal command run, adding it to the chat context.
#testFailureBrings in details of failed test runs, helping with root cause analysis and debugging.
#usagesAdds insights from "Find References", "Find Implementations", and "Go to Definition" features.
#VSCodeAPIAllows 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 Agents

Enroll now to unlock all content and receive all future updates for free.