Multi-root Workspaces

You can work with multiple project folders in Visual Studio Code with multi-root workspaces. This can be very helpful when you are working on several related projects at one time. For example, you might have a repository with a product's documentation which you like to keep current when you update the product source code.

multi-root hero

Note: Multi-root workspace mode is still a relatively new feature and some extensions may not have adopted the new APIs. Many extensions such as themes and snippets don't require any changes. If some of your extensions do not handle multiple folders, you may need to limit their use to a single folder.

Adding folders

It is easy to add another folder to your existing workspace. There are several gestures for adding folders:

Add Folder to Workspace...

The File > Add Folder to Workspace... command brings up an Open Folder dialog to select the new folder.

Add Root Folder

Once a root folder is added, the Explorer will show the new folder as a root in the File Explorer. You can right click on any of the root folders and use the context menu to add or remove folders.

Remove Root Folder

The File Explorer should work and behave as before. You can move files between root folders and use any of the typical file operation actions provided in the context menu and the Explorer view.

Settings like files.exclude are supported for each root folder if configured and across all folders if configured as global user setting.

Drag and drop

You can use drag and drop to add folders to a workspace. Drag a folder to the File Explorer to add it to the current workspace. You can even select and drag multiple folders.

Note: Dropping a single folder into the editor region of VS Code will still open the folder in single folder mode. If you drag and drop multiple folders into the editor region, a new multi-root workspace will be created.

Multiple selection native file open dialogs

Opening multiple folders with your platform's native file open dialog will create a multi-root workspace.

command line --add

Add a folder or multiple folders to the last active VS Code instance for a multi-root workspace.

  code --add vscode vscode-docs

Removing folders

You can remove a folder from a Workspace with the Remove Folder from Workspace context menu command.

Workspace file

When you add multiple folders, they are initially placed in a Workspace titled UNTITLED WORKSPACE and that name will remain until you save the workspace. You do not need to save a Workspace until you want to have it in a permanent location, for example, on your Desktop. Untitled Workspaces are present as long as the VS Code instance they are using is open. Once you completely close an instance with an untitled workspace, you will be asked to save it if you plan to open it again in the future:

save workspace dialog

When you save your workspace, it will create a .code-workspace file and the file name will be displayed in the File Explorer.

Save Workspace As...

If you want to move your Workspace file to a new location, you can use the File > Save Workspace As... command which will automatically set the correct folder paths relative to the new Workspace file location.

Opening workspace files

To reopen a Workspace, you can:

  • Double click the .code-workspace file in your platform's Explorer.
  • Use the File > Open Workspace... command and select the Workspace file.
  • Select the Workspace from the File > Open Recent (⌃R (Windows, Linux Ctrl+R)) list.
    • Workspaces have a (Workspace) suffix to differentiate them from folders.

open recent workspace list

Just like Close Folder when a single folder is open in VS Code, there is a Close Workspace (⌘K F (Windows, Linux Ctrl+K F)) command to close the active Workspace.

Workspace file schema

The schema of .code-workspace is fairly straightforward. You have an array of folders with either absolute or relative paths. Relative paths are better when you want to share Workspace files.

You can override the display name of your folders with the name attribute for a clearer display in the Explorer. For example, you could more clearly name your project folders such as 'Product' and 'Documentation':

{
    "folders": [
        {
            // Source code
            "name": "Product",
            "path": "vscode"
        },
        {
            // Docs and release notes
            "name": "Documentation",
            "path": "vscode-docs"
        },
        {
            // Yeoman extension generator
            "name": "Extension generator",
            "path": "vscode-generator-code"
        }
    ]
}

which will result in the following Explorer display:

named folders

As you can see from the example above, you can add comments to your Workspace files.

The Workspace file can also contain Workspace global settings under settings and extension recommendations under extensions which we will discuss below.

workspace file schema

General UI

Editor

There are only a few changes to the VS Code UI when you are using multi-root workspaces, primarily to disambiguate files between folders. For example, if there is a name collision between files in multiple folders, VS Code will include the folder name in tabbed headers.

tabbed headers

If you'd always like to see the folder displayed in the tabbed header, you can use the workbench.editor.labelFormat setting "medium" or "long" values to show the folder or full paths.

"workbench.editor.labelFormat": "medium"

VS Code UI such as the OPEN EDITORS or Quick Open (⌘P (Windows, Linux Ctrl+P)) list include the folder name.

quick pick has folder name

If you using an Icon Theme and the active theme supports it, you will see a special Workspace icon.

Below you can see the Workspace icons from the built-in Minimal (Visual Studio Code) icon theme:

custom workspace icon

VS Code features like global search work across all folders and group the search results by folder.

multi-root search results

When you have a multi-root workspace open, you can choose to search in a single root folder by using the ./ syntax in the files to include box. For example, if you enter ./project1/**/*.txt, that will search for all .txt files under the project1/ root folder.

