You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use fresh environment block on new terminals in Windows #47816
feature-requestRequest for new features or functionalityterminal-processProblems launching processes, managing ptys, exiting, process leaks, etc.windowsVS Code on Windows issues
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.
Reacted by Mirza Sikander, Himanshu Negi, Claude Léveillé, Zane Hitchcox, TimHambourger, Andrew Scott, Eylon Sultan, Yu Zhang, Tanja, Kevin S. and 118 more
Reacted by Bo Lingen, ShaimaNourddine, Kartik Raj, Carlos DaLomba, Noah Gilson, GStudiosX, Bruno Cabral, Mateusz Kurowski and Josh Olsen
Reacted by Tanja, Bo Lingen, Misael Villaverde, nikolaysalinder, Kartik Raj, Carlos DaLomba, Welding Torch, Nam Nguyen Thai - CLV, aarowman, GStudiosX and 4 more
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.
Reacted by Leon V, nikolaysalinder, Christian Ezeani, Carlos DaLomba, Mateusz Marchewczyk, Sven Schöne, 2BitSalute, Carl Walsh, ZM, z combinator and 19 more
Reacted by Helder Hernández, Noah Gilson, Chris Kim and NatashaRice2018
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.
You do need to kill all instances to refresh environment variables. This is easy to repro.
Start 2 vscode instances pointing to different directories.
Add a new env variable through System Properties > Environement variables called TEST
Check $env:TEST in both instances. Result: Not updated.
Restart one instance by killing it and then using Open folder to open the directory. Check again. Result: Not updated.
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.
Start one instance.
Update env variable.
Kill instance.
Open VScode by right clicking on Task bar and selecting the folder from Recent Workspaces
Check env variable. Result: Not updated.
Reacted by asdfasdfasdfasdf asd, Lulus Young, Tanja, ShaoKang, Thabile, actboy168, BaronMing1, Kyle Delaney, Bruno Vinicius Figueiredo dos Santos, Edwin Hendriks and 33 more
É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?
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).
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.
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! :)
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.
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
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.
import{exec}from"child_process";import*asosfrom"os";import*asvscodefrom"vscode";import{Prompt}from"./prompt-utils";exportclassEnvironmentRefresher{/** *///function to refreseh the PATH from EnvironmentRefresherpublicstaticasyncrefreshWindowsPath(): Promise<void>{returnnewPromise((resolve,reject)=>{constplatform=os.platform();letcommand: string;if(platform==="win32"){// Windows: Combine Machine and User PATHcommand=`powershell.exe -NoProfile -Command "& {[Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'User')}"`;}else{// Unix: Launch a login shell and print updated PATHcommand=`bash -ilc 'echo $PATH'`;// works for bash, adjust if user uses zsh or other}exec(command,(error,stdout)=>{if(error){reject(newError(`Failed to retrieve PATH: ${error.message}`));return;}constnewPath=stdout.trim();if(newPath.length>0){process.env['Path']=newPath;resolve();}else{reject(newError("Failed to retrieve a non-empty PATH."));}});});}
the code comes from the premake manager extension CODE
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.
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.
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?!
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.
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
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!
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
We can additionally update the vs code settings.json, which will instantly allow usage in terminal
feature-requestRequest for new features or functionalityterminal-processProblems launching processes, managing ptys, exiting, process leaks, etc.windowsVS Code on Windows issues
Activity
MirzaSikander commentedon Apr 19, 2018
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.
MirzaSikander commentedon Apr 19, 2018
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.
MirzaSikander commentedon Apr 19, 2018
Okay so I think I found two different issues.
System Properties > Environementvariables calledTEST$env:TESTin both instances. Result: Not updated.Open folderto open the directory. Check again. Result: Not updated.Open folder. Check again. Result: Updated.Recent, you will find that even after restarting VSCode, the environment variables are not updated.Recent WorkspacesTyriar commentedon May 15, 2018
É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?
eslachance commentedon May 15, 2018
I believe what I added was a global module such as
eslintor it might have beenwindows-built-toolswhich 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).claudeleveille commentedon Jun 5, 2018
Git also seems to be affected by this. Specifically, the
ssh-agentincluded in Git for Windows. This program relies on environment variables to work, so when VS Code is started before thessh-agentprogram, VS Code's Git integration can never find out about thessh-agentprocess 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.jonfelske commentedon Jun 19, 2018
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.
You can then either restart the terminal or use "source ~/.bash_profile" and the environment variable will be picked up. Hope that helps! :)
claudeleveille commentedon Jun 24, 2018
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.
nishant-labs commentedon Aug 31, 2018
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.2TEST=/Users/<user>/test_1_0PATH=$PATH:$MAVEN_HOME/bin:$TESTWhen I echo in mac terminal I get
<other paths>:/Users/<user>/apache-maven-3.5.2/bin:/Users/<user>/test_1_0where 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_0Can you please resolve this.
65 remaining items
bradthomasbrown commentedon Jan 5, 2026
It's MicroSlop, what on earth did you expect?
zeel01 commentedon Feb 4, 2026
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.
lolrobbe2 commentedon Feb 5, 2026
Josh Olsen (@zeel01) No not really, what i did was create a terminal that when started fetches the environment variables itself on creation:
the code comes from the premake manager extension
CODE
sdg002 commentedon Apr 28, 2026
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
jankap commentedon May 12, 2026
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...
zeel01 commentedon May 12, 2026
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.
lolrobbe2 commentedon May 12, 2026
the refresh code i provided could be used as a solution?!
adamerose commentedon May 26, 2026
Until this is implemented, my work around is running this in Git Bash:
When you force-kill VS Code instances instead manually closing them, you get all the same project windows restored to their previous positions automatically.
zeel01 commentedon May 26, 2026
This is a good bit of advice, however for those of us that use multiple desktops it causes a problem because of #146915
frozenprakash commentedon Jun 19, 2026
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!
frozenprakash commentedon Jun 19, 2026
Found a simple hack,
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
We can additionally update the vs code settings.json, which will instantly allow usage in terminal
%appdata%\Code - Insiders\User\settings.jsonI 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.
Fix #12: Stale PATH when launching VS Code from Command Palette