{"record":{"id":"d8f8d1aeabf789e1","repo":"rohitg00/agentmemory","slug":"default-data-dir-datadirresolution-relocatedfrom","errorCode":null,"errorMessage":"Default data dir ${dataDirResolution.relocatedFrom} is inside a git worktree; using ${dataDirResolution.dataDir} instead.","messagePattern":"Default data dir (.+?) is inside a git worktree; using (.+?) instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cli.ts","lineNumber":495,"sourceCode":"    join(process.cwd(), \"iii-config.yaml\"),\n    join(homedir(), \".agentmemory\", \"iii-config.yaml\"),\n    join(__dirname, \"iii-config.yaml\"),\n    join(__dirname, \"..\", \"iii-config.yaml\"),\n  ];\n  for (const c of candidates) {\n    if (existsSync(c)) return resolve(c);\n  }\n  return \"\";\n}\n\nfunction warnIfRelocatedDataDir(): void {\n  if (!dataDirResolution.relocatedFrom) return;\n\n  try {\n    mkdirSync(dataDirResolution.dataDir, { recursive: true });\n    const marker = join(dataDirResolution.dataDir, \".cwd-relocation-warning\");\n    if (existsSync(marker)) return;\n    p.log.warn(\n      `Default data dir ${dataDirResolution.relocatedFrom} is inside a git worktree; using ${dataDirResolution.dataDir} instead.`,\n    );\n    writeFileSync(marker, new Date().toISOString());\n  } catch {\n    p.log.warn(\n      `Default data dir ${dataDirResolution.relocatedFrom} is inside a git worktree; using ${dataDirResolution.dataDir} instead.`,\n    );\n  }\n}\n\nfunction whichBinary(name: string): string | null {\n  const cmd = IS_WINDOWS ? \"where\" : \"which\";\n  try {\n    const out = execFileSync(cmd, [name], {\n      encoding: \"utf-8\",\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n    });\n    const first = out","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/cli.ts#L477-L513","documentation":"agentmemory resolves its default data directory at CLI startup. If the default location (project-local data dir) sits inside a git worktree, the CLI refuses to store state there and relocates the data dir, printing this warning once per relocated location via warnIfRelocatedDataDir. A marker file (.cwd-relocation-warning) suppresses repeat warnings. It is purely informational — the engine continues with the relocated path.","triggerScenarios":"Running any `agentmemory` CLI command (via startEngine → warnIfRelocatedDataDir) from a working directory whose default data dir resolves to a path inside a git worktree (a directory created by `git worktree add`), when no prior marker file exists or the marker write/creation threw.","commonSituations":"Developers checking out the repo with `git worktree add` for parallel branches; CI runners that clone via worktrees; monorepo setups using worktrees; first run in a fresh worktree before the marker file exists.","solutions":["Do nothing — the engine uses the relocated data dir automatically; this is informational.","If you want state co-located anyway, set the data dir explicitly via the AGENTMEMORY data-dir environment/CLI option to a path outside the worktree.","Silence the warning by ensuring the marker file `.cwd-relocation-warning` can be written in the relocated data dir (check disk space and permissions).","Remove the git worktree and use a normal clone if project-local state is required."],"exampleFix":"// before (run inside a worktree, data dir relocated)\n$ agentmemory start\n// after (explicit data dir outside worktree)\n$ AGENTMEMORY_DATA_DIR=~/.agentmemory/data agentmemory start","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\n// detect a git worktree before starting the engine\nconst insideWorktree =\n  existsSync(\".git\") === false ||\n  require(\"node:fs\").readFileSync(\".git\", \"utf8\").includes(\"gitdir:\");\nif (insideWorktree) {\n  process.env.AGENTMEMORY_DATA_DIR ??= \"~/.agentmemory/data\"; // relocate proactively\n}","typeGuard":"function isInGitWorktree(dir: string): boolean {\n  const gitPath = join(dir, \".git\");\n  try {\n    return statSync(gitPath).isFile() && readFileSync(gitPath, \"utf8\").startsWith(\"gitdir:\");\n  } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Set the data-dir env/option explicitly when working in worktrees.","Check for a .git file (not directory) — the hallmark of a worktree — before starting.","Keep the marker file intact in the relocated dir to silence repeats.","Prefer normal clones or explicit data dirs in CI."],"tags":["filesystem","git-worktree","cli"],"backgroundTag":"data-dir-relocated-git-worktree","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}