thedotmack/claude-mem · error
Settings file is corrupted. Delete
Error message
Settings file is corrupted. Delete ${settingsPath} to reset. What it means
When reading the on-disk settings file for a GET/merge path, a JSON parse failure (including BOM-related issues, though parseJsonWithBom handles BOM) is caught and converted to a 500 telling the user the settings file is corrupted and to delete settingsPath to reset it. The worker refuses to guess at partial settings content.
Solutions
- Open the file at the path named in the error and fix the JSON syntax error (the server log includes the parse error details)
- Back up the file, delete it, and let the worker recreate defaults, then reapply settings via the API
- Validate the JSON with a linter/parser before saving manual edits
- Ensure the process writing settings uses atomic writes (write temp + rename) to avoid truncation
Example fix
// before (settings.json)
{ "autoCompact": true, }
// after
{ "autoCompact": true } Defensive patterns
Strategy: try-catch
Validate before calling
import { readFileSync } from 'fs';
try { JSON.parse(readFileSync(settingsPath, 'utf-8')); } catch (e) { console.error(`${settingsPath} is not valid JSON: ${(e as Error).message}`); } Type guard
function isValidSettingsFile(raw: string): boolean {
try { JSON.parse(raw); return true; } catch { return false; }
} Try / catch
try {
const settings = await updateSettings(changes);
} catch (e) {
if (String(e).includes('Settings file is corrupted')) {
// back up the file, delete it to reset, then reapply settings
}
} Prevention
- Edit settings via the API/UI rather than hand-editing the JSON file
- Validate JSON with a linter before saving manual edits
- Use atomic writes (write temp file + rename) when modifying settings on disk
- Keep a backup of settings.json before bulk edits or upgrades
When it happens
Trigger: A request path that readFileSync's the settings JSON file and hits a parse error: truncated file from a crash mid-write, hand-edited JSON with a syntax mistake, encoding artifacts, or a file that is not JSON at all.
Common situations: Manual editing of the settings file with a trailing comma or comment; disk-full or power loss during a settings write; another tool writing non-JSON content to the settings path; copy-paste from a rich-text editor introducing smart quotes.
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.
Related errors
- claude-mem: could not read
- Failed to read existing settings file; starting fresh
- [SETTINGS] Failed to load settings, using defaults:
- sync hub pull: malformed /changes response
- sync hub pull: more must be boolean
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/c641d001aff4b812.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/worker/http/routes/SettingsRoutes.ts:111
res.status(400).json({
success: false,
error: validation.error
});
return;
}
const settingsPath = paths.settings();
this.ensureSettingsFile(settingsPath);
let settings: any = {};
if (existsSync(settingsPath)) {
const settingsData = readFileSync(settingsPath, 'utf-8');
try {
settings = parseJsonWithBom(settingsData);
} catch (parseError) {
const normalizedParseError = parseError instanceof Error ? parseError : new Error(String(parseError));
logger.error('HTTP', 'Failed to parse settings file', { settingsPath }, normalizedParseError);
res.status(500).json({
success: false,
error: `Settings file is corrupted. Delete ${settingsPath} to reset.`
});
return;
}
}
// Write whitelist. Secrets are deliberately absent: the Observation TV token,
// and the Chroma / Telegram / CloudSync keys. POST /api/settings has no
// authentication, so any page the user visits could set one of its choosing.
// Keeping them off this list means only the filesystem or the env can set them.
const settingKeys = [
'CLAUDE_MEM_MODEL',
'CLAUDE_MEM_CONTEXT_OBSERVATIONS',
'CLAUDE_MEM_WORKER_PORT',
'CLAUDE_MEM_WORKER_HOST',
'CLAUDE_MEM_PROVIDER',
'CLAUDE_MEM_CLAUDE_AUTH_METHOD',View on GitHub (pinned to d8bc9755e7)