Coding

VS Code Workspace Explained: Folders, Multi-Root and Settings

A VS Code workspace is the collection of one or more folders open in a VS Code window. Open one folder and that folder is your workspace; open several folders together and save them as a .code-workspace file to get a multi-root workspace.

Most people use workspaces without noticing, because code . or File > Open Folder... already creates one. This article covers what a workspace stores, how the two kinds differ, and how to create and save a multi-root workspace.

What a VS Code workspace contains

According to the VS Code documentation, a workspace can hold folder-specific settings, tasks and launch (debug) configurations, and saved interface state such as the files you had open and the editor layout. You can also enable or disable extensions per workspace. VS Code remembers that state per folder, so reopening a project brings back where you left off.

You can also use VS Code with no workspace at all, for example by opening a single file from the File menu. You can edit text that way, but some features are reduced because there is no folder to attach settings, tasks or search to.

Single-folder workspace vs multi-root workspace

Single-folderMulti-root
How you open itcode . or File > Open Folder...Open a <name>.code-workspace file
Where settings live.vscode/settings.json in the folderThe settings section of the .code-workspace file, plus each folder's own .vscode
Tasks and launch configsFiles in .vscodeEach folder's .vscode, plus tasks and launch sections in the workspace file
Explorer labelFolder nameRoot names, with a (Workspace) suffix when a workspace file is open

Use a single folder when one repository is the whole project. Use multi-root when related projects need to stay open side by side. The documentation's own example is a product's source code next to a documentation repository that must be kept up to date.

How to create a multi-root workspace

Any of these routes works:

  • File > Add Folder to Workspace, then pick a folder in the dialog. Right-clicking a root folder in the Explorer also offers add and remove commands.
  • Drag folders into the File Explorer. Dropping several folders at once into the editor area also creates a multi-root workspace, while dropping a single folder there opens it in single-folder mode.
  • Select several folders at once in your platform's open dialog.
  • From a terminal, code --add <folder> adds folders to the last active VS Code instance.

The first time you add a second folder, VS Code creates an untitled workspace, shown as "UNTITLED WORKSPACE". It survives restarts while you keep it open, and VS Code asks you to save it when you fully close the window. If you close the window and dismiss the save prompt, the untitled workspace is deleted.

How to save and reopen a workspace

Choose File > Save Workspace As... to write the .code-workspace file. Saving it again to a new location rewrites the folder paths relative to the new place. To open it later, double-click the file, use File > Open Workspace, or pick it from File > Open Recent, where workspaces carry a "(Workspace)" suffix. Close Workspace closes the active one.

You can open the Command Palette to run any of these by name; see the VS Code Command Palette guide.

What a .code-workspace file looks like

It is a JSON file that allows comments. Folders can use absolute or relative paths, and the documentation recommends relative paths if you share the file. The optional name overrides how a folder appears in the Explorer. Example file:

{
  "folders": [
    { "name": "Product", "path": "product" },
    { "name": "Docs", "path": "docs" }
  ],
  "settings": {
    "files.autoSave": "afterDelay"
  },
  "extensions": {
    "recommendations": ["dbaeumer.vscode-eslint"]
  }
}

Besides folders and settings, the file can contain extensions, launch and tasks sections. Here the two folders sit next to the workspace file as product and docs.

Which settings win in a workspace

There are three levels. User settings apply everywhere. Workspace settings override them, and folder settings override both. In a multi-root workspace the Settings editor shows a third scope called Folder Settings. The relevant commands are Preferences: Open User Settings, Preferences: Open Workspace Settings and Preferences: Open Folder Settings.

One limit surprises people: only resource-level settings (those that apply to files and folders) work per folder. Editor-wide settings such as the zoom level are ignored in a folder's .vscode when several folders are open, because two projects cannot both set the zoom for one window. Unsupported folder settings appear grayed out in the Settings editor with an information icon. When you move from one folder to several, VS Code copies the appropriate editor-wide settings from the first folder into the workspace settings.

Debugging, tasks, search and Git across folders

  • Launch configurations. VS Code reads launch.json from every folder and adds the folder name to each configuration. Workspace-wide configurations go in the launch section, which you open with Workspaces: Open Workspace Configuration File. Variables such as ${workspaceFolder} resolve relative to their own folder; to point at a specific one, add its name after a colon, as in ${workspaceFolder:Program}. Workspace-level configurations must use these scoped variables.
  • Tasks. Tasks in tasks.json must use version 2.0.0. Workspace-scoped tasks only allow the shell and process types.
  • Search. Results are grouped by folder. To limit a search to one root, start the files to include pattern with ./, for example ./project1/**/*.txt.
  • Source control. A SOURCE CONTROL PROVIDERS section lists every active repository, so each folder can be its own Git repository.

Limits and troubleshooting

  • An extension only works in the first folder. Extensions that do not support multiple folders still run, but only against the first folder. Check the extension's page or report it to its author.
  • Identical file names in tabs. When names collide, VS Code adds the folder name to the tab. Set workbench.editor.labelFormat to "medium" or "long" to always show it.
  • Lost an untitled workspace. It exists only while its window is open unless saved. Save it with Save Workspace As... before closing.
  • Moving the workspace file. Use Save Workspace As... rather than moving the file by hand, so relative folder paths are rewritten for you.

If you want a self-contained copy of VS Code with its own settings, that is a separate feature; see VS Code portable mode.

Frequently asked questions

Do I need a .code-workspace file to use VS Code?
No. Opening a single folder already makes it a workspace, and its settings, tasks and launch configurations live in a .vscode folder inside it. You only need a .code-workspace file when you want several folders open together and want to save that combination.
Where is a VS Code workspace saved?
A single-folder workspace is the folder itself, with settings in .vscode/settings.json. A multi-root workspace is saved as a JSON file named <name>.code-workspace, in a location you choose with File > Save Workspace As. Until you save it, it is an untitled workspace that VS Code keeps only for that window.
Which wins, workspace settings or folder settings?
Folder settings override settings in the .code-workspace file, and both override your User settings. Only resource-level settings apply per folder in a multi-root workspace; editor-wide settings such as zoom level are ignored at folder level.
How do I go back to a single folder?
Close the workspace with File > Close Workspace and then open the folder directly with File > Open Folder. You can also remove folders with Remove Folder from Workspace until only one is left.

Sources