EDIT in 2023: I have macOS 13.2 Ventura and vscode 1.74.3 installed now, and this problem isn't reproducing the same way anymore. It looks like this is due to a relatively new vscode feature, Terminal Environment inheritance which is running the login shell:
When VS Code is opened, it launches a login shell environment in order to source a shell environment. This is done because developer tools are often added to the
$PATH
in a shell launch script like~/.bash_profile
.
This doesn't change the question, about a general fix without every app needing to add this custom workaround.
I have the option "Reopen windows when logging back in" set, which on my 11.6 macbook will reopen apps like vscode and iTerm2 after I restart. I want the reopened windows to have the expected environment variables set.
Most apps will reopen with no problem, but in vscode I'll get the error The terminal process failed to launch: Path to shell executable "pwsh" does not exist.
As far as I can tell, the problem is related to the system procedure for creating PATH
not running for windows reopened at login. By launching bash I can see the process PATH
environment variable is something like /usr/bin:/bin:/usr/sbin:/sbin
which explains the "pwsh" does not exist
error... (because pwsh
is in /usr/local/bin/
which normally is in my PATH
but is missing here.)
I could solve the immediate problem by specifying the full path to my shell executable in my vscode config, but other tools in /etc/paths
wouldn't be included in PATH
automatically either.
Is there some macOS setting I can change so that reopened windows have the right environment variables?
Or, I see that when iTerm2 reopens it starts my pwsh
shell and somehow has the correct PATH
-- could the vscode app copy the startup logic from iTerm2 to start with the right environment variables?