Learn › GitHub Copilot Mastery › Copilot Chat: Ask Mode for Understanding Code

Copilot Chat: Ask Mode for Understanding Code

Intermediate 🕐 12 min Lesson 4 of 13
What you'll learn
  • Use @workspace, @github, and @terminal context references to give Copilot Chat access to the right information
  • Apply slash commands /explain, /fix, /tests, and /doc to common code understanding tasks
  • Distinguish when Ask mode is the right choice versus Edit or Agent mode

When to Switch From Completions to Chat

Inline completions are best when you know what to write next. Copilot Chat is best when you need to understand something, explore options, or ask a question that requires more than a line of code as an answer. Ask mode is the conversational starting point — it gives you a direct line to ask anything about your code, your project, or programming in general.

Open the Chat panel with Ctrl+Alt+I (or Cmd+Shift+I on macOS) in VS Code, or from the Copilot tool window in JetBrains. You can also right-click any selected code and choose Copilot → Explain to open a focused chat about that selection.

Context References: Pointing Copilot at the Right Thing

Ask mode chat without context is generic. With context references, it is precise. Use the @ prefix to attach context:

  • @workspace — Gives Copilot access to your entire project. Ask questions like "Where is user authentication handled in this project?" and Copilot searches across all files.
  • @github — Connects to GitHub.com to answer questions about issues, pull requests, commits, and your repositories.
  • @terminal — Gives Copilot context from your terminal output. Useful after a failing command: paste or reference the output and ask what went wrong.

You can also use #file:path/to/file.ts to reference a specific file, or highlight code in the editor and open Chat — the selection is automatically included as context.

Slash Commands for Common Tasks

Slash commands are shortcuts for the most common Chat tasks. Type them at the start of a message:

Command
What it does
/explain
Explains selected code in plain language: what it does, how it works, what the edge cases are
/fix
Identifies a bug in selected code and suggests a fix with explanation
/tests
Generates unit tests for the selected function or class
/doc
Writes JSDoc, docstring, or inline comments for the selected code

Practical Workflows

Understanding unfamiliar code: Select a complex function, press Ctrl+I to open inline chat, and type /explain. Copilot walks through what each part does. This is faster than reading documentation or tracing execution manually, especially in large codebases you just joined.

Debugging a failing test: When a test fails with an error message you don't immediately recognise, paste the error into Chat with @terminal context and ask "What is causing this error?" Copilot identifies the root cause and suggests a fix.

Generating tests: Select a function and run /tests. Copilot generates unit tests with relevant edge cases — nulls, empty arrays, boundary values — based on the function's signature and body. You review and keep the ones that matter.

Exploring the codebase: Ask @workspace Where is the database connection initialised in this project? or @workspace Which files handle payment processing? Copilot searches across your project and gives you exact file references with explanations.

Ask Mode vs the Other Chat Modes

Ask mode is conversational — it produces explanations and code snippets in the chat panel that you then paste or apply manually. It does not touch your files directly. When you want Copilot to make changes to files, you switch to Edit mode or Agent mode. Ask mode is the right starting point when you need to understand before you act.

Try This

Open the largest or most complex file in your current project. Select 20-30 lines of code you find difficult to follow. Press Ctrl+I, type /explain, and read Copilot's explanation. Then ask a follow-up question in the same chat: "What would happen if this received a null value?" That kind of conversational follow-up is where Ask mode shows its value over a one-shot search.

Key takeaways
  • @workspace gives Copilot access to your full project for cross-file questions; @terminal gives it context from terminal output
  • Slash commands (/explain, /fix, /tests, /doc) are shortcuts for the most common Chat tasks — type them at the start of a message
  • Ask mode is conversational and read-only: it does not modify files; use Edit or Agent mode when you want Copilot to make changes