Skip to content

Windows: isInstalled() always returns false even when OpenCode is on PATH #63

@Alcatraz-Zhang

Description

@Alcatraz-Zhang

Short description

Windows: isInstalled() always returns false even when OpenCode is on PATH

What happened?

On Windows, running npx @cortexkit/magic-context@latest setup --harness opencode reports "OpenCode host not found on PATH" even when OpenCode is correctly installed and discoverable via where.exe opencode.

Root cause: isInstalled() in packages/cli/src/adapters/opencode.ts uses two detection strategies, both of which fail on Windows:

  1. process.env.HOME — typically undefined on Windows (should use os.homedir() or USERPROFILE)
  2. execSync("command -v opencode") — this is a Bash built-in that does not exist in PowerShell/CMD, so it always throws, causing isInstalled() to return false unconditionally on Windows.

Expected behavior: OpenCode is detected correctly on Windows, e.g. by falling back to where.exe opencode or using execSync("where opencode") when process.platform === "win32".

Steps to reproduce:

  1. Install OpenCode on Windows so it is available on PATH (e.g. via bun — C:\Users\<user>\.bun\bin\opencode.exe)
  2. Confirm with where.exe opencode — returns the correct path
  3. Run npx @cortexkit/magic-context@latest setup --harness opencode
  4. Setup reports: "OpenCode host not found on PATH. Install OpenCode: curl -fsSL https://opencode.ai/install | bash."

Suggested fix:

isInstalled(): boolean {
    if (existsSync(join(homedir(), ".opencode", "bin", "opencode"))) return true;
    const cmd = process.platform === "win32" ? "where opencode" : "command -v opencode";
    try {
        execSync(cmd, { stdio: "ignore" });
        return true;
    } catch {
        return false;
    }
}

Diagnostics

N/A

Plugin version

No response

OpenCode version

No response

Platform

Windows x64

Client

OpenCode TUI (CLI)

Log output (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions