Yeachan-Heo/oh-my-codex · error · Error

agents-init target must stay inside the current working…

Error message

agents-init target must stay inside the current working directory: ${requestedTarget}

What it means

agents-init resolves --target/<path> against the current working directory and refuses any path that escapes it (relative path starting with '..'). This is a safety boundary so the scaffolder cannot create/modify files outside the project tree. Absolute paths elsewhere on disk are also rejected via the same relative() check.

Solutions

  1. Run the command from the directory you want to scaffold into and pass `.` or a path inside it
  2. cd to the intended project root first
  3. Use a subdirectory of cwd as the target

Example fix

# before (cwd=/repo)
omx agents-init ../other-repo

# after
cd ../other-repo && omx agents-init .
Defensive patterns

Strategy: validation

Validate before calling

import { resolve, relative } from 'node:path';
const targetDir = resolve(process.cwd(), requestedTarget);
if (relative(process.cwd(), targetDir).startsWith('..')) {
  console.error('target must be inside the current working directory');
  process.exit(2);
}

Type guard

const isInsideCwd = (p: string): boolean => !relative(process.cwd(), resolve(process.cwd(), p)).startsWith('..');

Prevention

When it happens

Trigger: Passing `--target ../other-project`, `--target /tmp`, or an absolute path outside cwd; symlinks that resolve outside cwd are not caught here but absolute paths are.

Common situations: Running agents-init from a subdirectory while pointing at a sibling directory, or scripting against absolute paths in CI where cwd differs from expectations.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/ded8ff83aeefdb31. Report an issue: GitHub.

Appendix: source

Thrown at src/cli/agents-init.ts:291

    await writeFile(destinationPath, content);
  }
  summary.updated += 1;
  return { action: "updated", backedUp };
}

export async function agentsInit(
  options: AgentsInitOptions = {},
): Promise<void> {
  const dryRun = options.dryRun === true;
  const force = options.force === true;
  const verbose = options.verbose === true;
  const cwd = process.cwd();
  const requestedTarget = options.targetPath ?? ".";
  const targetDir = resolve(cwd, requestedTarget);
  const relativeTarget = relative(cwd, targetDir);

  if (relativeTarget.startsWith("..")) {
    throw new Error(
      `agents-init target must stay inside the current working directory: ${requestedTarget}`,
    );
  }

  const targetStat = await stat(targetDir).catch(() => null);
  if (!targetStat)
    throw new Error(`agents-init target not found: ${requestedTarget}`);
  if (!targetStat.isDirectory())
    throw new Error(
      `agents-init target must be a directory: ${requestedTarget}`,
    );

  const summary = createEmptySummary();
  const plannedDirs = await resolveTargetDirectories(targetDir);
  const backupRoot = join(
    cwd,
    ".omx",
    "backups",

View on GitHub (pinned to 3ad79a8a6f)