Skip to content

Bug: Expand-Archive module auto-load fails when spawned from opencode.exe (Bun) #24291

Closed as not planned

Description

@hui6900

Description

Expand-Archive fails with "module could not be loaded" error when called internally by opencode.exe (Bun-compiled v1.14.24) on Windows.
The error occurs in tools like skill, glob (and any internal tool that calls Expand-Archive).

Error Message

Expand-Archive : The 'Expand-Archive' command was found in the module 'Microsoft.PowerShell.Archive',
but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Archive'.

Environment

  • OS: Windows (win32)
  • Shell: PowerShell 7.6.1
  • opencode version: 1.14.24
  • Node.js version: 24.15.0
  • Binary: opencode-windows-x64 (Bun v1.3.13)

Investigation

The internal call is:
powershell -NoProfile -NonInteractive -Command
"$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive -LiteralPath ..."
Confirmed working scenarios:

  • pwsh -NoProfile -NonInteractive ✅
  • powershell.exe -NoProfile -NonInteractive ✅
  • Node.js child_process.spawnSync ✅
  • Import-Module Microsoft.PowerShell.Archive -Force ✅
    Module file is intact, PSModulePath is correct, no Zone.Identifier blocking, not an ExecutionPolicy issue.
    Fails only when spawned from opencode.exe (Bun-compiled binary). Likely a Bun child_process environment compatibility issue on Windows.

Workaround

SKILL.md files can be read directly via the read tool, bypassing the skill loading tool.

Expected Behavior

