{"record":{"id":"949b8b8a0fd7ac3d","repo":"can1357/oh-my-pi","slug":"cannot-change-working-directory-to-parsed-cwd","errorCode":null,"errorMessage":"Cannot change working directory to ${parsed.cwd}: ${reason}.${hint}","messagePattern":"Cannot change working directory to (.+?): (.+?)\\.(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/startup-cwd.ts","lineNumber":60,"sourceCode":"\t} catch {\n\t\t// Ignore fallback errors.\n\t}\n}\n\nexport async function applyStartupCwd(parsed: Args): Promise<void> {\n\tif (parsed.cwd) {\n\t\ttry {\n\t\t\tsetProjectDir(parsed.cwd);\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? error.message : String(error);\n\t\t\t// Permission denials are the macOS TCC case; a plain ENOENT typo\n\t\t\t// should not be told to grant Full Disk Access.\n\t\t\tconst code = (error as NodeJS.ErrnoException | null)?.code;\n\t\t\tconst hint =\n\t\t\t\tcode === \"EACCES\" || code === \"EPERM\"\n\t\t\t\t\t? \" On macOS, grant omp Files & Folders or Full Disk Access permission for the target directory.\"\n\t\t\t\t\t: \"\";\n\t\t\tthrow new Error(`Cannot change working directory to ${parsed.cwd}: ${reason}.${hint}`);\n\t\t}\n\t\t// setProjectDir resolves the (possibly relative) target against the launch\n\t\t// cwd and chdirs into it. Re-sync parsed.cwd to the resolved absolute path\n\t\t// so downstream consumers (buildSessionOptions, settings/discovery, session\n\t\t// persistence) don't re-resolve a relative string against the new cwd.\n\t\tparsed.cwd = getProjectDir();\n\t\treturn;\n\t}\n\tawait maybeAutoChdir(parsed);\n}\n","sourceCodeStart":42,"sourceCodeEnd":71,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/startup-cwd.ts#L42-L71","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nomp --cwd ~/Documnts/project\n// after\nomp --cwd ~/Documents/project","handlingStrategy":"validation","validationCode":"import { statSync } from \"node:fs\";\ntry {\n  if (!statSync(targetDir).isDirectory()) throw new Error(`${targetDir} is not a directory`);\n} catch (err) {\n  if ((err as NodeJS.ErrnoException).code === \"ENOENT\") throw new Error(`Directory does not exist: ${targetDir}`);\n  throw err;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await applyStartupCwd(parsed);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Cannot change working directory\")) {\n    console.error(`${err.message}\\nCheck the path, or on macOS grant Full Disk Access to your terminal.`);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["filesystem","permissions","startup","macos"],"backgroundTag":"cwd-change-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}