MCPcopy
hub / github.com/codeaashu/claude-code / loadPluginHooks

Function loadPluginHooks

src/utils/plugins/pluginLoader.ts:1224–1242  ·  view source on GitHub ↗

* Loads and validates plugin hooks configuration from a JSON file. * IMPORTANT: Only call this when the hooks file is expected to exist. * * @param hooksConfigPath - Full path to the hooks.json file * @param pluginName - Plugin name for error messages * @returns Validated HooksSettings * @thro

(
  hooksConfigPath: string,
  pluginName: string,
)

Source from the content-addressed store, hash-verified

1222 * @throws Error if file doesn't exist or is invalid
1223 */
1224async function loadPluginHooks(
1225 hooksConfigPath: string,
1226 pluginName: string,
1227): Promise<HooksSettings> {
1228 if (!(await pathExists(hooksConfigPath))) {
1229 throw new Error(
1230 `Hooks file not found at ${hooksConfigPath} for plugin ${pluginName}. If the manifest declares hooks, the file must exist.`,
1231 )
1232 }
1233
1234 const content = await readFile(hooksConfigPath, { encoding: 'utf-8' })
1235 const rawHooksConfig = jsonParse(content)
1236
1237 // The hooks.json file has a wrapper structure with description and hooks
1238 // Use PluginHooksSchema to validate and extract the hooks property
1239 const validatedPluginHooks = PluginHooksSchema().parse(rawHooksConfig)
1240
1241 return validatedPluginHooks.hooks as HooksSettings
1242}
1243
1244/**
1245 * Validate a list of plugin component relative paths by checking existence in parallel.

Callers 6

processSessionStartHooksFunction · 0.85
processSetupHooksFunction · 0.85
createPluginFromPathFunction · 0.85
refreshActivePluginsFunction · 0.85
setupPluginHookHotReloadFunction · 0.85
useManagePluginsFunction · 0.85

Calls 4

pathExistsFunction · 0.85
readFileFunction · 0.85
jsonParseFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected