{"record":{"id":"3f1ffac3e68e9161","repo":"JuliusBrussee/caveman","slug":"codex-home-points-to-json-stringify-configured-but-that-path","errorCode":null,"errorMessage":"CODEX_HOME points to ${JSON.stringify(configured)}, but that path does not exist","messagePattern":"CODEX_HOME points to (.+?), but that path does not exist","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":6198,"sourceCode":"function agentUserPath(agent: string, path: string): string {\n  const prefix = agent === \"claude\" ? \"~/.claude/\" : agent === \"codex\" ? \"~/.codex/\" : undefined;\n  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 {","sourceCodeStart":6180,"sourceCodeEnd":6216,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L6180-L6216","documentation":"The CLI honors a CODEX_HOME environment variable override for the Codex home directory, but deliberately does not fall back to a default when the override is set and invalid — falling back silently could route to another account's home. If statSync on the configured path fails with ENOENT, it throws naming the exact configured value.","triggerScenarios":"CODEX_HOME is set to a path that does not exist when the CLI resolves the Codex home: statSync(configured) throws with code ENOENT — a typo'd path, a deleted/moved directory, or a path that was never created (e.g. ~/codex-home vs ~/.codex).","commonSituations":"CODEX_HOME pointing at a removed dotfile directory after cleaning ~/.codex; a docker/CI container where the volume mount for CODEX_HOME was never created; switching machines where the old home path doesn't exist; typos like CODEX_HOME=$HOME/.codexx.","solutions":["Create the directory: mkdir -p \"$CODEX_HOME\"","Unset CODEX_HOME (or fix the typo) so the CLI uses the default Codex home","Point CODEX_HOME at an existing directory, e.g. export CODEX_HOME=$HOME/.codex","Check for typos and variable expansion failures in the shell profile that sets CODEX_HOME","In containers/CI, ensure the CODEX_HOME volume is mounted/created before the CLI runs"],"exampleFix":"// before\nexport CODEX_HOME=$HOME/.codexx   # does not exist\n// after\nexport CODEX_HOME=$HOME/.codex    # or: mkdir -p \"$CODEX_HOME\"","handlingStrategy":"validation","validationCode":"import { existsSync, statSync } from 'fs';\nconst home = process.env.CODEX_HOME;\nif (home && (!existsSync(home) || !statSync(home).isDirectory())) {\n  throw new Error(`CODEX_HOME=${home} is missing or not a directory`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  cli.codexCommand(args);\n} catch (err) {\n  if ((err as Error).message.includes('but that path does not exist')) {\n    const p = JSON.parse((err as Error).message.match(/CODEX_HOME points to (\\\".*?\\\")/)?.[1] ?? '\"?\"');\n    console.error(`Create ${p} (mkdir -p) or unset/fix CODEX_HOME.`);\n  } else throw err;\n}","preventionTips":["Never silently fall back from an invalid CODEX_HOME — fix or unset it","Run mkdir -p on CODEX_HOME paths in container/CI entrypoints","Check for typos and shell-expansion failures wherever CODEX_HOME is set","Verify the path exists and is a directory after machine or container migrations"],"tags":["env-var","codex","path","directory"],"backgroundTag":"file-not-found","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"}