MCPcopy Create free account
hub / github.com/codeaashu/claude-code / registerSkillHooks

Function registerSkillHooks

src/utils/hooks/registerSkillHooks.ts:20–64  ·  view source on GitHub ↗
(
  setAppState: (updater: (prev: AppState) => AppState) => void,
  sessionId: string,
  hooks: HooksSettings,
  skillName: string,
  skillRoot?: string,
)

Source from the content-addressed store, hash-verified

18 * @param skillRoot - The base directory of the skill (for CLAUDE_PLUGIN_ROOT env var)
19 */
20export function registerSkillHooks(
21 setAppState: (updater: (prev: AppState) => AppState) => void,
22 sessionId: string,
23 hooks: HooksSettings,
24 skillName: string,
25 skillRoot?: string,
26): void {
27 let registeredCount = 0
28
29 for (const eventName of HOOK_EVENTS) {
30 const matchers = hooks[eventName]
31 if (!matchers) continue
32
33 for (const matcher of matchers) {
34 for (const hook of matcher.hooks) {
35 // For once: true hooks, use onHookSuccess callback to remove after execution
36 const onHookSuccess = hook.once
37 ? () => {
38 logForDebugging(
39 `Removing one-shot hook for event ${eventName} in skill '${skillName}'`,
40 )
41 removeSessionHook(setAppState, sessionId, eventName, hook)
42 }
43 : undefined
44
45 addSessionHook(
46 setAppState,
47 sessionId,
48 eventName,
49 matcher.matcher || '',
50 hook,
51 onHookSuccess,
52 skillRoot,
53 )
54 registeredCount++
55 }
56 }
57 }
58
59 if (registeredCount > 0) {
60 logForDebugging(
61 `Registered ${registeredCount} hooks from skill '${skillName}'`,
62 )
63 }
64}
65

Callers 1

Calls 3

logForDebuggingFunction · 0.85
removeSessionHookFunction · 0.85
addSessionHookFunction · 0.85

Tested by

no test coverage detected