{"record":{"id":"7fec6bb154cb7bc1","repo":"JuliusBrussee/caveman","slug":"failed-to-read-codex-home-json-stringify-configured-error-as","errorCode":null,"errorMessage":"failed to read CODEX_HOME ${JSON.stringify(configured)}: ${(error as Error).message}","messagePattern":"failed to read CODEX_HOME (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":6200,"sourceCode":"  if (!prefix || !path.startsWith(prefix)) return path;\n  const root = agent === \"claude\" ? claudeConfigDir() : codexHomeDir();\n  return join(root, path.slice(prefix.length));\n}\n\nexport function codexHomeDir(env: NodeJS.ProcessEnv = process.env): string {\n  const configured = env.CODEX_HOME;\n  if (!configured) return join(homedir(), \".codex\");\n  // Match Codex's own home resolver: a nonempty override may be relative, but\n  // must already be a directory and is canonicalized before use. Never fall\n  // back to another account's default home when the override is invalid.\n  let metadata: ReturnType<typeof statSync>;\n  try {\n    metadata = statSync(configured);\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n      throw new Error(`CODEX_HOME points to ${JSON.stringify(configured)}, but that path does not exist`);\n    }\n    throw new Error(`failed to read CODEX_HOME ${JSON.stringify(configured)}: ${(error as Error).message}`);\n  }\n  if (!metadata.isDirectory()) {\n    throw new Error(`CODEX_HOME points to ${JSON.stringify(configured)}, but that path is not a directory`);\n  }\n  try {\n    return realpathSync(configured);\n  } catch (error) {\n    throw new Error(`failed to canonicalize CODEX_HOME ${JSON.stringify(configured)}: ${(error as Error).message}`);\n  }\n}\n\nfunction codexAuthPath(): string {\n  return join(codexHomeDir(), \"auth.json\");\n}\n\nfunction nonEmptyString(v: unknown): v is string {\n  return typeof v === \"string\" && v.trim().length > 0;\n}","sourceCodeStart":6182,"sourceCodeEnd":6218,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L6182-L6218","documentation":"Thrown when resolving CODEX_HOME fails with a filesystem error other than ENOENT (e.g. EACCES, ENOTDIR). The CLI stats the configured CODEX_HOME path before use and wraps any non-missing-file read failure into this error, including the OS error message. It means the path exists conceptually but could not be stat'ed.","triggerScenarios":"statSync(configured) on the CODEX_HOME path throws an ErrnoException whose code is not ENOENT — e.g. a parent directory component is not a directory (ENOTDIR), permission is denied (EACCES), or an I/O error occurs on the path.","commonSituations":"CODEX_HOME pointing inside a file path (e.g. /home/user/file.txt/subdir), a symlink with no search permission on an ancestor directory, a network mount being unavailable, or running as a user lacking execute permission on a parent directory.","solutions":["Verify the CODEX_HOME path: run `ls -la` on it and each ancestor to find the inaccessible or wrong component","Fix the path in the environment (unset CODEX_HOME or point it at an existing writable directory)","Correct permissions on ancestor directories (chmod +x on directories along the path)","Re-run the command; if it is a transient mount/I/O problem, retry after the filesystem is healthy"],"exampleFix":"// before\nCODEX_HOME=/home/user/notes.txt codex ...\n// after\nCODEX_HOME=/home/user/.codex codex ...","handlingStrategy":"try-catch","validationCode":"const configured = process.env.CODEX_HOME;\nif (configured) {\n  try { const st = fs.statSync(configured); if (!st.isDirectory()) throw new Error(`${configured} is not a directory`); }\n  catch (e) { console.error(`Cannot access CODEX_HOME ${configured}: ${e.message}`); }\n}","typeGuard":"function isAccessibleDir(p: string): boolean {\n  try { return fs.statSync(p).isDirectory(); } catch { return false; }\n}","tryCatchPattern":"try {\n  runCodexCommand();\n} catch (e) {\n  if (String(e.message).startsWith(\"failed to read CODEX_HOME\")) {\n    console.error(`CODEX_HOME is set but unreadable: ${e.message}. Fix the path or unset CODEX_HOME.`);\n  }\n}","preventionTips":["Verify CODEX_HOME exists and is a directory before launching the CLI","Never point CODEX_HOME inside or at a file path","Keep execute permission on all ancestor directories","Quote env values to avoid stray characters in the path"],"tags":["filesystem","env-var","codex","config"],"backgroundTag":"file-read-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}