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

Function processHookJSONOutput

src/utils/hooks.ts:568–819  ·  view source on GitHub ↗
({
  json: rawJson,
  command,
  hookName,
  toolUseID,
  hookEvent,
  expectedHookEvent,
  stdout,
  stderr,
  exitCode,
  durationMs,
}: {
  json: SyncHookJSONOutput
  command: string
  hookName: string
  toolUseID: string
  hookEvent: HookEvent
  expectedHookEvent?: HookEvent
  stdout?: string
  stderr?: string
  exitCode?: number
  durationMs?: number
})

Source from the content-addressed store, hash-verified

566}
567
568function processHookJSONOutput({
569 json: rawJson,
570 command,
571 hookName,
572 toolUseID,
573 hookEvent,
574 expectedHookEvent,
575 stdout,
576 stderr,
577 exitCode,
578 durationMs,
579}: {
580 json: SyncHookJSONOutput
581 command: string
582 hookName: string
583 toolUseID: string
584 hookEvent: HookEvent
585 expectedHookEvent?: HookEvent
586 stdout?: string
587 stderr?: string
588 exitCode?: number
589 durationMs?: number
590}): Partial<HookResult> {
591 const result: Partial<HookResult> = {}
592
593 // Cast to typed interface for type-safe property access
594 const json = rawJson as TypedSyncHookOutput
595
596 // At this point we know it's a sync response
597 const syncJson = json
598
599 // Handle common elements
600 if (syncJson.continue === false) {
601 result.preventContinuation = true
602 if (syncJson.stopReason) {
603 result.stopReason = syncJson.stopReason
604 }
605 }
606
607 if (json.decision) {
608 switch (json.decision) {
609 case 'approve':
610 result.permissionBehavior = 'allow'
611 break
612 case 'block':
613 result.permissionBehavior = 'deny'
614 result.blockingError = {
615 blockingError: json.reason || 'Blocked by hook',
616 command,
617 }
618 break
619 default:
620 // Handle unknown decision types as errors
621 throw new Error(
622 `Unknown hook decision type: ${json.decision}. Valid types are: approve, block`,
623 )
624 }
625 }

Callers 2

executeHooksFunction · 0.85
executeHookCallbackFunction · 0.85

Calls 2

jsonStringifyFunction · 0.85
createAttachmentMessageFunction · 0.85

Tested by

no test coverage detected