tinyhumansai/openhuman · error · Error

RPC token not found at ${tokenPath}. Pass --token or set OPE

Error message

RPC token not found at ${tokenPath}. Pass --token or set OPENHUMAN_CORE_TOKEN.

What it means

readToken() in goals-live.mjs resolves the RPC bearer in order: --token, then the OPENHUMAN_CORE_TOKEN env var (seeded into opts at startup), then <workspace>/core.token on disk. If all three fail — no flag, no env, and the core.token file unreadable — it throws with the path it tried. The core's HTTP RPC endpoint requires this per-launch hex bearer, so without it every request would 401 anyway; the script fails early instead.

Source

Thrown at scripts/debug/goals-live.mjs:169

    const active = await readFile(path.join(dir, "active_user.toml"), "utf8");
    const match = active.match(/^\s*user_id\s*=\s*"([^"]+)"\s*$/m);
    if (match?.[1]) return path.join(dir, "users", match[1], "workspace");
  } catch {
    // fall through
  }
  return dir;
}

async function readToken(opts) {
  if (opts.token.trim()) return opts.token.trim();
  const tokenPath = path.join(
    opts.workspace || (await defaultWorkspace()),
    "core.token",
  );
  try {
    return (await readFile(tokenPath, "utf8")).trim();
  } catch {
    throw new Error(
      `RPC token not found at ${tokenPath}. Pass --token or set OPENHUMAN_CORE_TOKEN.`,
    );
  }
}

async function rpc(coreUrl, token, method, params, timeoutMs = 600_000) {
  const controller = new AbortController();
  const timer = setTimeout(() => controller.abort(), timeoutMs);
  let res;
  try {
    res = await fetch(coreUrl, {
      method: "POST",
      signal: controller.signal,
      headers: {
        "content-type": "application/json",
        authorization: `Bearer ${token}`,
      },
      body: JSON.stringify({

View on GitHub (pinned to a221052e0d)

Solutions

  1. Pass the bearer explicitly: `--token <value>` or `OPENHUMAN_CORE_TOKEN=<value> node ...`
  2. Point at the workspace that actually holds core.token: `--workspace ~/.openhuman/users/<id>/workspace` (or ~/.openhuman-staging/... when OPENHUMAN_APP_ENV=staging)
  3. Let the script generate and inject its own token with `--spawn-core` (startCore mints `goals-<hex>` and passes OPENHUMAN_CORE_TOKEN to the child)
  4. Verify the file exists: `ls <workspace>/core.token` — if the core wrote it elsewhere, align --workspace with the core's OPENHUMAN_WORKSPACE

Example fix

// before
node scripts/debug/goals-live.mjs --core-url http://127.0.0.1:7788/rpc
# Error: RPC token not found at /home/me/.openhuman/.../core.token ...

// after
OPENHUMAN_CORE_TOKEN=$(cat ~/.openhuman/users/<id>/workspace/core.token) \
  node scripts/debug/goals-live.mjs --core-url http://127.0.0.1:7788/rpc
Defensive patterns

Strategy: validation

Validate before calling

import { access } from "node:fs/promises";

async function tokenResolvable(opts) {
  if (opts.token?.trim()) return true;
  if (process.env.OPENHUMAN_CORE_TOKEN?.trim()) return true;
  const ws = opts.workspace || process.env.OPENHUMAN_WORKSPACE || defaultWorkspaceGuess();
  try {
    await access(path.join(ws, "core.token"));
    return true;
  } catch {
    return false;
  }
}
if (!(await tokenResolvable(opts))) {
  console.error("no RPC bearer: pass --token, export OPENHUMAN_CORE_TOKEN, or boot the core once");
  process.exit(2);
}

Try / catch

try {
  token = await readToken(opts);
} catch (err) {
  if (/RPC token not found/.test(err.message)) {
    // recover: spawn a core that owns its token instead of failing
    opts.spawnCore = true;
    ({ token } = await startCore(opts));
  } else throw err;
}

Prevention

When it happens

Trigger: Running against an external core (no --spawn-core) whose workspace has no core.token because the core was started with OPENHUMAN_CORE_TOKEN set to a value never written to disk; passing --workspace pointing at a fresh/wrong directory; OPENHUMAN_APP_ENV=staging making the default dir ~/.openhuman-staging while the token lives in ~/.openhuman; the core simply not running/initialized in the resolved workspace.

Common situations: Core started standalone via `./target/debug/openhuman-core serve` with a custom token; multiple workspaces/profiles and the script picking the empty one; staging vs prod directory confusion; first run on a machine where the app has never booted the core.

Related errors


AI-assisted analysis of tinyhumansai/openhuman@a221052e0d (2026-08-16). Data as JSON: /api/errors/99303d0989ccf4ef. Report an issue: GitHub.