Skip to content

Use fresh environment block on new terminals in Windows #47816

Open

Description

At the moment, if any environment variables change, or new "apps" are installed while VS Code is running, in order for those changes to be recognized VS Code needs to be closed and re-open.

For instance, when running npm i -g <something> or choco install <package> in another prompt or powershell window, those new commands are not recognized until the app is rebooted.

It would be great if adding a new terminal instance with + would load these new variables/apps/notsurewhatterminologytouse.

Activity

  1. added
    terminal
    on Apr 13, 2018
  2. MirzaSikander commented on Apr 19, 2018

    @MirzaSikander

    Worse yet, if you have multiple instances of vscode running, all of them need to be killed and restarted for the environment variables to be updated for the sake of one window where you needed it.

  3. MirzaSikander commented on Apr 19, 2018

    @MirzaSikander

    Actually it is stuck in a weird state. Two instances have different values for the same variable. One is updated while the other is not. Not sure how to reproduce it. I think it is somehow tied to different workspaces. It would be great if somebody could shine a light on how vscode powershell integrated terminal fetches the environment variable.

  4. MirzaSikander commented on Apr 19, 2018

    @MirzaSikander

    Okay so I think I found two different issues.

    • You do need to kill all instances to refresh environment variables. This is easy to repro.
    1. Start 2 vscode instances pointing to different directories.
    2. Add a new env variable through System Properties > Environement variables called TEST
    3. Check $env:TEST in both instances. Result: Not updated.
    4. Restart one instance by killing it and then using Open folder to open the directory. Check again. Result: Not updated.
    5. Restart both instances by killing both and using Open folder. Check again. Result: Updated.
    • The second issue is that if you open your workspaces using links under Recent, you will find that even after restarting VSCode, the environment variables are not updated.
    1. Start one instance.
    2. Update env variable.
    3. Kill instance.
    4. Open VScode by right clicking on Task bar and selecting the folder from Recent Workspaces
    5. Check env variable. Result: Not updated.
  5. Tyriar commented on May 15, 2018

    @Tyriar
    Contributor

    npm i -g <something>

    Éric-Sébastien Lachance (@eslachance) are you on Windows? Isn't the global node_modules bin directory added to PATH, I would have expected this to work?

  6. added
    feature-request
    info-needed
    on May 15, 2018
  7. eslachance commented on May 15, 2018

    @eslachance
    Author

    I believe what I added was a global module such as eslint or it might have been windows-built-tools which of course does more than just copy javascript to the node modules. However, this does not simply affect node. This affects any and all things that you can do that adds something to the path, or does anything to modify what's accessible from the console. So even though my request stems from using npm i -g, the actual issue is broader and the feature request would definitely enhance the user experience for a lot of people (in my humble opinions).

  8. removed
    info-needed
    on May 15, 2018
  9. added this to the Backlog milestone on May 15, 2018
  10. claudeleveille commented on Jun 5, 2018

    @claudeleveille

    Git also seems to be affected by this. Specifically, the ssh-agent included in Git for Windows. This program relies on environment variables to work, so when VS Code is started before the ssh-agent program, VS Code's Git integration can never find out about the ssh-agent process and make use of the SSH keys stored in there. VS Code as a whole should periodically refresh it's environment variables to fix all of the issues mentioned here, and possibly also as a response to certain events. A rejected Git push/pull based on a failed publickey authentication attempt comes to mind as a good idea for the first event.

  11. jonfelske commented on Jun 19, 2018

    @jonfelske

    One thing that worked for me ( on mac ) was to add the environment variables to the bash profile. That way whenever you restart vscode or open a new terminal instance anything in the profile is loaded.

    jonfelske$ vi ~/.bash_profile
    # Environment variable needed
    export YOUR_ENV_VAR_NAME="some value here"
    

    You can then either restart the terminal or use "source ~/.bash_profile" and the environment variable will be picked up. Hope that helps! :)

  12. claudeleveille commented on Jun 24, 2018

    @claudeleveille

    What I ended up doing is installing PuTTY and running setx.exe GIT_SSH "C:\Program Files\PuTTY\plink.exe". Then I could load my keys into pagent and never had any other problems (except for not being able to accept host key fingerprints with Git). To trust host keys: echo 'y' | plink.exe <hostname-or-ip> does the trick in a script (though that's not super secure, I know).

    If only we could just converge on a single SSH suite inside of Windows, whether that's the WSL one, or the native port. I think that even PowerShell has some SSH functionality built-into sessions now.

  13. nishant-labs commented on Aug 31, 2018

    @nishant-labs

    I have same issue on mac for .bash_profile changes to take effect, Either will have to restart whole vscode IDE or execute "source ~/.bash_profile".

    Apart from that I have issue with duplicated paths in PATH variable.
    Below code is in .bash_profile:-

    MAVEN_HOME=/Users/<user>/apache-maven-3.5.2
    TEST=/Users/<user>/test_1_0
    PATH=$PATH:$MAVEN_HOME/bin:$TEST

    When I echo in mac terminal I get
    <other paths>:/Users/<user>/apache-maven-3.5.2/bin:/Users/<user>/test_1_0

    where as vscode integrated terminal outputs as
    <other paths>:/Users/<user>/apache-maven-3.5.2/bin:/Users/<user>/test_1_0:/Users/<user>/apache-maven-3.5.2/bin:/Users/<user>/test_1_0

    Can you please resolve this.

  14. 65 remaining items

  15. bradthomasbrown commented on Jan 5, 2026

    @bradthomasbrown

    Hard to believe this issue has been open for 7 years without any progress whatsoever.

    It's MicroSlop, what on earth did you expect?

  16. zeel01 commented on Feb 4, 2026

    @zeel01

    Is there really not even a work around for this? Needing to restart all VS Code instances because something was added to the PATH is not a very good user experience. It's one thing with a regular terminal but the whole IDE is another story, there must be some way to pick up these changes even if it means resetting the terminal session in the terminal panel.

  17. lolrobbe2 commented on Feb 5, 2026

    @lolrobbe2

    Josh Olsen (@zeel01) No not really, what i did was create a terminal that when started fetches the environment variables itself on creation:

    //
    context.subscriptions.push(vscode.window.registerTerminalProfileProvider('premake5.environment-profile', {
    		provideTerminalProfile: async () => {
    			await EnvironmentRefresher.refreshWindowsPath();
    
    			const isWindows = process.platform === 'win32';
    			const shellPath = isWindows ? 'cmd.exe' : 'bash';
    
    			return {
    				options: {
    					name: 'Premake CLI',
    					shellPath: shellPath,
    					env: process.env,
    					iconPath: vscode.Uri.file(context.asAbsolutePath("resources/media/premake-logo.png"))
    				}
    			};
    		}
    	}));
    import { exec } from "child_process";
    import * as os from "os";
    import * as vscode from "vscode";
    import { Prompt } from "./prompt-utils";
    export class EnvironmentRefresher {
    
        /** */
    //function to refreseh the PATH from EnvironmentRefresher
        public static async refreshWindowsPath(): Promise<void> {
     
            return new Promise((resolve, reject) => {
                const platform = os.platform();
    
                let command: string;
    
                if (platform === "win32") {
                    // Windows: Combine Machine and User PATH
                    command = `powershell.exe -NoProfile -Command "& {[Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'User')}"`;
                } else {
                    // Unix: Launch a login shell and print updated PATH
                    command = `bash -ilc 'echo $PATH'`; // works for bash, adjust if user uses zsh or other
                }
    
                exec(command, (error, stdout) => {
                    if (error) {
                        reject(new Error(`Failed to retrieve PATH: ${error.message}`));
                        return;
                    }
    
                    const newPath = stdout.trim();
                    if (newPath.length > 0) {
                        process.env['Path'] = newPath;
                        resolve();
                    } else {
                        reject(new Error("Failed to retrieve a non-empty PATH."));
                    }
                });
            });
        }

    the code comes from the premake manager extension
    CODE

  18. sdg002 commented on Apr 28, 2026

    @sdg002

    Just faced this issue (Windows 11). I spent about 20 minutes pulling my hair trying to figure out why a newly configured environment variable was not showing up in the Terminal Window.

    I had to close all running instances of VS Code and then it worked.

    System info

    Version: 1.117.0 (user setup)
    Commit: 10c8e557c8b9f9ed0a87f61f1c9a44bde731c409
    Date: 2026-04-21T16:12:14-07:00
    Electron: 39.8.7
    ElectronBuildId: 13841579
    Chromium: 142.0.7444.265
    Node.js: 22.22.1
    V8: 14.2.231.22-electron.0
    OS: Windows_NT x64 10.0.22631
    
  19. jankap commented on May 12, 2026

    @jankap

    Indeed, annoying issue. Even closing all VSC instances did not help, also not via task manager. Only option for me was to restart the PC...

  20. zeel01 commented on May 12, 2026

    @zeel01

    Come on Microsoft, it's been eight years since this issue was opened. Could you please take a week off from shoving more AI nonsense into the IDE and fix a real problem?

    At an absolute minimum, reloading the VS Code window should get us a new terminal session. Fully relaunching the application with multiple workspaces open is a complete non-starter. But I would find it hard to believe if you guys can't come up with a way to allow a new terminal session to actually be a new terminal session without needing anything else restarted.

  21. lolrobbe2 commented on May 12, 2026

    @lolrobbe2

    Come on Microsoft, it's been eight years since this issue was opened. Could you please take a week off from shoving more AI nonsense into the IDE and fix a real problem?

    At an absolute minimum, reloading the VS Code window should get us a new terminal session. Fully relaunching the application with multiple workspaces open is a complete non-starter. But I would find it hard to believe if you guys can't come up with a way to allow a new terminal session to actually be a new terminal session without needing anything else restarted.

    the refresh code i provided could be used as a solution?!

  22. adamerose commented on May 26, 2026

    @adamerose

    Until this is implemented, my work around is running this in Git Bash:

    taskkill -IM code.exe -F && start code
    

    When you force-kill VS Code instances instead manually closing them, you get all the same project windows restored to their previous positions automatically.

  23. zeel01 commented on May 26, 2026

    @zeel01

    When you force-kill VS Code instances instead manually closing them, you get all the same project windows restored to their previous positions automatically.

    This is a good bit of advice, however for those of us that use multiple desktops it causes a problem because of #146915

  24. frozenprakash commented on Jun 19, 2026

    @frozenprakash

    No wonder devs are moving to cursor, even with little close devs, they would implement it right away, and here with serious bug like this which is open for almost a decade!

  25. frozenprakash commented on Jun 19, 2026

    @frozenprakash

    Found a simple hack,

    1. Update to env variable - Environment.SetEnvironmentVariable("PATH", updated, EnvironmentVariableTarget.User)
      This doesn't work as it does not refresh inside vs code terminal - still we can update this so it will be usable in terminal outside vs code

    2. We can additionally update the vs code settings.json, which will instantly allow usage in terminal

    %appdata%\Code - Insiders\User\settings.json

    "terminal.integrated.env.windows": {
        "PATHEXT": "${env:PATHEXT};.CSX",
        // PATH segments:
        //   1. ${env:USERPROFILE}\.copilot\skills\open\scripts
        //   2. ${env:USERPROFILE}\source\repos\repo1\.github\skills\x-commands\scripts
        "PATH": "${env:PATH};${env:USERPROFILE}\\.copilot\\skills\\open\\scripts;${env:USERPROFILE}\\source\\repos\\repo1\\.github\\skills\\x-commands\\scripts"
      }
    

    I simply make it as a skill for this 2 step process, later i simply need to pass the file / path to this skill and it'll do the honors.

  26. added a commit that references this issue on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestterminal-processwindows

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions