#17113: Windows: prefer PowerShell 7 (pwsh) in shell resolution
agents
size: XS
Cluster:
Tool Execution and Error Handling
## Summary
On modern Windows setups, PowerShell 7 (`pwsh`) is commonly installed alongside Windows PowerShell 5.1 but not selected by default.
This PR updates Windows shell resolution to prefer PowerShell 7.
Resolution order:
```text
1. COMSPEC when it points to pwsh.exe
2. C:\Program Files\PowerShell\7\pwsh.exe
3. Windows PowerShell 5.1 (System32\WindowsPowerShell\v1.0\powershell.exe)
4. Final fallback: powershell.exe
```
- Keep `getShellConfig()` on `win32` aligned with this resolver.
- Update Windows assertion in `src/agents/shell-utils.e2e.test.ts` to accept either `powershell` or `pwsh`.
## Validation
- `lsp_diagnostics` clean on modified files.
- `pnpm test:e2e src/agents/shell-utils.e2e.test.ts` passes.
## Scope
This PR intentionally avoids generic PATH-based `pwsh` discovery to keep the change scoped to the original issue.
Closes #9629
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Updates Windows shell resolution to prefer PowerShell 7 (`pwsh.exe`) over Windows PowerShell 5.1 (`powershell.exe`). The new resolution order checks COMSPEC for pwsh.exe first, then looks for PowerShell 7 at the standard installation path (`C:\Program Files\PowerShell\7\pwsh.exe`), and falls back to Windows PowerShell 5.1 if neither is found.
**Key changes:**
- Modified `resolvePowerShellPath()` to prioritize PowerShell 7 detection
- Updated Windows test assertion to accept either `powershell` or `pwsh` in the shell path
- Maintains backward compatibility with Windows PowerShell 5.1 fallback
The implementation correctly handles quoted COMSPEC paths and uses proper file existence checks before returning paths. Test coverage appropriately reflects the new behavior.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are narrow in scope, well-tested, and implement a straightforward priority order for shell resolution. The logic properly handles edge cases (quoted paths, missing installations) with appropriate fallbacks. No breaking changes or security concerns identified.
- No files require special attention
<sub>Last reviewed commit: bafe326</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21215: Windows PowerShell reliability fixes (exec shim + Discord numeric p...
by musosoft · 2026-02-19
73.8%
#5168: Fix: force UTF-8 for Windows exec
by ManojINaik · 2026-01-31
73.7%
#18143: fix(windows): wrap shell builtins with cmd.exe /c for proper execution
by brandonwise · 2026-02-16
73.3%
#5950: Improvement/windows shell enhancement
by zzjj7000 · 2026-02-01
72.2%
#10708: fix: handle Windows PATH case-sensitivity in exec environment
by Yida-Dev · 2026-02-06
71.8%
#9250: Fix: Add shell:true for Windows .cmd files to prevent spawn EINVAL ...
by vishaltandale00 · 2026-02-05
71.7%
#19931: Config: merge PATH env vars and bootstrap Windows bins
by Kemalau · 2026-02-18
70.9%
#20330: Fix SSH tunnel startup on Windows by resolving ssh from PATH
by graysurf · 2026-02-18
70.5%
#10714: fix: handle Windows PATH case-sensitivity in node register invoke
by Yida-Dev · 2026-02-06
69.9%
#22425: chore: make prepare git hooks setup cross-platform
by OldFineDev · 2026-02-21
68.7%