Expand-Archive should work when called internally, same as it does from any normal PowerShell session.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 25, 2026
  2. github-actions commented on Apr 25, 2026

    @github-actions
    Contributor

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

    If your issue is specifically about a different aspect (e.g., a different error message or occurring in a different code path), please clarify how it differs from #23457 so maintainers can determine if this is a new distinct bug or a continuation of the same one.

  3. hui6900 commented on Apr 25, 2026

    @hui6900
    Author

    This is a different bug from #23457. #23457 fails with ParameterArgumentValidationError (null/empty -LiteralPath), while this one fails with CouldNotAutoloadMatchingModule — PowerShell can find the Expand-Archive command but fails to load the Microsoft.PowerShell.Archive module when spawned from the Bun-compiled binary. The module loads fine in all other scenarios (pwsh, powershell.exe, Node.js child_process). This is a module auto-load compatibility issue specific to Bun's process spawning on Windows.

  4. Snakeblack commented on May 2, 2026

    @Snakeblack

    Confirmed still reproducing in opencode v1.14.31 (latest as of today).

    Environment

    • OS: Windows 10.0.26200 (Windows 11)
    • Shell configured: C:\Program Files\PowerShell\7\pwsh.exe (PowerShell 7.6.1)
    • opencode: v1.14.31

    Symptoms

    Error appears in stderr of internal tools — observed in glob, grep, and skill loading:

    Expand-Archive : El comando 'Expand-Archive' se encontró en el módulo 'Microsoft.PowerShell.Archive',
    pero el módulo no pudo cargarse.
    + ... lobal:ProgressPreference = 'SilentlyContinue'; Expand-Archive -Litera ...
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    

    Tools still return correct results — the error is cosmetic noise on stderr, not a functional failure. But it pollutes the TUI output significantly when many tool calls happen in sequence.

    Confirms diagnosis from #24291

    • Manual repro with powershell.exe -NoProfile -NonInteractive -Command "..." from a regular shell works fine (Archive module v1.0.1.0 system + v1.2.5 user-installed both autoload OK)
    • Manual repro with pwsh.exe -NoProfile -NonInteractive -Command "..." also works fine
    • Fails only when the spawn comes from the Bun-compiled opencode.exe runtime
    • Custom "shell" setting in opencode.json does not affect internal tools (only the bash tool)

    Suggested workaround for maintainers

    Since the bug is in Bun's child_process env propagation on Windows, replacing Expand-Archive with a direct .NET call would sidestep the PowerShell module autoload entirely:

    Add-Type -AssemblyName System.IO.Compression.FileSystem
    [System.IO.Compression.ZipFile]::ExtractToDirectory($src, $dst)

    This works in any PowerShell session regardless of module autoload state, and removes the dependency on Microsoft.PowerShell.Archive entirely.

  5. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. cumal commented on May 27, 2026

    @cumal

    Same problem here. Windows 11 using proweshell 7.6.1 and OC 1.15.10

    My log:

    explore this project and search for a boolean variable which controls the speed of the software.
    + Thought: 2.1s
    I'll explore the codebase to find a boolean variable controlling software speed. Let me search systematically.
    ✱ Grep "\b(speed|fast|slow)\s*[=:]\s*(true|false)" 
    Expand-Archive : The 'Expand-Archive' command was found in the module 'Microsoft.PowerShell.Archive', but the module 
    could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Archive'.
    At line:1 char:50
    + ... lobal:ProgressPreference = 'SilentlyContinue'; Expand-Archive -Litera ...
    +                                                    ~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Expand-Archive:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
  7. lostal commented on Jun 16, 2026

    @lostal

    Same here. v1.15.3, Win 11, PS 7.6.2. Error on every prompt, glob and grep are dead. Module loads fine from a terminal but fails when opencode's binary spawns it. Also leaves vscode-eslint.zip unextracted in ~/.local/share/opencode/bin/. Looks like a Bun child_process issue on Windows.

  8. weeix commented on Jun 19, 2026

    @weeix

    Still an issue in v1.17.8, Win10, PS 7.6.2

    Have anyone tried the fix introduced by the auto-closed PR #25396 yet?

  9. krlosgarciar commented on Jun 24, 2026

    @krlosgarciar

    Confirmed the same root cause on Windows 11 (PS 7.6.3, opencode 1.17.9 via mise/node). The Expand-Archive autoload fails only when spawned from the Bun-compiled binary, works perfectly when run manually from either powershell.exe or pwsh.exe.

    Looking at the compiled source, opencode searches for rg.exe in this order:

    1. rg.exe anywhere in PATH
    2. rg.exe directly at ~/.cache/opencode/bin/rg.exe
    3. Download the ripgrep zip and extract it with powershell.exe -NoProfile -NonInteractive -Command "$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive ..."

    Step 3 is where it breaks. The workaround is to short-circuit at step 2:

    opencode already downloaded the zip to ~/.cache/opencode/bin/

    $zip = "$env:USERPROFILE\.cache\opencode\bin\ripgrep-15.1.0-x86_64-pc-windows-msvc.zip"
    
    # Extract rg.exe manually (avoiding Expand-Archive autoload entirely)
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $archive = [System.IO.Compression.ZipFile]::OpenRead($zip)
    foreach ($entry in $archive.Entries) {
        if ($entry.FullName -match 'rg\.exe$') {
            $dest = Join-Path (Split-Path $zip) "rg.exe"
            [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $dest, $true)
        }
    }
    $archive.Dispose()
    

    Clean up the zip (no longer needed)

    Remove-Item $zip -Force

    After this, restart opencode. It finds rg.exe at step 2 and never calls Expand-Archive. The glob and grep tools work without errors.

  10. logsin37 commented on Jul 30, 2026

    @logsin37

    Confirmed the same root cause on Windows 11 (PS 7.6.3, opencode 1.17.9 via mise/node). The Expand-Archive autoload fails only when spawned from the Bun-compiled binary, works perfectly when run manually from either powershell.exe or pwsh.exe.

    Looking at the compiled source, opencode searches for rg.exe in this order:

    1. rg.exe anywhere in PATH
    2. rg.exe directly at ~/.cache/opencode/bin/rg.exe
    3. Download the ripgrep zip and extract it with powershell.exe -NoProfile -NonInteractive -Command "$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive ..."

    Step 3 is where it breaks. The workaround is to short-circuit at step 2:

    opencode already downloaded the zip to ~/.cache/opencode/bin/

    $zip = "$env:USERPROFILE.cache\opencode\bin\ripgrep-15.1.0-x86_64-pc-windows-msvc.zip"

    Extract rg.exe manually (avoiding Expand-Archive autoload entirely)

    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $archive = [System.IO.Compression.ZipFile]::OpenRead($zip)
    foreach ($entry in $archive.Entries) {
    if ($entry.FullName -match 'rg.exe$') {
    $dest = Join-Path (Split-Path $zip) "rg.exe"
    [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $dest, $true)
    }
    }
    $archive.Dispose()

    Clean up the zip (no longer needed)

    Remove-Item $zip -Force
    After this, restart opencode. It finds rg.exe at step 2 and never calls Expand-Archive. The glob and grep tools work without errors.

    @krlosgarciar is right. You can send this to your opencode and let it fix the bug for you:
    Run this PowerShell command to bypass the Expand-Archive autoload bug (issue #24291). It extracts rg.exe from the already-downloaded ripgrep zip using the .NET API instead of Expand-Archive, so opencode finds rg.exe at step 2 and never calls the broken module.

    $zip = "$env:USERPROFILE\.cache\opencode\bin\ripgrep-15.1.0-x86_64-pc-windows-msvc.zip"
    $dest = Join-Path (Split-Path $zip) "rg.exe"
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $archive = [System.IO.Compression.ZipFile]::OpenRead($zip)
    foreach ($entry in $archive.Entries) {
        if ($entry.FullName -match 'rg\.exe$') {
            [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $dest, $true)
            break
        }
    }
    $archive.Dispose()
    Remove-Item $zip -Force

    Then #restart# opencode. grep/glob/skill tools will work without the Expand-Archive error.

  11. github-actions commented on Sep 30, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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