Skip to content

On Windows, the which command doesn't respect changes to $env.PATHEXT #18419

Description

@pfmoore

Bug report form

  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.

Describe the bug

The which command on Windows finds program files. It does so using the PATHEXT environment variable, which lists file extensions that are to be treated as executable on Windows. However, if I temporarily change $env.PATHEXT using with-env, the which command does not see the change.

For what it's worth, if I change $env.PATH using with-env, this does correctly affect the behaviour of which.

How to reproduce

Demonstration of which finding an executable based on PATHEXT:

❯ $env.PATH.30
C:\Users\Gustav\.local\scripts
❯ ls C:\Users\Gustav\.local\scripts\tmp_py.py
╭───┬──────────────────────────────────────────┬──────┬───────┬─────────────╮
│ # │                   name                   │ type │ size  │  modified   │
├───┼──────────────────────────────────────────┼──────┼───────┼─────────────┤
│ 0 │ C:\Users\Gustav\.local\scripts\tmp_py.py │ file │ 127 B │ 2 years ago │
╰───┴──────────────────────────────────────────┴──────┴───────┴─────────────╯
❯ $env.PATHEXT
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYZ;.PYW;.PYZW
❯ which tmp_py
╭───┬─────────┬──────────────────────────────────────────┬──────────╮
│ # │ command │                   path                   │   type   │
├───┼─────────┼──────────────────────────────────────────┼──────────┤
│ 0 │ tmp_py  │ C:\Users\Gustav\.local\scripts\tmp_py.py │ external │
╰───┴─────────┴──────────────────────────────────────────┴──────────╯

Demonstration of temporary change to PATHEXT not working:

❯ ls C:\Users\Gustav\.local\scripts\v.ps1
╭───┬──────────────────────────────────────┬──────┬────────┬─────────────╮
│ # │                 name                 │ type │  size  │  modified   │
├───┼──────────────────────────────────────┼──────┼────────┼─────────────┤
│ 0 │ C:\Users\Gustav\.local\scripts\v.ps1 │ file │ 2.3 kB │ 5 years ago │
╰───┴──────────────────────────────────────┴──────┴────────┴─────────────╯
❯ which v
╭────────────╮
│ empty list │
╰────────────╯
❯ with-env { PATHEXT: ($env.PATHEXT + ";.ps1") } { which v }
╭────────────╮
│ empty list │
╰────────────╯

Demonstration that other commands see the change to PATHEXT:

❯ with-env { PATHEXT: ($env.PATHEXT + ";.ps1") } { py -c "import os; print(os.environ['PATHEXT'])" }
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYZ;.PYW;.PYZW;.ps1

Expected behavior

I expected the which command to correctly find executables with extensions added to PATHEXT via with-env, in the same way that it finds executables in directories added to PATH via with-env.

Configuration

❯ version | transpose key value | to md --pretty

key value
version 0.113.1
major 0
minor 113
patch 1
branch
commit_hash 7b7df4a
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.93.1 (01f6ddf75 2026-02-11)
rust_channel 1.93.1-x86_64-pc-windows-msvc
cargo_version cargo 1.93.1 (083ac5135 2025-12-15)
build_time 2026-05-29 22:36:34 +00:00
build_rust_channel release
allocator standard
features default, mcp, network, plugin, rustls-tls, sqlite, trash-support
installed_plugins formats 0.103.0
experimental_options example=false, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=false, native-clip=false, cell-path-types=false

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:environmentRelated to the management of environment variables/process stateplatform:windowsIssues which are specific to Windowsstatus:needs-triageAn issue that hasn't had any proper look

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions