In VS Code, how does Copilot build the semantic index behind #codebase, and what keeps a file out of that index?
answer
- built for you automatically
- depends on where the repo is hosted
- an organization policy for the rest
- two exclusion sources, not three
- agents fall back without it
basics
~10 sCopilot maintains the index automatically: GitHub indexes GitHub-hosted repositories, Azure DevOps repositories are indexed too, and other workspaces are indexed by Copilot. Files matched by .gitignore or files.exclude, and binaries, stay out.
solid answer
~40 sSemantic search (`#codebase`) needs a workspace index, which Copilot builds and maintains automatically. For repositories on GitHub.com or GitHub Enterprise Cloud, GitHub builds the index once per repository, so it is often instantly available; GitHub Enterprise Server is not supported. Azure DevOps repositories are indexed after Microsoft sign-in. Other workspaces, such as local or GitLab folders, get an index built by Copilot, which uploads data to GitHub; that feature is off by default for organization and enterprise users until the `Semantic indexing for non-GitHub repositories` policy is set to Enabled. The index skips binaries and files excluded by `.gitignore` or `files.exclude`; `search.exclude` affects only text search and grep. Without an index, agents still use text search, grep, file search and usages.
go deeper
Recall that #codebase means semantic search over the workspace and that Copilot builds the index for you, with its status shown in the Copilot Status Bar menu.
Explain the index sources by hosting, that .gitignore and files.exclude keep files out while search.exclude affects only text search, and how agents fall back without an index.
Show you tune exclusions to cut noisy search context, and diagnose a missing index on an organization seat to the non-GitHub indexing policy rather than to the workspace.
Weigh uploading non-GitHub code for semantic search against the policy's default, and separate relevance exclusions from the access controls a security review actually asks for.
## What the index is for Copilot's agents gather context with several tools: **semantic search** (`#codebase`), text search, grep, file search, usages, directory listing and file reads. Semantic search finds code that matches the meaning of a question rather than its exact words, and it is the only one of these tools that **requires a workspace index**. Copilot maintains that index automatically; parts of it may be stored on your machine and parts may come from remote sources. Its status appears in the Copilot status dashboard in VS Code's Status Bar, and the **Build Codebase semantic index** command builds or rebuilds it on demand. ## Where the index comes from | Workspace | How the index is built | |---|---| | Repository on GitHub.com or GitHub Enterprise Cloud | GitHub builds it once per repository, so it is often instantly available; sign in with GitHub | | GitHub Enterprise Server | Remote indexing not supported | | Azure DevOps repository | Built and maintained automatically after Microsoft sign-in | | Any other workspace (local folder, other hosts) | Copilot builds it; first build can take minutes, then it updates in the background | The last row carries a governance catch. GitHub's documentation calls it **semantic indexing for non-GitHub repositories**: it uploads workspace data to GitHub to make it searchable, is available only on GitHub.com, and is **disabled by default** for organizations and enterprises with Copilot Business or Copilot Enterprise. An enterprise or organization owner must set the `Semantic indexing for non-GitHub repositories` policy to **Enabled**; if it stays **Unconfigured**, members cannot use it. VS Code's page summarises this as enabled for personal accounts, off by default for organization and enterprise users. GitHub also states that Copilot does not use an indexed repository for model training. ## What goes into the index - Relevant **text files** in the current project, not limited to particular languages. - Some irrelevant types, such as `.tmp` or `.out`, are skipped automatically. - **Binary files**, such as images and PDFs, are not indexed. - Files excluded by the **`files.exclude`** setting or by a **`.gitignore`** file are left out. ## Keeping files out: the three settings compared | Mechanism | Text search and grep | Semantic index | Explorer | |---|---|---|---| | `.gitignore` | excluded | excluded | not addressed by the page | | `files.exclude` | excluded | excluded | hidden | | `search.exclude` | excluded | not listed by the docs | stays visible | VS Code's guidance is to exclude generated files, build output, logs and large datasets, because every search match becomes part of the conversation context; strict exclusions improve relevance and speed and reduce the tokens search results consume. Two caveats: 1. `.gitignore` is **bypassed** for what the agent can see when you have an ignored file open or text selected in it. 2. These are relevance controls, not access controls. Blocking content for a team is the job of content exclusions, which organization or enterprise owners configure separately. ## When there is no index yet You do not need to type `#codebase`; agents run semantic search automatically when it helps, and `#codebase` simply forces it for one prompt. While a new local workspace is still building its first index, agents fall back to text search, grep, file search and language intelligence such as usages, which the docs say still give accurate results for most prompts. Small projects may even be read directly into the agent's context. ## Diagnosing a missing or noisy index 1. Open the Copilot status dashboard in the Status Bar and check the index status. 2. For a GitHub-hosted repository, confirm you are signed in with GitHub and, for a private repository, that you granted the extra permission VS Code asks for at startup. 3. For a repository hosted elsewhere on an organization seat, ask an owner whether the non-GitHub indexing policy is Enabled. 4. Run **Build Codebase semantic index** to rebuild on demand. 5. If results are noisy rather than missing, add generated folders to `.gitignore` or `files.exclude` so they leave the index as well as text search.
- You add dist/ to search.exclude so Copilot stops quoting build output, but agent answers still cite it. What else should you change?search.exclude keeps files out of text search and grep only, and VS Code's docs do not list it for the semantic index. Add the folder to .gitignore or to files.exclude, which exclude it from text search, grep and the semantic index; files.exclude also hides it from the Explorer.
- A developer on an organization seat opens a GitLab-hosted repository and semantic search never becomes available. Why?Indexing for repositories hosted outside GitHub uploads data to GitHub and is controlled by the Semantic indexing for non-GitHub repositories policy, which is disabled by default for Copilot Business and Copilot Enterprise. An organization or enterprise owner must set it to Enabled. Until then agents rely on text search, grep, file search and usages.
- You must type #codebase or Copilot never searches the workspace semantically.
- search.exclude removes files from Copilot's semantic index.
- Remote GitHub indexing works the same on GitHub Enterprise Server.
- Files matched by .gitignore can never reach the agent, even when open.
- Without a semantic index, agent mode cannot find code at all.