Why might Copilot Chat in VS Code answer a whole-repository question about only the open file, and what do #codebase and attached files change?
answer
- what chat sends without being asked
- active file, selection, file name
- inline chat is scoped to one editor
- #codebase forces a semantic search
- an index that is still building
basics
~20 sChat sends the active file and selection implicitly, and inline chat is scoped to the active editor, so a broad question can collapse onto one file. #codebase forces a workspace semantic search; #-mentioned files guarantee specific files are read.
solid answer
~50 sCopilot Chat in VS Code automatically includes the active file, your selection and the file name. Asked in editor inline chat, the prompt is scoped to the active editor anyway. So a vague "how does this work?" often comes back as an answer about the file you have open. In the Chat view an agent decides on its own whether to search further, and runs semantic search by itself when that makes sense. Adding `#codebase` forces that semantic search over the workspace index for this prompt. Attaching `#<file>`, `#<folder>` or `#<symbol>` (or dragging files in) makes sure those exact files are read. If the index is not ready yet, for example a local folder still building its first index, agents fall back to text search, grep, file search and language intelligence. Checking the response's references list shows what it actually used.
go deeper
Recall the implicit context, which is the active file, the selection and the file name, and that #codebase or #-mentioned files make broader context explicit.
Explain the mechanics: inline chat's editor scope, an agent's own choice to search, #codebase forcing semantic search, and the index sources with their fallbacks.
Diagnose a narrow answer step by step: the surface, the wording, the references list, the index status, and the organization policy that leaves local indexing off.
Weigh standardising on GitHub-hosted repositories for instant remote indexing against enabling local indexing through policy for workspaces that live elsewhere.
## The symptom A developer asks Copilot Chat in VS Code something about the whole repository, such as "where do we validate payment input?", and the answer describes only the file open in the editor. Usually nothing is broken. The answer reflects the context the request carried, and that depends on the surface, the wording and the state of the workspace index. ## What chat sends without being asked VS Code adds **implicit context** to a chat prompt: - the **active file**, - the **current selection**, - the **file name**. When the question is vague ("how does this work?", "what does this do?"), the active file is the most concrete thing in the request, and the answer gravitates to it. VS Code's own advice is to avoid words like "this", which could mean the last answer, the current file or the whole project. The surface matters too. In **editor inline chat**, the prompt is scoped to the code in the active editor. A repository-wide question asked there starts from the wrong scope. Ask it in the Chat view. ## How the Chat view gathers more In the Chat view, an agent decides on its own whether it needs more context. It can use several search tools: | Tool | What it does | Needs an index? | |---|---|---| | **Semantic search** (`#codebase`) | Finds code by meaning, not exact keywords | Yes | | **Text search** | Finds text in file contents | No | | **Grep** | Exact text or regex across files | No | | **File search** | Finds files by name or glob | No | | **Usages** | References, implementations, definitions | No | VS Code's FAQ says you do **not** need `#codebase` in every prompt, because agents run semantic search on their own when it makes sense. `#codebase` is how you **force** a semantic search for one prompt, which helps when a broad question keeps coming back narrow. ## Making the context explicit There are two different tools for two different needs: 1. **`#codebase`** when you don't know where the answer lives: it searches the workspace by meaning. 2. **Attached files** when you do know: type `#` and choose a file, folder or symbol (open the file that holds a symbol first), drag files from the Explorer or Search view, or use **Add Context** > **Files & Folders** or **Symbols**. Attachments guarantee those files are considered. They do not limit the agent to them. `#codebase` does not paste every file into the prompt. It returns the matches a semantic search finds. A question such as "how many times is this function invoked?" is still a poor fit, because VS Code's guidance says not to expect a full analysis of the codebase from chat. ## When the index is the problem Semantic search depends on a **workspace index**, and there are three ways it gets built: - **GitHub repositories** are indexed by GitHub (GitHub.com and GitHub Enterprise Cloud, not GitHub Enterprise Server), often instantly. - **Azure DevOps repositories** are indexed automatically once you sign in with a Microsoft account. - **Other workspaces**, including local folders, are indexed by Copilot itself. The first build can take a few minutes. VS Code's docs say this local indexing is on for personal accounts but **off by default for organization and enterprise users** until a policy enables it. While no index is available, agents rely on text search, grep, file search and language intelligence. The answers can still be good, but they are keyword-driven. The Copilot status dashboard in the Status Bar shows the indexing status, and **Build Codebase semantic index** builds or rebuilds it on demand. Which files the index skips is decided by the workspace's exclusion settings, which the material on Copilot's context and instruction files covers. ## Diagnosing it quickly - Check where you asked: editor inline chat stays on the active editor. - Check the response's **references** list to see which files it used. - Rephrase without "this", and use names that appear in the code. - Add `#codebase` to force a semantic search, or attach the files you already suspect. - Check the index status if the workspace is new, local, or under an organization account.
- Do you need to add #codebase to every Copilot Chat prompt in VS Code?No. VS Code's FAQ says agents run semantic search on their own when it makes sense. `#codebase` forces a semantic search for one prompt, which helps when a broad question keeps landing on the active file.
- How do you attach a symbol, such as one class, to a Copilot Chat prompt in VS Code?Open the file that contains the symbol, then type `#` and choose the symbol from the picker. Files and folders can also be attached through **Add Context** or by dragging them into the Chat view.
- Copilot Chat reads the entire repository on every prompt without any search.
- #codebase pastes the full text of every workspace file into the prompt.
- Attaching #-mentioned files stops the agent from looking at anything else.
- Without a semantic index, Copilot Chat cannot search the codebase at all.
- Editor inline chat is a good place for repository-wide questions.