thedotmack/claude-mem · warning
[install] Failed to parse existing settings.json, starting f
Error message
[install] Failed to parse existing settings.json, starting from empty:
What it means
The installer reads an existing settings.json (with BOM tolerance) before merging updates. If parsing throws, it warns and starts from an empty document — meaning every OTHER top-level key in the broken file will be lost when the new settings are written. The current error message is included so you can locate the syntax problem.
Source
Thrown at src/npx-cli/commands/install.ts:799
// apiKeyHelper, model, statusLine, etc.). readFlatSettings unwraps the
// env subtree for reads, but writing that flattened view back as the
// entire file silently drops every non-env top-level key — destroying
// user configuration that disableClaudeAutoMemory + writeJsonFileAtomic
// had carefully written.
//
// Track whether the file uses the env-nested shape so we mutate only the
// relevant subtree and preserve every other top-level key on write.
let document: Record<string, unknown> = {};
let envNested = false;
if (existsSync(path)) {
try {
const parsed = parseJsonWithBom(readFileSync(path, 'utf-8'));
if (parsed && typeof parsed === 'object') {
document = parsed as Record<string, unknown>;
envNested = typeof document.env === 'object' && document.env !== null;
}
} catch (parseError: unknown) {
console.warn('[install] Failed to parse existing settings.json, starting from empty:', parseError instanceof Error ? parseError.message : String(parseError));
document = {};
}
} else {
const dir = dirname(path);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
}
const target = envNested
? (document.env as Record<string, unknown>)
: document;
for (const [key, value] of Object.entries(updates)) {
target[key] = value;
}
writeSettingsJsonAtomic(path, document);
// settings.json can carry tokens (CMEM Pro setup token, provider APIView on GitHub (pinned to e2d1df569a)
Solutions
- Back up and repair the file BEFORE letting the installer write: `cp ~/.claude-mem/settings.json{,.bak}` then fix the syntax error reported in the warning message.
- Validate with `jq . ~/.claude-mem/settings.json` — the parse error location matches what the installer hit.
- If the contents are not worth saving, delete the file and let the installer regenerate a clean one.
- After install, re-add any custom top-level keys you lost from the backup.
Example fix
// before: ~/.claude-mem/settings.json (invalid — trailing comma)
{ "CLAUDE_MEM_PROVIDER": "claude", }
// after
{ "CLAUDE_MEM_PROVIDER": "claude" } Defensive patterns
Strategy: validation
Validate before calling
// Validate BEFORE the installer does — protects other keys from the empty-document path:
import { readFileSync, existsSync, copyFileSync } from 'node:fs';
if (existsSync(p)) {
copyFileSync(p, `${p}.bak`); // snapshot before any installer write
try { JSON.parse(readFileSync(p, 'utf8').replace(/^\uFEFF/, '')); }
catch (e) { console.error('settings.json invalid — fix before install:', e); process.exit(1); }
} Try / catch
catch (parseError: unknown) {
// KEEP the parsed document as {} ONLY if you know the file had no other keys;
// otherwise abort the write instead of clobbering — data preservation beats convenience.
} Prevention
- Snapshot settings.json before every claude-mem install/upgrade run.
- Lint settings files in CI (`jq . settings.json > /dev/null`) when you manage them declaratively.
- Use JSON editors or jq for edits, never freeform text editors with JSONC habits.
- Remember the semantics: this warning means all unmanaged top-level keys WILL be lost on the next write.
When it happens
Trigger: parseJsonWithBom throwing on invalid JSON: trailing commas, comments, unquoted keys, truncated file from a killed concurrent write. The subsequent writeSettingsJsonAtomic overwrites the file with only the installer's keys.
Common situations: Hand-edited settings.json with a trailing comma or JSON5-style comment; file truncated by a crash mid-write; another tool wrote JSON-with-BOM plus invalid syntax; symlinked settings file pointing at a broken target.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to read existing settings file; starting fresh
- claude-mem: could not read ${USER_SETTINGS_PATH} while check
- [SETTINGS] Failed to load settings, using defaults:
- Could not restrict permissions on ${path} to 0600: ${chmodEr
- generation parse error: ${outcome.reason}
AI-assisted analysis of thedotmack/claude-mem@e2d1df569a (2026-08-20).
Data as JSON: /api/errors/5b2b77e4dceae201.
Report an issue: GitHub.