thedotmack/claude-mem · error · Error

Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwri

Error message

Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwrite user settings

What it means

readAntigravitySettings() reads ~/.gemini/settings.json (shared between Gemini CLI and Antigravity CLI). If the file exists but JSON.parse fails, the installer deliberately refuses to overwrite the user's hand-edited settings and throws, because silently rewriting would destroy a partially-valid config. The original parse error is logged first, then re-thrown as a plain Error from the install flow.

Source

Thrown at src/services/integrations/AntigravityCliHooksInstaller.ts:118

    }],
  };
}

function readAntigravitySettings(): AntigravitySettingsJson {
  if (!existsSync(GEMINI_SETTINGS_PATH)) {
    return {};
  }

  const content = readFileSync(GEMINI_SETTINGS_PATH, 'utf-8');
  try {
    return JSON.parse(content) as AntigravitySettingsJson;
  } catch (error) {
    if (error instanceof Error) {
      logger.error('WORKER', 'Corrupt JSON in Antigravity CLI (shared Gemini) settings', { path: GEMINI_SETTINGS_PATH }, error);
    } else {
      logger.error('WORKER', 'Corrupt JSON in Antigravity CLI (shared Gemini) settings', { path: GEMINI_SETTINGS_PATH }, new Error(String(error)));
    }
    throw new Error(`Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwrite user settings`);
  }
}

function writeAntigravitySettings(settings: AntigravitySettingsJson): void {
  mkdirSync(GEMINI_CONFIG_DIR, { recursive: true });
  writeFileSync(GEMINI_SETTINGS_PATH, JSON.stringify(settings, null, 2) + '\n');
}

// Generic JSON-group merge — doesn't depend on event names, copied verbatim
// from the removed GeminiCliHooksInstaller.ts.
function mergeHooksIntoSettings(
  existingSettings: AntigravitySettingsJson,
  newHooks: AntigravityHooksConfig,
): AntigravitySettingsJson {
  const settings = { ...existingSettings };
  if (!settings.hooks) {
    settings.hooks = {};
  }

View on GitHub (pinned to d768ba3643)

Solutions

  1. Open ~/.gemini/settings.json in an editor and fix the JSON syntax error (validate with a JSON linter or `node -e "JSON.parse(require('fs').readFileSync(process.env.HOME+'/.gemini/settings.json','utf8'))"`).
  2. If you cannot salvage it, back up the file, replace it with `{}`, then re-run the installer.
  3. Re-run `npx claude-mem@latest install` once the file parses cleanly.

Example fix

// before — settings.json contains: { "hooks": { , } }

// after — valid JSON
{
  "hooks": {}
}
// then re-run: npx claude-mem@latest install
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync, existsSync } from 'fs';

function isSettingsJsonValid(path: string): boolean {
  if (!existsSync(path)) return true; // absent is fine
  try { JSON.parse(readFileSync(path, 'utf-8')); return true; }
  catch { return false; }
}

Type guard

function isCorruptSettingsError(e: unknown): boolean {
  return e instanceof Error && /Corrupt JSON in .*settings\.json/i.test(e.message);
}

Try / catch

try {
  await installAntigravityCliHooks();
} catch (e) {
  if (e instanceof Error && /refusing to overwrite user settings/.test(e.message)) {
    console.error(`${e.message}\nFix or back up the settings file, then re-run install.`);
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running installAntigravityCliHooks (or the main installer's Antigravity path) when ~/.gemini/settings.json contains malformed JSON — stray trailing comma, unquoted keys, a pasted snippet with smart quotes, or a truncated file from a previous interrupted write.

Common situations: User manually edited settings.json and introduced a syntax error; another tool wrote partial JSON and crashed; file got corrupted by a merge conflict marker left in; an editor inserted a BOM or CRLF that breaks the parser on a strict platform.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12). Data as JSON: /api/errors/33ca39b8342e7f46. Report an issue: GitHub.