can1357/oh-my-pi · error · Error
Cannot change working directory to ${parsed.cwd}: ${reason}.
Error message
Cannot change working directory to ${parsed.cwd}: ${reason}.${hint} What it means
`applyStartupCwd` honors the `--cwd`/`parsed.cwd` request by chdir-ing (via setProjectDir) into the target directory. When the change fails (directory doesn't exist, permission denied, not a directory), it throws this error with a reason and, for EACCES/EPERM on macOS, a hint about granting Full Disk Access. The message includes the requested path and why it failed.
Source
Thrown at packages/coding-agent/src/cli/startup-cwd.ts:60
} catch {
// Ignore fallback errors.
}
}
export async function applyStartupCwd(parsed: Args): Promise<void> {
if (parsed.cwd) {
try {
setProjectDir(parsed.cwd);
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
// Permission denials are the macOS TCC case; a plain ENOENT typo
// should not be told to grant Full Disk Access.
const code = (error as NodeJS.ErrnoException | null)?.code;
const hint =
code === "EACCES" || code === "EPERM"
? " On macOS, grant omp Files & Folders or Full Disk Access permission for the target directory."
: "";
throw new Error(`Cannot change working directory to ${parsed.cwd}: ${reason}.${hint}`);
}
// setProjectDir resolves the (possibly relative) target against the launch
// cwd and chdirs into it. Re-sync parsed.cwd to the resolved absolute path
// so downstream consumers (buildSessionOptions, settings/discovery, session
// persistence) don't re-resolve a relative string against the new cwd.
parsed.cwd = getProjectDir();
return;
}
await maybeAutoChdir(parsed);
}
View on GitHub (pinned to 9690622007)
Solutions
- Verify the path exists and is a directory: `ls -ld <dir>`
- On macOS, grant the terminal app Full Disk Access (System Settings → Privacy & Security) and relaunch
- Fix the `--cwd` argument spelling or use an absolute path
- Check mount/network drive availability if the path is on a removable or remote volume
Example fix
// before omp --cwd ~/Documnts/project // after omp --cwd ~/Documents/project
Defensive patterns
Strategy: validation
Validate before calling
import { statSync } from "node:fs";
try {
if (!statSync(targetDir).isDirectory()) throw new Error(`${targetDir} is not a directory`);
} catch (err) {
if ((err as NodeJS.ErrnoException).code === "ENOENT") throw new Error(`Directory does not exist: ${targetDir}`);
throw err;
} Try / catch
try {
await applyStartupCwd(parsed);
} catch (err) {
if (err instanceof Error && err.message.startsWith("Cannot change working directory")) {
console.error(`${err.message}\nCheck the path, or on macOS grant Full Disk Access to your terminal.`);
process.exit(1);
}
throw err;
} Prevention
- Verify the --cwd path exists before launching
- On macOS, pre-grant your terminal Full Disk Access for protected folders
- Use absolute directory paths; never point --cwd at a file
When it happens
Trigger: Launching `omp --cwd <dir>` (or equivalent startup cwd option) where the directory is missing, unreadable, or the OS denies access — the underlying chdir/stat error's code (e.g. ENOENT, EACCES, EPERM, ENOTDIR) determines the reason string.
Common situations: Typo'd or deleted target directory; on macOS, Terminal lacks Files & Folders / Full Disk Access for protected locations (Desktop/Documents/external volumes); pointing at a file instead of a directory; network mount unavailable.
Related errors
- {}: {error}
- inter-device move failed: {} to {}; unable to remove target:
- Permission denied
- cannot stat {file}: {error}
- failed to read filter definition {}: {e}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/949b8b8a0fd7ac3d.
Report an issue: GitHub.