Skip to content

Grep tool fails on Windows: ripgrep extraction broken by MSIX PowerShell 7 PSModulePath, and failures are cached until restart #40623

Closed as not planned

Description

@luckducks

Description

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) before C:\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:

Expand-Archive : 无法加载模块"Microsoft.PowerShell.Archive",因为找不到模块"Microsoft.PowerShell.Archive"中的"Expand-Archive"命令。
Import-Module Microsoft.PowerShell.Archive
所在位置 行:1 字符: 50
+ ... lobal:ProgressPreference = 'SilentlyContinue'; Expand-Archive -Litera ...
+                                                    ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Expand-Archive:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

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

  1. Do not have rg.exe in PATH or in ~/.cache/opencode/bin/
  2. Install PowerShell 7 via Microsoft Store (MSIX) and launch opencode from its terminal
  3. Ask the agent to use the grep tool
  4. Observe CouldNotAutoloadMatchingModule error; ripgrep-15.1.0-x86_64-pc-windows-msvc.zip is downloaded but never extracted
  5. 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)

Activity

  1. github-actions commented on Aug 5, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. luckducks commented on Aug 5, 2026

    @luckducks
    Author

    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:

    1. Download ripgrep for Windows: gh release download 15.1.0 --repo BurntSushi/ripgrep --pattern "ripgrep-15.1.0-x86_64-pc-windows-msvc.zip"
    2. Extract it and copy rg.exe to %USERPROFILE%\.cache\opencode\bin\rg.exe (create the directory if needed)
    3. 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.

    Options:

    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.
  3. MilkyWay008 commented on Aug 17, 2026

    @MilkyWay008

    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

  4. Y545329005 commented on Oct 11, 2026

    @Y545329005

    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.

  5. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions