GitHub Copilot Chat sometimes loads the wrong repository context, causing it to suggest code or answer questions based on files from a different project. This happens when the extension cannot correctly detect the active repository or when multiple repositories are open in the same workspace. The problem is common among developers who work with multiple repos in Visual Studio Code or JetBrains IDEs. This article explains why Copilot Chat loses context and provides step-by-step fixes to restore correct behavior.
Key Takeaways: Restoring Correct Repository Context in Copilot Chat
- VS Code command palette > Developer: Reload Window: Refreshes the extension host and forces Copilot to re-read the active workspace.
- GitHub Copilot Chat settings > Repository selector: Lets you manually choose the correct repository when multiple are open.
- .copilot-context file in repo root: Explicitly defines which repository Copilot Chat should use for context.
Why Copilot Chat Picks the Wrong Repository
GitHub Copilot Chat determines repository context by reading the workspace folder structure and the active Git repository. In Visual Studio Code, the extension uses the workspaceFolders API and the git.repository state to identify the current project. When you open a workspace that contains multiple folders, each with its own Git root, Copilot Chat may select the wrong folder as the primary context.
JetBrains IDEs use a similar mechanism based on the project root and the active module. If you have multiple modules or projects loaded in the same IDE window, Copilot Chat may default to the first module in the list instead of the one you are actively editing.
The extension does not always re-evaluate context when you switch between files or tabs. It caches the repository identifier at session start. If you switch to a different repository without reloading the window, Copilot Chat continues to reference the original repository. This leads to incorrect suggestions, stale file references, and answers that reference code from the wrong project.
Steps to Fix Wrong Repository Context
The following steps apply to Visual Studio Code and JetBrains IDEs. Perform them in order until the context is corrected.
Step 1: Verify the Active Repository in the Status Bar
- Open the Copilot Chat panel
Click the Copilot Chat icon in the activity bar or press Ctrl+Shift+I on Windows, Cmd+Shift+I on Mac. - Check the repository name displayed at the top of the chat panel
If the name does not match the repository you are working on, the context is wrong. Note the displayed name. - Close any other workspace folders that contain unrelated repositories
In VS Code, go to File > Close Folder for each extra folder. In JetBrains, go to File > Close Project and reopen only the correct project.
Step 2: Reload the IDE Window
- In VS Code, open the Command Palette
Press Ctrl+Shift+P on Windows or Cmd+Shift+P on Mac. - Run the Reload Window command
TypeDeveloper: Reload Windowand press Enter. The window restarts and Copilot Chat reinitializes with the correct workspace. - In JetBrains IDEs, go to File > Invalidate Caches
Select Invalidate and Restart. This clears the extension cache and forces Copilot Chat to rebuild its context index.
Step 3: Manually Select the Correct Repository
- In the Copilot Chat panel, click the repository dropdown
This dropdown appears near the top of the chat panel if multiple repositories are detected. - Select the correct repository from the list
Copilot Chat immediately re-indexes that repository and uses it for all subsequent queries. - If the dropdown is missing, open the VS Code settings
Go to File > Preferences > Settings, search forgithub.copilot.chat.repositorySelection, and set it tomanual. This makes the dropdown always visible.
Step 4: Add a .copilot-context File
- Create a file named
.copilot-contextin the root of the correct repository
This file tells Copilot Chat which repository to use by default. - Add the repository path or name
Write the relative path to the repository root or the repository name as recognized by your Git remote. Example:my-frontend-app. - Save the file and reload the window
Run the Reload Window command from Step 2 to apply the change.
Step 5: Disable Multi-Root Workspaces Temporarily
- Open the workspace file
In VS Code, go to File > Open Workspace from File and select your.code-workspacefile. - Remove extra folders from the workspace
In the workspace settings JSON, delete thefoldersentries that point to other repositories. Save the file. - Reload the window
Copilot Chat now sees only one repository and uses it for context.
If Copilot Chat Still Uses Wrong Context After the Main Fix
Copilot Chat Returns Code Snippets from a Different Project
If the suggestions still reference files from another repository, the extension may be reading a cached index. Clear the Copilot Chat cache by running the command Copilot: Clear Chat History from the command palette. Then ask a new question to force a fresh context load.
Copilot Chat Ignores the .copilot-context File
The .copilot-context file is only read when Copilot Chat initializes. If you add the file after the session started, reload the window. Also verify the file is in the root of the repository that is currently active in the workspace, not in a subfolder.
Multiple VS Code Windows Each Have the Same Wrong Context
This occurs when you open the same workspace file from different windows. Close all VS Code windows, reopen only the correct project folder, and reload. Do not use the workspace file until you have removed the conflicting folders.
Copilot Chat Context Methods: Manual Selection vs .copilot-context File
| Item | Manual Repository Dropdown | .copilot-context File |
|---|---|---|
| Setup effort | One click per session | One-time file creation |
| Works with multi-root workspaces | Yes, dropdown appears automatically | Yes, but only one repository per file |
| Persistence across sessions | No, must re-select each session | Yes, persists until file is removed |
| IDE support | VS Code and JetBrains | VS Code only |
| Best for | Frequent context switching | Single-project workflows |
Now you can force Copilot Chat to use the correct repository by reloading the window, selecting the repo manually, or adding a .copilot-context file. Start by checking the repository name in the chat panel after reloading. If you work with multiple repositories daily, keep the github.copilot.chat.repositorySelection setting set to manual so you always see the dropdown.