different-ai/openwork · error

project_dir is required

Error message

project_dir is required

What it means

This error is thrown by the `opencodeMcpAuth` helper in the Electron runtime before it shells out to the `opencode` binary for MCP server authentication. The function requires a non-empty `projectDir` because the child process runs with it as its working directory (the project scope for MCP auth). When the argument is missing, null, or whitespace-only after trimming, it fails fast with this message instead of spawning a process in the wrong directory.

Source

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

    const installDir = path.join(app.getPath("home"), ".opencode", "bin");
    const command = await pinnedOpencodeInstallCommand();
    const result = await runShellCommand("bash", ["-lc", command], {
      env: { ...(await buildChildEnv()), OPENCODE_INSTALL_DIR: installDir },
      timeoutMs: 180_000,
    });
    return {
      ok: result.status === 0,
      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,

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Ensure a project directory is resolved before calling opencodeMcpAuth (e.g. from app state or dialog result)
  2. Trim and validate the projectDir argument at the call site before invoking
  3. Guard the IPC/invocation flow so the MCP auth action is disabled when no project is open

Example fix

// before
await opencodeMcpAuth(state.projectDir, serverName);
// after
if (!state.projectDir?.trim()) throw new Error('Open a project first');
await opencodeMcpAuth(state.projectDir, serverName);
Defensive patterns

Strategy: validation

Validate before calling

function hasProjectDir(dir) {
  return typeof dir === 'string' && dir.trim().length > 0;
}

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await opencodeMcpAuth(projectDir, serverName);
} catch (e) {
  if (e.message === 'project_dir is required') {
    promptUserToOpenProject();
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `opencodeMcpAuth(undefined, ...)`, `opencodeMcpAuth(null, ...)`, `opencodeMcpAuth("", ...)` or `opencodeMcpAuth(" ", ...)` — i.e. the projectDir argument is absent, empty, or whitespace-only.

Common situations: IPC handlers invoked from the renderer before a project/folder has been opened; a stale or corrupted UI state where the workspace path was never set; callers passing an untrimmed blank string from config; refactoring that renamed the parameter without updating all call sites.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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