MCPcopy Index your code
hub / github.com/codeaashu/claude-code / groupHooksByEventAndMatcher

Function groupHooksByEventAndMatcher

src/utils/hooks/hooksConfigManager.ts:270–365  ·  view source on GitHub ↗
(
  appState: AppState,
  toolNames: string[],
)

Source from the content-addressed store, hash-verified

268
269// Group hooks by event and matcher
270export function groupHooksByEventAndMatcher(
271 appState: AppState,
272 toolNames: string[],
273): Record<HookEvent, Record<string, IndividualHookConfig[]>> {
274 const grouped: Record<HookEvent, Record<string, IndividualHookConfig[]>> = {
275 PreToolUse: {},
276 PostToolUse: {},
277 PostToolUseFailure: {},
278 PermissionDenied: {},
279 Notification: {},
280 UserPromptSubmit: {},
281 SessionStart: {},
282 SessionEnd: {},
283 Stop: {},
284 StopFailure: {},
285 SubagentStart: {},
286 SubagentStop: {},
287 PreCompact: {},
288 PostCompact: {},
289 PermissionRequest: {},
290 Setup: {},
291 TeammateIdle: {},
292 TaskCreated: {},
293 TaskCompleted: {},
294 Elicitation: {},
295 ElicitationResult: {},
296 ConfigChange: {},
297 WorktreeCreate: {},
298 WorktreeRemove: {},
299 InstructionsLoaded: {},
300 CwdChanged: {},
301 FileChanged: {},
302 }
303
304 const metadata = getHookEventMetadata(toolNames)
305
306 // Include hooks from settings files
307 getAllHooks(appState).forEach(hook => {
308 const eventGroup = grouped[hook.event]
309 if (eventGroup) {
310 // For events without matchers, use empty string as key
311 const matcherKey =
312 metadata[hook.event].matcherMetadata !== undefined
313 ? hook.matcher || ''
314 : ''
315 if (!eventGroup[matcherKey]) {
316 eventGroup[matcherKey] = []
317 }
318 eventGroup[matcherKey].push(hook)
319 }
320 })
321
322 // Include registered hooks (e.g., plugin hooks)
323 const registeredHooks = getRegisteredHooks()
324 if (registeredHooks) {
325 for (const [event, matchers] of Object.entries(registeredHooks)) {
326 const hookEvent = event as HookEvent
327 const eventGroup = grouped[hookEvent]

Callers 1

HooksConfigMenuFunction · 0.85

Calls 5

getAllHooksFunction · 0.85
getRegisteredHooksFunction · 0.85
forEachMethod · 0.80
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected