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.
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)
Solutions
- Install the opencode binary and ensure it is on PATH (verify with `which opencode`)
- If launching from the desktop app, confirm PATH includes the install location or set it via buildChildEnv
- Rebuild/repackage so the bundled opencode binary ships with the app
- 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
- Verify `which opencode` works in the GUI-launched environment, not just the terminal
- Ship/bundle the opencode binary with the desktop app and test packaged builds
- Document PATH setup for non-standard installs
- Smoke-test binary resolution on app startup
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
- OpenWork Computer Use is missing from this OpenWork build.
- project_dir is required
- server_name is required
- invalid_mcp_token_payload
- invalid_mcp_connection_payload
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/fc2fd2ad138a9cbd.
Report an issue: GitHub.