You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Grep tool fails on Windows: ripgrep extraction broken by MSIX PowerShell 7 PSModulePath, and failures are cached until restart #40623
The built-in grep/glob tools fail on Windows when rg.exe is not installed. Two bugs are involved:
Bug 1 — ripgrep zip extraction always fails when the Microsoft Store (MSIX) version of PowerShell 7 is installed and used to launch opencode.
opencode downloads ripgrep successfully, then extracts the zip by spawning powershell.exe (Windows PowerShell 5.1) with Expand-Archive (packages/core/src/ripgrep/binary.ts). If opencode was launched from the MSIX PowerShell 7 session, that session's PSModulePath lists the Store package's own Modules dir (c:\program files\windowsapps\microsoft.powershell_<ver>_x64__8wekyb3d8bbwe\Modules, i.e. $PSHOME\Modules of the MSIX pwsh) beforeC:\Windows\system32\WindowsPowerShell\v1.0\Modules.
The spawned 5.1 process inherits this PSModulePath (extendEnv: true). When autoloading Expand-Archive, the 5.1 module autoloader hits the PowerShell-7-only (Core edition)Microsoft.PowerShell.Archive module in the MSIX dir first, deems it incompatible, and stops searching instead of continuing to the compatible 5.1 module in System32. Result:
The zip is downloaded to ~/.cache/opencode/bin/ but never extracted; every Grep/Glob call repeats download + extraction failure.
Bug 2 — the failed ripgrep resolution is permanently cached.
binary.ts wraps the locate/download/extract logic in Effect.cached, which caches failures as well as successes. Even after the environment is fixed (e.g. rg.exe manually placed in ~/.cache/opencode/bin/), every Grep/Glob call in the same process keeps returning the stale failure with no retry, until opencode is restarted. Verified via logs: a fresh process finds rg.exe and works immediately; the long-running process keeps failing without even logging a new "downloading ripgrep" attempt.
Plugins
None (default)
OpenCode version
1.18.13 (CLI, installed via npm)
Steps to reproduce
Do not have rg.exe in PATH or in ~/.cache/opencode/bin/
Install PowerShell 7 via Microsoft Store (MSIX) and launch opencode from its terminal
Ask the agent to use the grep tool
Observe CouldNotAutoloadMatchingModule error; ripgrep-15.1.0-x86_64-pc-windows-msvc.zip is downloaded but never extracted
Manually place rg.exe into ~/.cache/opencode/bin/ — the tool still fails until opencode is restarted
Screenshot and/or share link
N/A
Operating System
Windows 11
Terminal
Windows Terminal (PowerShell 7.6.3, Microsoft Store/MSIX install)
Workarounds (confirmed working on the affected machine)
Quick fix — make opencode find rg.exe without downloading:
opencode resolves ripgrep in this order: which("rg.exe") → <Global.Path.bin>/rg.exe → download from GitHub (packages/core/src/ripgrep/binary.ts). On Windows, Global.Path.bin is %USERPROFILE%\.cache\opencode\bin\. So:
Extract it and copy rg.exe to %USERPROFILE%\.cache\opencode\bin\rg.exe (create the directory if needed)
Restart opencode — required because of Bug 2 (the failed resolution is cached in the process; only a fresh process will pick up the binary)
Root-cause fix — fix the PowerShell module resolution:
The failure only happens because Windows PowerShell 5.1 inherits the MSIX PowerShell 7 session's PSModulePath, which lists the Store package's $PSHOME\Modules (Core-only modules) before C:\Windows\system32\WindowsPowerShell\v1.0\Modules\. The 5.1 autoloader stops at the first incompatible (Core-only) match and reports CouldNotAutoloadMatchingModule instead of continuing the search.
Alternatively, launch opencode from Windows PowerShell 5.1 or from a terminal that does not put the MSIX pwsh package dir ahead of system32\WindowsPowerShell\v1.0\Modules\ in PSModulePath.
Verification:
rg.exe alone fixes grep/glob permanently — confirmed on the affected machine after restart (headless opencode run returned 64 matches; in-session grep returned 18 matches).
The node repro confirmed the env dependence: spawning 5.1 with the full MSIX-inherited PSModulePath reproduces the exact CouldNotAutoloadMatchingModule error; removing/overriding PSModulePath makes extraction succeed.
Two real bugs in one. The PowerShell-7-only Microsoft.PowerShell.Archive getting picked first is the autoloader doing exactly what the docs say it'll do...... it stops at the first compatible-looking match and never falls back to System32. Fix for that: strip the MSIX $PSHOME\Modules from PSModulePath before opencode spawns 5.1 (Expand-Archive's real home), or just launch opencode from a non-MSIX shell. Bug 2 is rougher...... Effect.cached wrapping a failing effect is a 'never retry until restart' footgun, and that's basically the contract nobody wants from a tool resolver. Until that's patched, the workaround you posted (drop rg.exe into ~/.cache/opencode/bin + restart) is what works. Oh also, btw, I built a portable Hermes OTG and I keep it on USB for the 'every Grep call retries the same broken download' days...... imo, side-by-side agent helps you keep diagnosing while the upstream fix lands. https://github.com/MilkyWay008/Hermes-OTG
Additional confirmation from a Windows 11 machine, including a source-check that may help pin this down.
Environment: opencode 1.19.0 (CLI, scoop), Windows 11, PowerShell 7.6.6 installed via Microsoft Store (MSIX), opencode launched from the MSIX pwsh session.
Symptom (matches exactly): grep/glob/skill all fail with CouldNotAutoloadMatchingModule. The zip ripgrep-15.1.0-x86_64-pc-windows-msvc.zip is downloaded on every new run (observed 10-02, 10-03, 10-05, 10-06 x2, 10-08, 10-10, 10-11) into ~/.cache/opencode/bin/ but rg.exe is never extracted.
Source check (main today): packages/core/src/ripgrep/binary.ts still selects the extraction shell as findExecutable("powershell.exe") ?? findExecutable("pwsh.exe"), i.e. it prefers Windows PowerShell 5.1 even when a pwsh is available — so this is not fixed by the shell setting in config. The child is spawned with extendEnv: true, which is what carries the MSIX PSModulePath through.
A detail that may help: I could not reproduce the failure from outside opencode. Spawning powershell.exe from a pwsh parent (even with PSModulePath explicitly set to the MSIX-ordered 5-entry list) always worked — 5.1 recomputes PSModulePath on startup in that path. The failure only happens when the process is spawned the way Bun does it with extendEnv: true. So the difference appears to be the spawn/env mechanism, not the PSModulePath value itself.
Workaround that actually fixed it: which("rg.exe") is consulted before download (resolution order: PATH -> Global.Path.bin -> download). Installing ripgrep so that rg.exe is on PATH (scoop install ripgrep -> shims/rg.exe) resolves it — the download/extract path is never entered. Also confirms Bug 2: a fresh process is required (the failure is cached in-process until restart). Separately, manually placing rg.exe in ~/.cache/opencode/bin/ did not stick — opencode's own install/cleanup path removed it.
Happy to provide logs if useful.
Environment note: machine registry PSModulePath (HKLM) does not contain the WindowsApps dir; the MSIX dirs are injected into the session env by the Store pwsh at startup.
Activity
github-actions commentedon Aug 5, 2026
This issue might be a duplicate of existing issues. Please check:
Expand-Archivefails when spawned from opencode.exe (Bun) on Windows, module auto-load error (open)Expand-Archiveerror on Windows PowerShell when loading skills (closed)luckducks commentedon Aug 5, 2026
Workarounds (confirmed working on the affected machine)
Quick fix — make opencode find
rg.exewithout downloading:opencode resolves ripgrep in this order:
which("rg.exe")→<Global.Path.bin>/rg.exe→ download from GitHub (packages/core/src/ripgrep/binary.ts). On Windows,Global.Path.binis%USERPROFILE%\.cache\opencode\bin\. So:gh release download 15.1.0 --repo BurntSushi/ripgrep --pattern "ripgrep-15.1.0-x86_64-pc-windows-msvc.zip"rg.exeto%USERPROFILE%\.cache\opencode\bin\rg.exe(create the directory if needed)Root-cause fix — fix the PowerShell module resolution:
The failure only happens because Windows PowerShell 5.1 inherits the MSIX PowerShell 7 session's
PSModulePath, which lists the Store package's$PSHOME\Modules(Core-only modules) beforeC:\Windows\system32\WindowsPowerShell\v1.0\Modules\. The 5.1 autoloader stops at the first incompatible (Core-only) match and reportsCouldNotAutoloadMatchingModuleinstead of continuing the search.Options:
C:\Program Files\PowerShell\7\out of the 5.1 module-search collision and is serviced by Windows Update.system32\WindowsPowerShell\v1.0\Modules\inPSModulePath.Verification:
rg.exealone fixes grep/glob permanently — confirmed on the affected machine after restart (headlessopencode runreturned 64 matches; in-session grep returned 18 matches).PSModulePathreproduces the exactCouldNotAutoloadMatchingModuleerror; removing/overridingPSModulePathmakes extraction succeed.fix(core): retry failed ripgrep resolution and sanitize PowerShell 5.…
MilkyWay008 commentedon Aug 17, 2026
Two real bugs in one. The PowerShell-7-only
Microsoft.PowerShell.Archivegetting picked first is the autoloader doing exactly what the docs say it'll do...... it stops at the first compatible-looking match and never falls back to System32. Fix for that: strip the MSIX$PSHOME\ModulesfromPSModulePathbefore opencode spawns 5.1 (Expand-Archive's real home), or just launch opencode from a non-MSIX shell. Bug 2 is rougher......Effect.cachedwrapping a failing effect is a 'never retry until restart' footgun, and that's basically the contract nobody wants from a tool resolver. Until that's patched, the workaround you posted (droprg.exeinto~/.cache/opencode/bin+ restart) is what works. Oh also, btw, I built a portable Hermes OTG and I keep it on USB for the 'every Grep call retries the same broken download' days...... imo, side-by-side agent helps you keep diagnosing while the upstream fix lands. https://github.com/MilkyWay008/Hermes-OTGY545329005 commentedon Oct 11, 2026
Additional confirmation from a Windows 11 machine, including a source-check that may help pin this down.
Environment: opencode 1.19.0 (CLI, scoop), Windows 11, PowerShell 7.6.6 installed via Microsoft Store (MSIX), opencode launched from the MSIX pwsh session.
Symptom (matches exactly):
grep/glob/skillall fail withCouldNotAutoloadMatchingModule. The zipripgrep-15.1.0-x86_64-pc-windows-msvc.zipis downloaded on every new run (observed 10-02, 10-03, 10-05, 10-06 x2, 10-08, 10-10, 10-11) into~/.cache/opencode/bin/butrg.exeis never extracted.Source check (main today):
packages/core/src/ripgrep/binary.tsstill selects the extraction shell asfindExecutable("powershell.exe") ?? findExecutable("pwsh.exe"), i.e. it prefers Windows PowerShell 5.1 even when a pwsh is available — so this is not fixed by theshellsetting in config. The child is spawned withextendEnv: true, which is what carries the MSIXPSModulePaththrough.A detail that may help: I could not reproduce the failure from outside opencode. Spawning
powershell.exefrom a pwsh parent (even withPSModulePathexplicitly set to the MSIX-ordered 5-entry list) always worked — 5.1 recomputesPSModulePathon startup in that path. The failure only happens when the process is spawned the way Bun does it withextendEnv: true. So the difference appears to be the spawn/env mechanism, not thePSModulePathvalue itself.Workaround that actually fixed it:
which("rg.exe")is consulted before download (resolution order:PATH->Global.Path.bin-> download). Installing ripgrep so thatrg.exeis onPATH(scoop install ripgrep->shims/rg.exe) resolves it — the download/extract path is never entered. Also confirms Bug 2: a fresh process is required (the failure is cached in-process until restart). Separately, manually placingrg.exein~/.cache/opencode/bin/did not stick — opencode's own install/cleanup path removed it.Happy to provide logs if useful.
Environment note: machine registry
PSModulePath(HKLM) does not contain the WindowsApps dir; the MSIX dirs are injected into the session env by the Store pwsh at startup.thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