MCPcopy Create free account
hub / github.com/WJX20/claude-code / executeHookCallback

Function executeHookCallback

src/utils/hooks.ts:4939–4995  ·  view source on GitHub ↗
({
  toolUseID,
  hook,
  hookEvent,
  hookInput,
  signal,
  hookIndex,
  toolUseContext,
}: {
  toolUseID: string
  hook: HookCallback
  hookEvent: HookEvent
  hookInput: HookInput
  signal: AbortSignal
  hookIndex?: number
  toolUseContext?: ToolUseContext
})

Source from the content-addressed store, hash-verified

4937}
4938
4939async function executeHookCallback({
4940 toolUseID,
4941 hook,
4942 hookEvent,
4943 hookInput,
4944 signal,
4945 hookIndex,
4946 toolUseContext,
4947}: {
4948 toolUseID: string
4949 hook: HookCallback
4950 hookEvent: HookEvent
4951 hookInput: HookInput
4952 signal: AbortSignal
4953 hookIndex?: number
4954 toolUseContext?: ToolUseContext
4955}): Promise<HookResult> {
4956 // Create context for callbacks that need state access
4957 const context = toolUseContext
4958 ? {
4959 getAppState: toolUseContext.getAppState,
4960 updateAttributionState: toolUseContext.updateAttributionState,
4961 }
4962 : undefined
4963 const json = await hook.callback(
4964 hookInput,
4965 toolUseID,
4966 signal,
4967 hookIndex,
4968 context,
4969 )
4970 if (isAsyncHookJSONOutput(json)) {
4971 return {
4972 outcome: 'success',
4973 hook,
4974 }
4975 }
4976
4977 const processed = processHookJSONOutput({
4978 json,
4979 command: 'callback',
4980 // TODO: If the hook came from a plugin, use the full path to the plugin for easier debugging
4981 hookName: `${hookEvent}:Callback`,
4982 toolUseID,
4983 hookEvent,
4984 expectedHookEvent: hookEvent,
4985 // Callbacks don't have stdout/stderr/exitCode
4986 stdout: undefined,
4987 stderr: undefined,
4988 exitCode: undefined,
4989 })
4990 return {
4991 ...processed,
4992 outcome: 'success',
4993 hook,
4994 }
4995}
4996

Callers 1

executeHooksFunction · 0.85

Calls 2

isAsyncHookJSONOutputFunction · 0.85
processHookJSONOutputFunction · 0.85

Tested by

no test coverage detected