pi-mono/packages/coding-agent/docs/windows.md
Petr Houška e8ee38887e
fix(coding-agent): find Git Bash of git on PATH on Windows (#12494)
Fixes #12408

## Problem

On Windows, bash resolution only probes `%ProgramFiles%\Git` and
`%ProgramFiles(x86)%\Git`, then takes the first `bash.exe` from `where`.
With Git for Windows installed elsewhere, that is usually the WSL
launcher `System32\bash.exe`: commands fail (WSL disabled) or run inside
the distro.

## Fix

Ask the `git.exe` on `PATH` where it is installed: `git var
GIT_SHELL_PATH` (Git 2.47+) reports `<root>/usr/bin/sh.exe`. Use
`<root>\bin\bash.exe`, Git's launcher, which sets up `MSYSTEM` and
`PATH` (`usr\bin\bash.exe` alone cannot find `ls`).

This avoids guessing the root from the location of `git.exe`, which
depends on the PATH option and MSYSTEM flavor (`cmd`, `bin`,
`mingw64\bin`, `ucrt64\bin`) and fails for package-manager shims.

Resolution order on Windows:

1. `shellPath`
2. Git Bash under Program Files (unchanged; no `git` process for default
installs)
3. Git Bash of `git.exe` on `PATH` (new)
4. `bash.exe` on `PATH`

If Git is older than 2.47, reports a shell outside the `usr\bin\sh.exe`
layout, or has no `bin\bash.exe`, resolution continues with step 4.

Durable's `NodeExecutionEnv` mirrors the same lookup.

## Tests

`packages/coding-agent/test/windows-shell-config.test.ts`: Git Bash of
git on PATH wins over the WSL launcher; Program Files still wins without
spawning git; fallbacks for old Git, unexpected shell path, missing
launcher.

This PR is AI-generated.
2026-11-24 21:44:36 +01:00

5.9 KiB

Run Pi on Windows

Run Pi either as a native Windows process or inside Windows Subsystem for Linux (WSL). Native Windows uses Git Bash by default for Bash commands and can optionally expose PowerShell to the model. Pi inside WSL uses the Linux environment and its Bash installation.

Follow the main Quickstart to install and authenticate Pi. Use this page to choose and configure its command environment.

Choose native Windows or WSL

Environment Command environment Use it when
Native Windows with Git Bash Git Bash for the built-in bash tool and ! commands Your files and development tools primarily live on Windows
Native Windows with the powershell tool PowerShell for model tool calls; Bash remains available for ! commands The task depends on PowerShell modules or Windows-native commands
WSL Linux Bash and tools inside the selected WSL distribution Your files and toolchain already live in Linux or WSL

Use Git Bash on native Windows

For most native Windows users, installing Git for Windows is sufficient.

Pi resolves Bash in this order:

  1. shellPath from ~/.pi/agent/settings.json
  2. Git Bash at %ProgramFiles%\Git\bin\bash.exe
  3. Git Bash at %ProgramFiles(x86)%\Git\bin\bash.exe
  4. Git Bash of the Git for Windows installation whose git.exe is on PATH, wherever it is installed (Git 2.47 or later)
  5. bash.exe on PATH, including Cygwin, MSYS2, or legacy WSL Bash

Start Pi and enter this command to verify the shell:

!printf 'Bash is working\n'

If Pi cannot find Bash, it reports the locations it checked. Install Git for Windows, put another Bash executable on PATH, or configure shellPath.

Let the model use PowerShell

The optional powershell tool runs commands through pwsh.exe when available, then falls back to Windows PowerShell. It starts PowerShell with -NoProfile -NonInteractive -ExecutionPolicy Bypass. Administrator-enforced execution policies can still take precedence.

PowerShell discovery checks these locations in order:

  1. pwsh.exe on PATH
  2. %ProgramFiles%\PowerShell\7\pwsh.exe
  3. powershell.exe on PATH
  4. %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe

To replace the model-facing bash tool with powershell, add this to ~/.pi/agent/settings.json:

{
  "defaultTools": ["read", "powershell", "edit", "write"]
}

["-bash", "+powershell"] does the same while keeping any other default tools you configured.

Restart Pi, then ask it to run a harmless PowerShell command. The ! and !! editor commands continue to use Bash. The powershell tool is available only when Pi runs as a native Windows process.

See Settings for other tool combinations.

WSL

WSL path conversion on Windows and extra Git branch polling in WSL recognize /mnt/<drive>, not custom mount roots.

When using the legacy WSL bash.exe launcher from Windows, Pi sends commands over stdin to avoid command-line quoting problems.

Use a custom Bash executable

Set shellPath when Bash is installed somewhere Pi does not discover automatically:

{
  "shellPath": "C:\\cygwin64\\bin\\bash.exe"
}

JSON uses backslashes for escape sequences. When you write a Windows path with backslashes, write each backslash twice, as shown above.

See Configure shell commands for command prefixes, aliases, and the complete shell-resolution behavior.

Choose a terminal

Windows terminals run Pi through a console host (conhost). Some bundle an up-to-date copy; others use the older one built into Windows, which has bugs that affect Pi.

We recommend Windows Terminal. It always ships an up-to-date conhost, and Pi is best tested with it.

Last updated: October 2026.

Terminal Conhost Status
Windows Terminal Bundled, current Recommended
VS Code, Tabby, WezTerm nightly Bundled, current Works
Alacritty Built-in, unless conpty.dll and OpenConsole.exe from Windows Terminal are next to alacritty.exe Works only with those files
WezTerm 20240203 and older Bundled, old Known issues
Classic console (cmd.exe or PowerShell without Windows Terminal), mintty (Git Bash), ConEmu, Cmder, Hyper, Windows OpenSSH Built-in Known issues

Configure Windows Terminal

Windows Terminal reserves or rewrites some modified keys. See Windows Terminal to configure Shift+Enter and Alt+Enter, and Keybindings for Pi's Windows and WSL shortcut defaults.

Known issues

These issues come from conhost. Microsoft has fixed them in its source, but has not said when the built-in conhost will get the fixes.

Issue Affects Remedy
Switching from fullscreen to regular mode, or Ctrl+G from fullscreen, crashes the session (#9186, microsoft/terminal#17515) Built-in conhost Use a terminal with a current conhost, or start Pi with --tui-mode regular
Text such as ;0;rgb:0000/0000/0000 appears in the prompt, and BEL opens the external editor (#10256) Built-in conhost behind another terminal: mintty, Windows OpenSSH Use a terminal with a current conhost
Fragments such as 79 or 55 appear in the prompt (#10717) WezTerm 20240203 Use WezTerm nightly
In regular mode, each keystroke redraws the input line on a new row (#6300) Built-in conhost, classic console Use fullscreen mode (the default), or a terminal with a current conhost