{"record":{"id":"bb4bc90eb209c4ba","repo":"thedotmack/claude-mem","slug":"corrupt-json-in-gemini-hooks-config-path-refusing-to","errorCode":null,"errorMessage":"Corrupt JSON in ${GEMINI_HOOKS_CONFIG_PATH}, refusing to overwrite user hooks","messagePattern":"Corrupt JSON in (.+?), refusing to overwrite user hooks","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/integrations/AntigravityCliHooksInstaller.ts","lineNumber":205,"sourceCode":"// unparseable) content throws so we never clobber a user's hand-edited hooks.\nfunction readAntigravityHooksConfig(): AntigravityHooksConfig {\n  if (!existsSync(GEMINI_HOOKS_CONFIG_PATH)) {\n    return {};\n  }\n  const content = readFileSync(GEMINI_HOOKS_CONFIG_PATH, 'utf-8');\n  if (!content.trim()) {\n    return {};\n  }\n  try {\n    return JSON.parse(content) as AntigravityHooksConfig;\n  } catch (error) {\n    logger.error(\n      'WORKER',\n      'Corrupt JSON in Antigravity CLI hooks config',\n      { path: GEMINI_HOOKS_CONFIG_PATH },\n      error instanceof Error ? error : new Error(String(error)),\n    );\n    throw new Error(`Corrupt JSON in ${GEMINI_HOOKS_CONFIG_PATH}, refusing to overwrite user hooks`);\n  }\n}\n\nfunction writeAntigravityHooksConfig(hooksConfig: AntigravityHooksConfig): void {\n  mkdirSync(path.dirname(GEMINI_HOOKS_CONFIG_PATH), { recursive: true });\n  writeFileSync(GEMINI_HOOKS_CONFIG_PATH, JSON.stringify(hooksConfig, null, 2) + '\\n');\n}\n\n// Generic JSON-group merge — merges claude-mem's hook groups into an existing\n// event→groups map (keyed on the `claude-mem` hook name), preserving any hooks\n// the user or other tools registered. Event-name agnostic.\nfunction mergeHooksIntoConfig(\n  existingConfig: AntigravityHooksConfig,\n  newHooks: AntigravityHooksConfig,\n): AntigravityHooksConfig {\n  const config: AntigravityHooksConfig = { ...existingConfig };\n\n  for (const [eventName, newGroups] of Object.entries(newHooks)) {","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/integrations/AntigravityCliHooksInstaller.ts#L187-L223","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the JSON syntax in GEMINI_HOOKS_CONFIG_PATH (validate with a JSON parser).","Remove only the claude-mem entries manually if you want to keep other hooks, then retry.","Restore the file from backup or delete it and re-run the installer to regenerate defaults.","Avoid concurrent installers/tools writing the same hooks file; re-run after the other tool finishes."],"exampleFix":"// before (hooks.json)\n{ \"hooks\": { \"SessionStart\": [ { \"command\": \"bun run\",\n\n// after\n{\n  \"hooks\": {\n    \"SessionStart\": [\n      { \"command\": \"bun run worker\" }\n    ]\n  }\n}","handlingStrategy":"validation","validationCode":"try {\n  JSON.parse(readFileSync(GEMINI_HOOKS_CONFIG_PATH, 'utf8'));\n} catch (e) {\n  console.error(`Fix JSON in ${GEMINI_HOOKS_CONFIG_PATH} before modifying hooks:`, e.message);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  installer.removeHooks();\n} catch (e) {\n  if (String(e.message).includes('Corrupt JSON')) {\n    console.error(`Repair or delete ${GEMINI_HOOKS_CONFIG_PATH}, then re-run.`);\n  } throw e;\n}","preventionTips":["Run a JSON syntax check on the hooks config before install/remove/status operations.","Ensure only one installer writes the hooks file at a time.","Back up the hooks config before upgrading tools that share it."],"tags":["json","hooks-config","antigravity","install"],"backgroundTag":"json-parse-error","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}