rohitg00/agentmemory · info
EEXIST
EEXIST
Error message
${target} already exists — leaving it untouched. What it means
`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.
Source
Thrown at src/cli.ts:2951
"Could not locate .env.example in the package. Re-install with: npm i -g @agentmemory/agentmemory",
);
process.exit(1);
}
const dir = dirname(target);
const { mkdir, copyFile } = await import("node:fs/promises");
const { constants: fsConstants } = await import("node:fs");
try {
await mkdir(dir, { recursive: true });
// COPYFILE_EXCL collapses the exists-check + copy into one syscall —
// an existsSync(target) + copyFile() pair races with a parallel init
// (or any other process touching ~/.agentmemory/.env between the two
// calls) and would silently overwrite a config the operator just
// wrote. EEXIST out of copyFile is the only "already configured"
// signal we trust.
await copyFile(template, target, fsConstants.COPYFILE_EXCL);
} catch (err) {
if ((err as NodeJS.ErrnoException)?.code === "EEXIST") {
p.log.warn(`${target} already exists — leaving it untouched.`);
p.log.info(
`Compare against the latest template: diff ${target} ${template}`,
);
p.outro("Nothing changed.");
return;
}
p.log.error(
`Failed to copy template: ${err instanceof Error ? err.message : String(err)}`,
);
process.exit(1);
}
p.log.success(`Wrote ${target}`);
p.note(
[
"All keys are commented out by default. Uncomment the ones you want.",
"",
"Common next steps:",
" 1. Pick an LLM provider key (ANTHROPIC_API_KEY / OPENAI_API_KEY / GEMINI_API_KEY / etc.)",View on GitHub (pinned to e04ba88819)
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.
Example fix
// before: rerun refuses to clobber // ~/.claude/mcp.json already exists — leaving it untouched. // after: review then replace deliberately cp ~/.claude/mcp.json ~/.claude/mcp.json.bak rm ~/.claude/mcp.json && npx agentmemory connect
Defensive patterns
Strategy: try-catch
Validate before calling
import { existsSync } from "node:fs";
if (existsSync(target)) {
console.log(`${target} exists; diff against ${template} or delete it to re-install`);
process.exit(0);
} Type guard
const isEexist = (e: unknown): e is NodeJS.ErrnoException => (e as NodeJS.ErrnoException)?.code === "EEXIST";
Try / catch
try {
await copyFile(template, target, fsConstants.COPYFILE_EXCL);
} catch (err) {
if ((err as NodeJS.ErrnoException)?.code === "EEXIST") {
console.log(`${target} already exists — diff ${target} ${template}`);
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Unknown --tools value "${toolsMode}" (valid: all, core); fal
- POST ${url} failed: ${res.status} ${res.statusText}${suffix}
- agentmemory: could not locate bundled plugin/ directory (sea
- OPENAI_API_KEY is required for the openai provider
- AGENTMEMORY_VIEWER_HOST=${host} requires AGENTMEMORY_SECRET
AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30).
Data as JSON: /api/errors/8ed68a0eee244161.
Report an issue: GitHub.