How to Use GitHub Copilot in VS Code Multi-Root Workspaces With Mixed Stacks
🔍 WiseChecker

How to Use GitHub Copilot in VS Code Multi-Root Workspaces With Mixed Stacks

You work in a VS Code multi-root workspace where each folder uses a different programming language and framework. For example, one folder runs a Node.js API and another folder runs a Python data pipeline. GitHub Copilot can assist across all folders, but it may suggest code that does not match the language or project conventions of the active file. This happens because Copilot reads context from the entire workspace, including files from unrelated stacks. This article explains how to configure Copilot to respect folder boundaries, how to use workspace-scoped settings, and how to avoid cross-stack contamination in multi-root workspaces with mixed technology stacks.

Key Takeaways: Configuring Copilot for Multi-Root Workspaces

  • VS Code settings.json per folder: Override Copilot settings like github.copilot.enable at the folder level to disable Copilot for specific stacks.
  • Workspace-level .gitignore: Exclude files from unrelated stacks to prevent Copilot from reading them as context.
  • Copilot inline suggestions: Use Ctrl+Enter to open the Copilot completions panel and review suggestions from the current file only.

ADVERTISEMENT

Why Copilot Can Suggest Irrelevant Code in Multi-Root Workspaces

GitHub Copilot generates suggestions based on the entire open workspace. In a multi-root workspace, every folder and every file that is not excluded becomes part of the context. When you edit a Python file, Copilot may look at JavaScript files from another folder and produce suggestions that mix syntax or import patterns. This cross-stack contamination occurs because Copilot does not automatically know which folder is your current project. It treats all open files as relevant context.

The Copilot extension reads the open tabs, the active file, and files in the same directory. It also reads files from other folders in the workspace if they are open or if they are referenced by imports. In a mixed-stack workspace, a Python file might import a module that is not present in the JavaScript folder, but Copilot may still see JavaScript code and suggest incorrect function signatures. The root cause is the lack of folder-level scoping in the Copilot context engine.

Additional factors include the github.copilot.enable setting, which is global by default, and the workspace .gitignore file, which does not affect Copilot. You must explicitly tell Copilot which files and folders to ignore or disable it per language.

Steps to Configure Copilot Per Folder in a Multi-Root Workspace

  1. Create or open your multi-root workspace file
    In VS Code, go to File > Save Workspace As to create a .code-workspace file. This file contains the list of root folders and workspace-level settings.
  2. Add folder-level settings for Copilot
    Open the .code-workspace file. Inside the settings object, add a github.copilot.enable entry with folder overrides. Use the folder name as the key. Example:
    "settings": {
    "[python]": {
    "github.copilot.enable": true
    },
    "[javascript]": {
    "github.copilot.enable": false
    }
    }

    This disables Copilot for JavaScript files while keeping it active for Python files.
  3. Disable Copilot for specific languages globally
    If you want to disable Copilot for an entire language across all folders, use the github.copilot.enable setting with language identifiers. Open VS Code Settings (Ctrl+,), search for github.copilot.enable, and edit the JSON to include "typescript": false or "go": false.
  4. Exclude folders from Copilot context
    Add a files.exclude setting in the workspace file to hide entire folders from the file explorer. Copilot does not read files that are excluded from the workspace. Example:
    "files.exclude": {
    "/node_modules": true,
    "
    /python_env": true
    }

    This prevents Copilot from using files inside node_modules or python_env as context.
  5. Use a .copilotignore file
    Create a .copilotignore file in the root of each folder. This file uses the same syntax as .gitignore. Copilot will not read files or folders listed in .copilotignore. Example for a JavaScript folder:
    # .copilotignore
    node_modules/
    dist/
    log

    Place this file in the JavaScript folder root. Copilot ignores those paths when generating suggestions.
  6. Restart Copilot after configuration changes
    Open the Command Palette (Ctrl+Shift+P), search for Developer: Reload Window, and press Enter. This reloads all extensions and settings, including the per-folder Copilot configuration.

ADVERTISEMENT

If Copilot Still Shows Irrelevant Suggestions

Copilot uses code from the wrong folder in inline suggestions

If Copilot shows a suggestion that contains imports or functions from another folder, close all files from that folder. Copilot reads open tabs. With only the active file open, Copilot has less cross-stack context. Then press Ctrl+Enter to open the Copilot completions panel. This panel shows multiple suggestions. Select the one that matches your current language.

Copilot suggests deprecated or incorrect API calls

When you have multiple versions of the same library across folders, Copilot may pick the wrong version. For example, a Python folder uses Flask 2.0 and another uses Flask 3.0. Add the github.copilot.advanced setting in the workspace file to limit the number of files Copilot reads. Set github.copilot.advanced.maxTokens to a lower value to reduce context size. This does not fix the version mismatch completely. The better fix is to use a virtual environment per folder and exclude the other folder’s site-packages using .copilotignore.

Copilot stops working in one folder after disabling it in another

This happens when you set github.copilot.enable to false globally instead of per language. Check your user settings.json. If you see "github.copilot.enable": false at the top level, remove it. Use the per-language override as shown in Step 2 above. Then reload the window.

GitHub Copilot in Multi-Root Workspaces vs Single-Folder Workspaces: Key Differences

Item Multi-Root Workspace Single-Folder Workspace
Context scope All open folders and files Only the single folder and its files
Per-folder settings Supported via .code-workspace file Not applicable
Language isolation Manual via .copilotignore or github.copilot.enable Automatic because only one language stack exists
Copilot completions panel Shows suggestions from all folders unless filtered Shows suggestions from the single folder
Configuration complexity Higher: must set per-folder or per-language overrides Lower: global settings work

You can now configure GitHub Copilot to work correctly in multi-root workspaces with mixed stacks. Apply per-folder settings in the .code-workspace file, use .copilotignore to exclude unrelated files, and close tabs from other stacks when editing. For advanced isolation, combine language-specific disable rules with folder-level exclusions. This prevents Copilot from suggesting code that mixes Python and JavaScript syntax in the same completion.

ADVERTISEMENT