vscode: Incorrect $PATH order in task shell

Type: Bug

I have a custom task in tasks.json. Since upgrading to 1.80 it’s loading my $PATH env variable in an incorrect order.

I have tested this by adding this task in tasks.json.

{
  "label": "echo PATH",
  "type": "shell",
  "command": "echo $PATH"
},

When I run this task it shows a different $PATH than when I choose New Terminal within VS Code and run echo $PATH. The paths themselves appear the same, just in a different order which is causing issues with finding the proper bins.

I’m on Mac OS X 13.3 and use zsh.

VS Code version: Code 1.80.1 (Universal) (74f6148eb9ea00507ec113ec51c489d6ffb4b771, 2023-07-12T17:20:23.298Z) OS version: Darwin x64 22.4.0 Modes:

System Info
Item Value
CPUs Intel® Core™ i9-9880H CPU @ 2.30GHz (16 x 2300)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 2
Memory (System) 16.00GB (0.58GB free)
Process Argv . --crash-reporter-id f3967eb1-1d64-41bb-a279-ee5aa5d9697f
Screen Reader no
VM 0%
Extensions (12)
Extension Author (truncated) Version
vscode-toggle-quotes Bri 0.3.6
compulim-vscode-closetag Com 1.2.0
vscode-mac-color-picker dae 1.1.0
vscode-eslint dba 2.4.2
ERB Syntax und 0.0.1
prettier-vscode esb 9.19.0
batch-rename-extension Jan 0.0.6
dotenv mik 1.0.1
remote-containers ms- 0.299.0
material-icon-theme PKi 4.28.0
vscode-syntax-tree rub 0.5.1
svelte-vscode sve 107.8.0

(1 theme extensions excluded)

A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263cf:30789497
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30610679
282f8724:30602487
pyind779:30671433
89544117:30613380
vscrp:30673768
pythonsymbol12:30671437
showlangstatbar:30737416
vsctsb:30748421
pythonms35:30701012
03d35959:30757346
pythonfmttext:30731395
pythoncmv:30756943
fixshowwlkth:30771522
showindicator:30785052
pythongtdpath:30769146
i26e3531:30780429
pythonnosmt12:30779714
pythonidxpt:30784022
pythonnoceb:30776495
h7j2d465:30786200
dsvsc013cf:30789518

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 7
  • Comments: 34 (10 by maintainers)

Most upvoted comments

I think this one is probably related: https://github.com/microsoft/vscode/issues/186244

I’m also adopting the source ~/.zshrc && in the command workaround suggested in that linked issue, seems like the only thing that works for now

I’m not sure why it would be breaking anything for you though 🤔

Changing the order of the path breaks a lot of things for me, it is loading system versions of things like Ruby etc instead of my local ones 😅 I tried to override the behavior with options.env.PATH but that gets blown away too.

I am a little surprised that there’s not more activity on this issue, my environment must be weirder than I thought, because I thought this would have blown a lot of people up

@meganrogge I wonder if it’s due to this commit. Not sure if this is in 1.80. https://github.com/microsoft/vscode/commit/ca9192e80b096d715378e905fc074723924bad10

