anomalyco / anomalyco/opencode

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

Open
#40,623 3 comments 0 reactions 1 assignee View on GitHub

@Hona is already working on this.

Since Aug 5, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.