different-ai/openwork · error

Failed to locate opencode.

Error message

Failed to locate opencode.

What it means

Thrown by `opencodeMcpAuth` when `resolveBinary("opencode")` returns no path — the runtime cannot find an executable `opencode` binary to run for MCP authentication. This check happens after argument validation but before the process spawn, so it guarantees the CLI exists before shelling out.

Solutions

  1. Install the opencode binary and ensure it is on PATH (verify with `which opencode`)
  2. If launching from the desktop app, confirm PATH includes the install location or set it via buildChildEnv
  3. Rebuild/repackage so the bundled opencode binary ships with the app
  4. Check resolveBinary search paths match your install layout

Example fix

// before
// resolveBinary('opencode') returns undefined; error thrown
// after
// ensure the binary exists before invoking the flow
import { execFileSync } from 'node:child_process';
const which = execFileSync('which', ['opencode'], { encoding: 'utf8' }).trim();
if (!which) throw new Error('Install opencode first');
Defensive patterns

Strategy: fallback

Validate before calling

import { execFileSync } from 'node:child_process';
function opencodeOnPath() {
  try { execFileSync('which', ['opencode']); return true; }
  catch { return false; }
}

Try / catch

try {
  await opencodeMcpAuth(projectDir, serverName);
} catch (e) {
  if (e.message === 'Failed to locate opencode.') {
    showError('Install the opencode CLI, then retry');
  } else throw e;
}

Prevention

When it happens

Trigger: `opencode` is not installed, is not on PATH, or the packaged/bundled binary is missing at the location `resolveBinary` searches (dev vs. packaged app layout differences).

Common situations: Running the Electron app on a machine where only the npm package (not the standalone opencode binary) is installed; PATH differences between shell and GUI-launched app on macOS; a broken build/package step that omitted the bundled binary; wrong architecture binary.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/fc2fd2ad138a9cbd. Report an issue: GitHub.

Appendix: source

Thrown at apps/desktop/electron/runtime.mjs:2274

      status: result.status,
      stdout: result.stdout,
      stderr: result.stderr,
    };
  }

  async function opencodeMcpAuth(projectDir, serverName) {
    const safeProjectDir = String(projectDir ?? "").trim();
    const safeServerName = String(serverName ?? "").trim();
    if (!safeProjectDir) {
      throw new Error("project_dir is required");
    }
    if (!safeServerName) {
      throw new Error("server_name is required");
    }

    const program = resolveBinary("opencode");
    if (!program) {
      throw new Error("Failed to locate opencode.");
    }

    const result = await runShellCommand(program, ["mcp", "auth", safeServerName], {
      cwd: safeProjectDir,
      env: await buildChildEnv(),
      timeoutMs: 120_000,
    });
    return {
      ok: result.status === 0,
      status: result.status,
      stdout: result.stdout,
      stderr: result.stderr,
    };
  }

  async function sandboxCleanupOpenworkContainers() {
    const candidates = await listOpenworkManagedContainers().catch((error) => {
      throw error;

View on GitHub (pinned to 2b7df46e8a)