Settings

With multiple root folders in one workspace, it is possible to have a .vscode folder in each root folder defining the settings that should apply for that folder. To avoid setting collisions, only resource (file, folder) settings are applied when using a multi-root workspace. Settings which affect the entire editor (for example, UI layout) are ignored. For example, two projects cannot both set the zoom level.

User settings are supported as with single folder project and you can also set global Workspace settings which will apply to all folders in your multi-root Workspace. Global Workspace settings will be stored in your .code-workspace file.

{
    "folders": [
        {
            "path": "vscode"
        },
        {
            "path": "vscode-docs"
        },
        {
            "path": "vscode-generator-code"
        }
    ],
    "settings": {
        "window.zoomLevel": 1,
        "files.autoSave": "afterDelay"
    }
}

When you go from a single folder instance to multiples folders, VS Code will add the appropriate editor-wide settings from the first folder to the new global Workspace settings.

You can easily review and modify the different settings files through the Settings editor. The Settings editor dropdown lets you select your User settings, global Workspace settings and individual folder settings.

settings dropdown

You can also open specific settings files with the commands:

  • Preferences: Open User Settings - Open your global User settings
  • Preferences: Open Workspace Settings - Open the settings section of your Workspace file.
  • Preferences: Open Folder Settings - Open the settings for the active folder.

Global Workspace settings override User settings and folder settings can override Workspace or User settings.

Unsupported folder settings

Unsupported editor-wide folder settings will show as grayed out in your folder settings and are filtered out of the DEFAULT FOLDER SETTINGS list. You will also see an information icon in front of the setting.

unsupported setting information

Debugging

With multi-root workspaces, VS Code searches across all folders for launch.json debug configuration files and displays them with the folder name as a suffix.

debugging dropdown

The example above shows the debugging configurations for the TSLint extension. There is a launch configuration from the tslint extension folder to start the extension running in the VS Code Extension Host and also an attach configuration from the tslint-server folder to attach the debugger to a running TSLint server.

You can also see the three Add Config commands for the folders, tslint, tslint-server, and tslint-tests, in the vscode-tslint Workspace. The Add Config command will either open an existing launch.json file in the folder's .vscode subfolder or create a new one and display the debugging configuration template dropdown.

debugging template dropdown

Variables used in a configuration (for example ${workspaceFolder} or the now deprecated ${workspaceRoot}) are resolved relative to the folder they belong to.

Tasks

Similar to how VS Code searches for debugging configurations, VS Code will also try to autodetect tasks from gulp, grunt, npm, and TypeScript project files across all folders in a workspace as well as search for tasks defined in tasks.json files. The location of tasks is indicated by a folder name suffix. Note that tasks defined in tasks.json must be version 2.0.0.

tasks dropdown

From the TSList extension Workspace example above, you can see that there are two configured tasks from tasks.json files in the tslint and tslist-tests folders and numerous autodetected npm and TypeScript compiler detected tasks.

Source Control

With multi-root workspaces there is a SOURCE CONTROL PROVIDERS section which gives you an overview when you have multiple active repositories. These can be contributed by several SCM providers; for example, you can have Git repositories side-by-side with TFS workspaces. As you select repositories in this view, you can see the source control details below.

multiple scm providers

You can use Ctrl+Click or Shift+Click to select multiple repositories. Their details will appear as separate regions underneath.

Extensions

Multi-root workspaces have been available as a preview on Insiders build since the June 2017 1.14 release and we've been working with extension authors to help them get ready for the release to Stable. If you are an extension author, you can review our Adopting Multi Root Workspace APIs guide to learn about VS Code API changes and how to make your extension work well across multiple folders.

Below are some of the popular extensions which have already adopted the multi-root workspace APs.

Note: If an extension doesn't yet support multiple folders, it will still work in the first folder of your multi-root workspace.

Extension recommendations

VS Code supports folder level extension recommendations through the extensions.json files under the folder's .vscode subfolder. You can also provide global Workspace extension recommendations by adding them to your .code-workspace file. You can use the Extensions: Configure Recommended Extensions (Workspace) command to open your Workspace file and add extension identifiers ({publisherName}.{extensionName}) to the extensions.recommendations array.

{
    "folders": [
        {
            "path": "vscode"
        },
        {
            "path": "vscode-docs"
        }
    ],
    "extensions": {
        "recommendations": [
            "eg2.tslint",
            "dbaeumer.vscode-eslint",
            "msjsdiag.debugger-for-chrome"
        ]
    }
}

Next Steps

  • Debugging - Learn how to set up debugging for your application.
  • Tasks - Tasks let you run external tools like compilers within VS Code.

Common Questions

Q: How can I go back to working with a single project folder?

You can either close the Workspace and open the folder directly or remove the folder from Workspace.

Q: As an extension author what do I need to do?

See our Adopting Multi Root Workspace APIs guide. Most extensions can easily support multi-root workspaces.