{"record":{"id":"10a2284a9a1c7cbe","repo":"thedotmack/claude-mem","slug":"corrupt-hooks-json-at-windsurf-hooks-json-path","errorCode":null,"errorMessage":"Corrupt hooks.json at ${WINDSURF_HOOKS_JSON_PATH}, refusing to overwrite","messagePattern":"Corrupt hooks\\.json at (.+?), refusing to overwrite","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/integrations/WindsurfHooksInstaller.ts","lineNumber":142,"sourceCode":"  workerServicePath: string,\n  workingDirectory: string,\n): void {\n  mkdirSync(WINDSURF_HOOKS_DIR, { recursive: true });\n\n  let existingConfig: WindsurfHooksJson = { hooks: {} };\n  if (existsSync(WINDSURF_HOOKS_JSON_PATH)) {\n    try {\n      existingConfig = JSON.parse(readFileSync(WINDSURF_HOOKS_JSON_PATH, 'utf-8'));\n      if (!existingConfig.hooks) {\n        existingConfig.hooks = {};\n      }\n    } catch (error) {\n      if (error instanceof Error) {\n        logger.error('WORKER', 'Corrupt hooks.json, refusing to overwrite', { path: WINDSURF_HOOKS_JSON_PATH }, error);\n      } else {\n        logger.error('WORKER', 'Corrupt hooks.json, refusing to overwrite', { path: WINDSURF_HOOKS_JSON_PATH }, new Error(String(error)));\n      }\n      throw new Error(`Corrupt hooks.json at ${WINDSURF_HOOKS_JSON_PATH}, refusing to overwrite`);\n    }\n  }\n\n  for (const eventName of WINDSURF_HOOK_EVENTS) {\n    const command = buildHookCommand(bunPath, workerServicePath, eventName);\n\n    const hookEntry: WindsurfHookEntry = {\n      command,\n      show_output: false,\n      working_directory: workingDirectory,\n    };\n\n    const existingHooks = (existingConfig.hooks[eventName] ?? []).filter(\n      (hook) => !hook.command.includes('worker-service') || !hook.command.includes('windsurf')\n    );\n\n    existingConfig.hooks[eventName] = [...existingHooks, hookEntry];\n  }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/integrations/WindsurfHooksInstaller.ts#L124-L160","documentation":"mergeAndWriteHooksJson() reads the Windsurf hooks.json; if it exists but JSON.parse fails, the installer refuses to overwrite the user's existing config (which may be partially valid) and throws after logging the parse error. This mirrors the same protective pattern used for Gemini/Antigravity settings.","triggerScenarios":"Running installWindsurfHooks when the Windsurf hooks.json file (WINDSURF_HOOKS_JSON_PATH) is present but contains invalid JSON.","commonSituations":"User hand-edited the hooks.json and left a syntax error; another hook installer wrote malformed JSON and crashed; file truncated by an interrupted write; merge-conflict markers left in the file.","solutions":["Open the Windsurf hooks.json path and fix the JSON syntax (validate with a JSON linter).","If unsalvageable, back up then replace with `{ \"hooks\": {} }` and re-run the installer.","Re-run `npx claude-mem@latest install` (Windsurf path) once the file parses."],"exampleFix":"// before — hooks.json: { \"hooks\": { , } }\n\n// after\n{\n  \"hooks\": {}\n}\n// then re-run the Windsurf installer step","handlingStrategy":"validation","validationCode":"import { readFileSync, existsSync } from 'fs';\n\nfunction windsurfHooksJsonValid(path: string): boolean {\n  if (!existsSync(path)) return true;\n  try { JSON.parse(readFileSync(path, 'utf-8')); return true; }\n  catch { return false; }\n}","typeGuard":"function isCorruptWindsurfHooksError(e: unknown): boolean {\n  return e instanceof Error && /Corrupt hooks\\.json .* refusing to overwrite/i.test(e.message);\n}","tryCatchPattern":"try {\n  mergeAndWriteHooksJson(bunPath, workerServicePath, cwd);\n} catch (e) {\n  if (e instanceof Error && /refusing to overwrite/i.test(e.message)) {\n    console.error(`${e.message}\\nFix the JSON (or back it up and replace with {\"hooks\":{}}), then re-run.`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Validate the Windsurf hooks.json parses before running the installer.","Back up config files before bulk edits.","Respect 'refusing to overwrite' as data protection — repair the file instead of bypassing."],"tags":["config","json","filesystem","windsurf","installer"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}