It’s strange that the PR this commit references (https://github.com/microsoft/vscode/pull/186938) seems to just be for performance but the commit seems to remove fetching the shell env.

This worked as expected with the following version of vscode:

Version: 1.79.2
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:58:33.551Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 23.3.0

And was broken on the following version:

Version: 1.80.2
Commit: 2ccd690cbff1569e4a83d7c43d45101f817401dc
Date: 2023-07-27T20:57:59.134Z
Electron: 22.3.14
ElectronBuildId: 22695494
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 23.3.0

This is also a problem for me when using Conda python environments because the system version of python is selected instead of the version used in the environment.

macOS terminal:

> echo $PATH | tr ':' '\n'
/Users/*****/miniconda3/envs/test/bin
/Users/*****/miniconda3/condabin
/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/Apple/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
> conda info --env
# conda environments:
#
base                     /Users/*****/miniconda3
test                  *  /Users/*****/miniconda3/envs/test
> which -a python3
/Users/*****/miniconda3/envs/test/bin/python3
/usr/bin/python3

Inside vscode task:

> echo $PATH | tr ':' '\n'
/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/Apple/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
/Users/*****/miniconda3/envs/test/bin
/Users/*****/miniconda3/condabin
> conda info --env
# conda environments:
#
base                     /Users/*****/miniconda3
test                  *  /Users/*****/miniconda3/envs/test
> which -a python3
/usr/bin/python3
/Users/*****/miniconda3/envs/test/bin/python3

I have the same issue.

Version: 1.81.1
Date: 2023-08-09T22:18:39.991Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 6.4.11-arch2-1

Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794

.vscode/tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo PATH",
      "type": "shell",
      "command": "echo $PATH | tr ':' '\\n'"
    }
  ],
}

Executing the task

 *  Executing task: echo $PATH | tr ':' '\n' 

/usr/local/bin
/usr/bin
/usr/local/sbin
/var/lib/flatpak/exports/bin
/usr/bin/site_perl
/usr/bin/vendor_perl
/usr/bin/core_perl
 *  Terminal will be reused by tasks, press any key to close it. 

From terminal

$ echo $PATH | tr ':' '\n'
/home/us-er/.local/share/rtx/installs/node/18.17.1/bin
/home/us-er/.local/share/rtx/installs/go/1.21.0/go/bin
/home/us-er/.local/share/rtx/installs/go/1.21.0/packages/bin
/home/us-er/.local/share/rtx/installs/java/openjdk-17/bin
/home/us-er/.local/share/rtx/installs/nim/2.0.0/bin
/home/us-er/.local/share/rtx/installs/nim/2.0.0/nimble/bin
/home/us-er/.local/share/rtx/installs/rust/1.72.0/bin
/home/us-er/.local/share/rtx/installs/bin/0.17.0/bin
/home/us-er/.local/share/rtx/installs/pipx/1.2.0/bin
/home/us-er/.local/share/rtx/installs/zig/0.11.0/bin
/home/us-er/.local/share/rtx/installs/shfmt/3.7.0/bin
/home/us-er/.local/share/rtx/installs/ninja/1.11.1/bin
/home/us-er/.local/share/rtx/installs/neovim/0.9.1/bin
/home/us-er/.local/share/rtx/installs/kotlin/1.9.10/kotlinc/bin
/home/us-er/.local/share/rtx/installs/kotlin/1.9.10/kotlin-native/bin
/home/us-er/.local/share/rtx/installs/cmake/3.27.4/bin
/home/us-er/.local/share/rtx/installs/meson/1.2.1/bin
/home/us-er/.local/share/rtx/installs/shellcheck/0.9.0/bin
/usr/local/bin
/usr/bin
/usr/local/sbin
/var/lib/flatpak/exports/bin
/usr/bin/site_perl
/usr/bin/vendor_perl
/usr/bin/core_perl
/home/us-er/.local/bin

Current work around:

~/.zprofile

# ~/.zprofile

# Import the default profile
if [ -f "/etc/profile" ]; then
    # shellcheck disable=SC1091
    . "/etc/profile"
fi

# Append "$1" to $PATH when not already in.
append_path() {
    case ":$PATH:" in
    *:"$1":*) ;;
    *)
        export PATH="${PATH:+$PATH:}$1"
        ;;
    esac
}

# user-paths
append_path "$HOME/.local/bin"
eval "$(/usr/bin/rtx activate zsh)"
#append_path "$HOME/.local/share/rtx/shims" # slower

unset -f append_path

@meganrogge @Tyriar can you reopen this issue? It’s still a problem. What information do you need from me to help resolve it?

@ryanb in which case I think it is expected since the builtin git extension uses this API