{"record":{"id":"8ed68a0eee244161","repo":"rohitg00/agentmemory","slug":"eexist","errorCode":"EEXIST","errorMessage":"${target} already exists — leaving it untouched.","messagePattern":"(.+?) already exists — leaving it untouched\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/cli.ts","lineNumber":2951,"sourceCode":"      \"Could not locate .env.example in the package. Re-install with: npm i -g @agentmemory/agentmemory\",\n    );\n    process.exit(1);\n  }\n  const dir = dirname(target);\n  const { mkdir, copyFile } = await import(\"node:fs/promises\");\n  const { constants: fsConstants } = await import(\"node:fs\");\n  try {\n    await mkdir(dir, { recursive: true });\n    // COPYFILE_EXCL collapses the exists-check + copy into one syscall —\n    // an existsSync(target) + copyFile() pair races with a parallel init\n    // (or any other process touching ~/.agentmemory/.env between the two\n    // calls) and would silently overwrite a config the operator just\n    // wrote. EEXIST out of copyFile is the only \"already configured\"\n    // signal we trust.\n    await copyFile(template, target, fsConstants.COPYFILE_EXCL);\n  } catch (err) {\n    if ((err as NodeJS.ErrnoException)?.code === \"EEXIST\") {\n      p.log.warn(`${target} already exists — leaving it untouched.`);\n      p.log.info(\n        `Compare against the latest template: diff ${target} ${template}`,\n      );\n      p.outro(\"Nothing changed.\");\n      return;\n    }\n    p.log.error(\n      `Failed to copy template: ${err instanceof Error ? err.message : String(err)}`,\n    );\n    process.exit(1);\n  }\n  p.log.success(`Wrote ${target}`);\n  p.note(\n    [\n      \"All keys are commented out by default. Uncomment the ones you want.\",\n      \"\",\n      \"Common next steps:\",\n      \"  1. Pick an LLM provider key (ANTHROPIC_API_KEY / OPENAI_API_KEY / GEMINI_API_KEY / etc.)\",","sourceCodeStart":2933,"sourceCodeEnd":2969,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/cli.ts#L2933-L2969","documentation":"`agentmemory connect` (or the config-install command at src/cli.ts:2951) copies a config template to the target path using copyFile(..., COPYFILE_EXCL) so it never overwrites an existing file. When the target already exists, Node's copyFile throws with code EEXIST; the CLI catches it, logs '<target> already exists — leaving it untouched.', and exits without changes. The message string is the warning you see, surfaced as a NodeJS.ErrnoException.","triggerScenarios":"Running the install/connect command twice, or after another tool (the app itself, another CLI) already created the target config file (e.g. an MCP config JSON for the adapter).","commonSituations":"Re-running setup on an existing project; a previous version of the tool wrote the file and you want the new template; multiple agents/tools writing the same config path.","solutions":["Intentional safety: diff your file against the template as the CLI suggests: diff <target> <template>.","If you want the new template, back up and remove the existing file, then re-run the command.","Merge desired new keys manually instead of replacing a hand-tuned config.","Use a fresh/dry-run target path if you just want to preview the template contents."],"exampleFix":"// before: rerun refuses to clobber\n// ~/.claude/mcp.json already exists — leaving it untouched.\n// after: review then replace deliberately\ncp ~/.claude/mcp.json ~/.claude/mcp.json.bak\nrm ~/.claude/mcp.json && npx agentmemory connect","handlingStrategy":"try-catch","validationCode":"import { existsSync } from \"node:fs\";\nif (existsSync(target)) {\n  console.log(`${target} exists; diff against ${template} or delete it to re-install`);\n  process.exit(0);\n}","typeGuard":"const isEexist = (e: unknown): e is NodeJS.ErrnoException =>\n  (e as NodeJS.ErrnoException)?.code === \"EEXIST\";","tryCatchPattern":"try {\n  await copyFile(template, target, fsConstants.COPYFILE_EXCL);\n} catch (err) {\n  if ((err as NodeJS.ErrnoException)?.code === \"EEXIST\") {\n    console.log(`${target} already exists — diff ${target} ${template}`);\n  } else throw err;\n}","preventionTips":["Check for the target file before running install/connect commands.","Treat EEXIST as 'already configured', not a failure.","Diff existing configs against new templates after upgrades to pick up new keys.","Back up before deleting a target to accept a fresh template."],"tags":["cli","eexist","file-conflict","config","idempotency"],"backgroundTag":"file-already-exists","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}