Skip to content

Commit bda8c85

Browse files
Copilotntrogh
andauthored
Document --user-data-dir for VS Code instance isolation (#8996)
* Initial plan * Document VS Code instance isolation with --user-data-dir Co-authored-by: ntrogh <[email protected]> * Address review feedback: update heading level, note format, and remove examples Co-authored-by: ntrogh <[email protected]> * Remove additional line about unexpected issues as requested Co-authored-by: ntrogh <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ntrogh <[email protected]>
1 parent e88348b commit bda8c85

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

docs/configure/command-line.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ There are several CLI options that help with reproducing errors and advanced set
124124
Argument|Description
125125
------------------|-----------
126126
`--extensions-dir <dir>` | Set the root path for extensions.<br>Overridden in [Portable Mode](/docs/editor/portable.md) by the `data` folder.
127-
`--user-data-dir <dir>` | Specifies the directory that user data is kept in, useful when running as root.<br>Overridden in [Portable Mode](/docs/editor/portable.md) by the `data` folder.
127+
`--user-data-dir <dir>` | Specifies the directory that user data is kept in. Can be used to run multiple isolated instances of VS Code with separate environments, settings, and extensions. Also useful when running as root.<br>Overridden in [Portable Mode](/docs/editor/portable.md) by the `data` folder.
128128
`-s, --status` | Print process usage and diagnostics information.
129129
`-p, --performance` | Start with the **Developer: Startup Performance** command enabled.
130130
`--disable-gpu` | Disable GPU hardware acceleration.
@@ -135,6 +135,35 @@ Argument|Description
135135
`--add <dir>` | Add folder(s) to the last active window for a multi-root workspace.
136136
`--remove <dir>` | Remove folder(s) from the last active window for a multi-root workspace.
137137

138+
## Isolating VS Code instances
139+
140+
By default, VS Code instances share environment variables in the following way:
141+
142+
* If this is the first VS Code instance, environment variables are inherited from the parent process.
143+
* If this is not the first VS Code instance, environment variables are inherited from the already running VS Code instance.
144+
145+
This behavior can cause issues when you need different environment variables for different projects or build configurations. For example, if you're working on two projects that require different versions of Node.js or different `PATH` settings.
146+
147+
To run VS Code instances with separate environment variables, use the `--user-data-dir` option to specify a unique user data directory for each instance:
148+
149+
```bash
150+
# First instance with its own environment
151+
code ~/project1 --user-data-dir ~/vscode-data-project1
152+
153+
# Second instance with different environment
154+
code ~/project2 --user-data-dir ~/vscode-data-project2
155+
```
156+
157+
Each instance with a different `--user-data-dir` will maintain its own:
158+
159+
* Environment variables
160+
* Settings and preferences
161+
* Installed extensions
162+
* UI state and layout
163+
164+
> [!NOTE]
165+
> When using `--user-data-dir`, you'll need to reinstall extensions for each user data directory, as extensions are stored separately.
166+
138167
### Create remote tunnel
139168

140169
VS Code integrates with other [remote environments](/docs/remote/remote-overview.md) to become even more powerful and flexible. Our goal is to provide a cohesive experience that allows you to manage both local and remote machines from one, unified CLI.

docs/terminal/advanced.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ When VS Code is opened, it launches a login shell environment in order to source
176176

177177
This environment inheritance can be disabled on macOS and Linux via the `setting(terminal.integrated.inheritEnv)` setting.
178178

179+
### Environment variables between VS Code instances
180+
181+
When launching multiple VS Code instances, environment variables are shared between them:
182+
183+
* The first VS Code instance inherits environment variables from the parent process (for example, the shell or application that launched VS Code).
184+
* Subsequent VS Code instances inherit environment variables from the first running VS Code instance, not from the parent process.
185+
186+
To isolate environment variables between VS Code instances, use the [`--user-data-dir` command-line option](/docs/configure/command-line.md#isolating-vs-code-instances) to run each instance with a separate user data directory. This ensures that each instance maintains its own environment, settings, and extensions.
187+
179188
### Interaction with `$LANG`
180189

181190
There is some special interaction with the `$LANG` environment variable, which determines how characters are presented in the terminal. This feature is configured with the `setting(terminal.integrated.detectLocale)` setting:

0 commit comments

Comments
 (0)