Yeachan-Heo/oh-my-codex · error · Error
agents-init target must be a directory: ${requestedTarget}
Error message
agents-init target must be a directory: ${requestedTarget} What it means
The agents-init target exists but stat reports it is not a directory (a regular file, symlink to file, etc.). Scaffolding agent config requires a directory to create subdirectories and files into.
Source
Thrown at src/cli/agents-init.ts:300
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",
"agents-init",
new Date().toISOString().replaceAll(":", "-"),
);
const activeSession = await readSessionState(cwd);
const rootSessionGuardActive = Boolean(
activeSession && !isSessionStale(activeSession),
);
console.log("oh-my-codex AGENTS bootstrap");View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Point --target at a directory, not a file
- If the path should be a directory, remove the conflicting file or rename it
Example fix
# before omx agents-init --target AGENTS.md # after omx agents-init --target .
Defensive patterns
Strategy: type-guard
Validate before calling
const st = statSync(targetDir, { throwIfNoEntry: false });
if (st && !st.isDirectory()) {
console.error(`target is not a directory: ${targetDir}`);
process.exit(2);
} Type guard
const isDirectory = (p: string): boolean => {
const s = statSync(p, { throwIfNoEntry: false });
return s?.isDirectory() ?? false;
}; Prevention
- Point --target at directories, never at files
- Check for name collisions between intended directories and existing files
When it happens
Trigger: Passing --target pointing at a file like README.md or a symlink that resolves to a file.
Common situations: Reusing a path that was a directory but is now a file, or pointing at a config filename instead of its parent directory.
Related errors
- agents-init target must stay inside the current working dire
- agents-init target not found: ${requestedTarget}
- Unknown agents-init option: ${arg}\n${AGENTS_INIT_USAGE}
- agents-init accepts at most one path argument.\n${AGENTS_INI
- Unknown adapt argument: ${arg}
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/cbcdc6c32781359f.
Report an issue: GitHub.