thedotmack/claude-mem · error

Corrupt JSON in , refusing to overwrite user hooks

Error message

Corrupt JSON in ${GEMINI_HOOKS_CONFIG_PATH}, refusing to overwrite user hooks

What it means

readAntigravityHooksConfig parses the Antigravity hooks config JSON (shared Gemini hooks file). On JSON.parse failure it logs and throws so that removeAntigravityHooksFromHooksConfig and status checks never overwrite a file whose content they could not understand. This protects user-managed hook entries from data loss.

Solutions

  1. Fix the JSON syntax in GEMINI_HOOKS_CONFIG_PATH (validate with a JSON parser).
  2. Remove only the claude-mem entries manually if you want to keep other hooks, then retry.
  3. Restore the file from backup or delete it and re-run the installer to regenerate defaults.
  4. Avoid concurrent installers/tools writing the same hooks file; re-run after the other tool finishes.

Example fix

// before (hooks.json)
{ "hooks": { "SessionStart": [ { "command": "bun run",

// after
{
  "hooks": {
    "SessionStart": [
      { "command": "bun run worker" }
    ]
  }
}
Defensive patterns

Strategy: validation

Validate before calling

try {
  JSON.parse(readFileSync(GEMINI_HOOKS_CONFIG_PATH, 'utf8'));
} catch (e) {
  console.error(`Fix JSON in ${GEMINI_HOOKS_CONFIG_PATH} before modifying hooks:`, e.message);
  process.exit(1);
}

Try / catch

try {
  installer.removeHooks();
} catch (e) {
  if (String(e.message).includes('Corrupt JSON')) {
    console.error(`Repair or delete ${GEMINI_HOOKS_CONFIG_PATH}, then re-run.`);
  } throw e;
}

Prevention

When it happens

Trigger: Any operation that calls readAntigravityHooksConfig (install merge, removal, status check) while GEMINI_HOOKS_CONFIG_PATH contains invalid JSON — corrupt edits, partial writes, or non-JSON content placed at that path.

Common situations: Manual edits to the hooks config, another extension writing incompatible content to the shared Gemini hooks file, or a previous crashed installer leaving a truncated file.

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


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/bb4bc90eb209c4ba. Report an issue: GitHub.

Appendix: source

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

// unparseable) content throws so we never clobber a user's hand-edited hooks.
function readAntigravityHooksConfig(): AntigravityHooksConfig {
  if (!existsSync(GEMINI_HOOKS_CONFIG_PATH)) {
    return {};
  }
  const content = readFileSync(GEMINI_HOOKS_CONFIG_PATH, 'utf-8');
  if (!content.trim()) {
    return {};
  }
  try {
    return JSON.parse(content) as AntigravityHooksConfig;
  } catch (error) {
    logger.error(
      'WORKER',
      'Corrupt JSON in Antigravity CLI hooks config',
      { path: GEMINI_HOOKS_CONFIG_PATH },
      error instanceof Error ? error : new Error(String(error)),
    );
    throw new Error(`Corrupt JSON in ${GEMINI_HOOKS_CONFIG_PATH}, refusing to overwrite user hooks`);
  }
}

function writeAntigravityHooksConfig(hooksConfig: AntigravityHooksConfig): void {
  mkdirSync(path.dirname(GEMINI_HOOKS_CONFIG_PATH), { recursive: true });
  writeFileSync(GEMINI_HOOKS_CONFIG_PATH, JSON.stringify(hooksConfig, null, 2) + '\n');
}

// Generic JSON-group merge — merges claude-mem's hook groups into an existing
// event→groups map (keyed on the `claude-mem` hook name), preserving any hooks
// the user or other tools registered. Event-name agnostic.
function mergeHooksIntoConfig(
  existingConfig: AntigravityHooksConfig,
  newHooks: AntigravityHooksConfig,
): AntigravityHooksConfig {
  const config: AntigravityHooksConfig = { ...existingConfig };

  for (const [eventName, newGroups] of Object.entries(newHooks)) {

View on GitHub (pinned to d8bc9755e7)