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

Function loadPluginHooks

src/utils/plugins/pluginLoader.ts:1225–1243  ·  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

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

pathExistsFunction · 0.85
readFileFunction · 0.85
jsonParseFunction · 0.85

Tested by

no test coverage detected