Skip to main content
Context is the key differentiator that determines whether GitHub Copilot gives generic suggestions or project-specific, valuable code. By mastering context manipulation techniques, you’ll guide Copilot to generate more accurate, relevant, and usable completions that align with your project’s goals and coding standards. This lesson explains why context matters, the types of context Copilot uses, practical ways to supply context, specialized agents you can target, and a consolidated example (Tkinter Word Count GUI) showing how selection, files, and plotting fit together.

Why context matters

  • Context is the information provided to the model that helps it understand your requirements and produce appropriate responses.
  • Good context improves suggestion relevance and accuracy, reduces repeated clarifications, and speeds up development.
  • When Copilot consistently understands your codebase and intent, you spend less time editing suggestions and more time solving problems.
Primary goals for effective context management:
  1. Increase the relevance of Copilot suggestions by providing the most appropriate information.
  2. Reduce back-and-forth clarifications by giving the right context up front.
  3. Improve development efficiency by receiving accurate suggestions faster.

What is context for Copilot?

Context is everything that helps the model understand what you’re trying to accomplish: code files, selected text in your editor, terminal output, recent source-control changes, repository-level instructions, and any explicit instructions you provide.
A dark-themed infographic titled "Understanding Context – Definition" showing a small robot connected to panels of charts and code, with labels explaining context as information given to an AI model that guides understanding and improves output quality.

Types of context

There are three main types of context that influence Copilot’s suggestions:
A dark-themed presentation slide titled "Types of Context" showing three colored circles labeled Calculated Context (blue), Explicit Context (orange), and Implicit Context (green), each with a small icon and a one-line description. Arrows connect the circles to indicate a flow between the context types.

Calculated context

Calculated context is chosen automatically by Copilot to maximize relevance. For example, when you use the @workspace agent or ask a project-level question, Copilot analyzes your prompt and selects files from your workspace that it considers most relevant. This reduces manual work and narrows the surface area, letting you focus on describing what you need.

Explicit context

Explicit context is where you tell Copilot exactly what to consider. Common approaches:
  1. Describe the context in natural language within your prompt.
  2. Use references like #selection and #editor to point to editor content.
  3. Attach files via Attach Context when the relevant files are not part of calculated context.
The image shows a split screen: the left side is a code editor (VS Code) with a right-click context menu highlighting Copilot and other editor actions, and the right side is a presentation slide titled "Explicit Context" listing three ways to provide context (user prompts, references like #selection/#editor, and attached files).

Implicit context

Implicit context is added automatically by Copilot and typically includes:
  • The current file you’re editing
  • Any selected text in the editor
  • Visible editor contents (when #editor is used)
Implicit context helps Copilot focus on what you’re actively working on. If implicit context pulls in irrelevant data on large projects, you can disable it in Copilot settings to regain strict control.
A dark presentation slide titled "Implicit Context" with three numbered panels and icons summarizing: 01 "Automatically added by Copilot", 02 "Includes current file and selection", and 03 "Can be disabled in configurations."

Sources of context Copilot can draw from

  • Code files and project structure (modules, dependencies, and architecture)
  • Current editor selection and visible editor content
  • Terminal output (errors, build logs, command results)
  • Source-control metadata and recent changes
  • Repository-level instructions such as .github/copilot-instructions.md
These sources combined help Copilot build a fuller picture of your development environment and intent.

Practical example: Word Count GUI (consolidated)

Below is a consolidated, corrected example of a simple Tkinter-based Word Count application. This shows how file selection, text processing, and Matplotlib plotting can be structured in a single module.
Note: This focused snippet includes the correct FigureCanvasTkAgg import from matplotlib.backends.backend_tkagg so it can be embedded into a Tkinter application. For more on Tkinter and Matplotlib integration, see the Python docs for Tkinter and Matplotlib’s user guide: https://docs.python.org/3/library/tkinter.html and https://matplotlib.org/stable/users/index.html.

Specialized agents

Copilot exposes specialized agents you can reference in chat to access different types of context:
A presentation slide titled "Context Referencing – Chat Participants (Agents)" showing five agent tiles: @workspace, @terminal, @vscode, @github, and @azure, each with a brief description of their responsibilities (project structure, terminal help, VS Code features, GitHub skills, and Azure deployments).

References and symbol targeting

When you need to reference files or symbols precisely, use these directives:
  • #file <filename> — point Copilot to a specific file in the repo.
  • #sym — target a specific symbol (function, class, or variable) and open a symbol picker.
  • #selection — direct Copilot to the current editor selection.
  • #editor — include the visible contents of the active editor.
  • #codebase — give Copilot relevant workspace content.
  • #changes — include source-control changes (recent modifications).
  • #terminal — reference terminal output or last command.
Examples from a symbol picker or quick results might look like:

Promoting inline chat to full chat

If you start a short, inline chat in the editor and the discussion grows longer or requires referencing earlier messages, promote the inline chat to a full chat window. This preserves context and provides a larger workspace for longer troubleshooting or code review sessions. Context references are especially useful for debugging, resolving build issues, or reviewing recent changes because they let Copilot see relevant parts of your repo beyond a single file.

Repository-level and custom instructions

For fine-grained control over Copilot behavior, add repository-level instructions in .github/copilot-instructions.md. Copilot considers these instructions for interactions in that repository. Use repository-level instructions to encode team conventions, code style preferences, test requirements, and other project-specific rules. Example (place in .github/copilot-instructions.md):

Balancing context volume

Too little context and Copilot lacks necessary information; too much context and the model may be distracted by irrelevant data. Shape the context you provide — prefer concise, relevant context for the task at hand. Use #selection, #sym, and repository-level instructions to narrow Copilot’s focus.
Provide enough targeted context (files, symbols, and short instructions) and avoid dumping entire large files unless they are directly relevant. Use #selection, #sym, and repository-level instructions to keep suggestions focused.

Wrap-up

Context manipulation is a decisive skill for getting the most out of GitHub Copilot. Understanding calculated, explicit, and implicit context, how to provide them, and how to use specialized agents and repository-level instructions will help you obtain highly relevant suggestions, reduce clarification cycles, and accelerate development. Further reading and references:

Watch Video