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

Function getMatchingHooks

src/utils/hooks.ts:1603–1874  ·  view source on GitHub ↗
(
  appState: AppState | undefined,
  sessionId: string,
  hookEvent: HookEvent,
  hookInput: HookInput,
  tools?: Tools,
)

Source from the content-addressed store, hash-verified

1601 * @returns Array of matched hooks with optional plugin context
1602 */
1603export async function getMatchingHooks(
1604 appState: AppState | undefined,
1605 sessionId: string,
1606 hookEvent: HookEvent,
1607 hookInput: HookInput,
1608 tools?: Tools,
1609): Promise<MatchedHook[]> {
1610 try {
1611 const hookMatchers = getHooksConfig(appState, sessionId, hookEvent)
1612
1613 // If you change the criteria below, then you must change
1614 // src/utils/hooks/hooksConfigManager.ts as well.
1615 let matchQuery: string | undefined = undefined
1616 switch (hookInput.hook_event_name) {
1617 case 'PreToolUse':
1618 case 'PostToolUse':
1619 case 'PostToolUseFailure':
1620 case 'PermissionRequest':
1621 case 'PermissionDenied':
1622 matchQuery = hookInput.tool_name
1623 break
1624 case 'SessionStart':
1625 matchQuery = hookInput.source
1626 break
1627 case 'Setup':
1628 matchQuery = hookInput.trigger
1629 break
1630 case 'PreCompact':
1631 case 'PostCompact':
1632 matchQuery = hookInput.trigger
1633 break
1634 case 'Notification':
1635 matchQuery = hookInput.notification_type
1636 break
1637 case 'SessionEnd':
1638 matchQuery = hookInput.reason
1639 break
1640 case 'StopFailure':
1641 matchQuery = hookInput.error
1642 break
1643 case 'SubagentStart':
1644 matchQuery = hookInput.agent_type
1645 break
1646 case 'SubagentStop':
1647 matchQuery = hookInput.agent_type
1648 break
1649 case 'TeammateIdle':
1650 case 'TaskCreated':
1651 case 'TaskCompleted':
1652 break
1653 case 'Elicitation':
1654 matchQuery = hookInput.mcp_server_name
1655 break
1656 case 'ElicitationResult':
1657 matchQuery = hookInput.mcp_server_name
1658 break
1659 case 'ConfigChange':
1660 matchQuery = hookInput.source

Callers 2

executeHooksFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Calls 7

getHooksConfigFunction · 0.85
logForDebuggingFunction · 0.85
matchesPatternFunction · 0.85
hookDedupKeyFunction · 0.85
getIfConditionFunction · 0.85
valuesMethod · 0.80

Tested by

no test coverage detected