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

Function processHookJSONOutput

src/utils/hooks.ts:489–737  ·  view source on GitHub ↗
({
  json,
  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

487}
488
489function processHookJSONOutput({
490 json,
491 command,
492 hookName,
493 toolUseID,
494 hookEvent,
495 expectedHookEvent,
496 stdout,
497 stderr,
498 exitCode,
499 durationMs,
500}: {
501 json: SyncHookJSONOutput
502 command: string
503 hookName: string
504 toolUseID: string
505 hookEvent: HookEvent
506 expectedHookEvent?: HookEvent
507 stdout?: string
508 stderr?: string
509 exitCode?: number
510 durationMs?: number
511}): Partial<HookResult> {
512 const result: Partial<HookResult> = {}
513
514 // At this point we know it's a sync response
515 const syncJson = json
516
517 // Handle common elements
518 if (syncJson.continue === false) {
519 result.preventContinuation = true
520 if (syncJson.stopReason) {
521 result.stopReason = syncJson.stopReason
522 }
523 }
524
525 if (json.decision) {
526 switch (json.decision) {
527 case 'approve':
528 result.permissionBehavior = 'allow'
529 break
530 case 'block':
531 result.permissionBehavior = 'deny'
532 result.blockingError = {
533 blockingError: json.reason || 'Blocked by hook',
534 command,
535 }
536 break
537 default:
538 // Handle unknown decision types as errors
539 throw new Error(
540 `Unknown hook decision type: ${json.decision}. Valid types are: approve, block`,
541 )
542 }
543 }
544
545 // Handle systemMessage field
546 if (json.systemMessage) {

Callers 2

executeHooksFunction · 0.85
executeHookCallbackFunction · 0.85

Calls 2

jsonStringifyFunction · 0.85
createAttachmentMessageFunction · 0.85

Tested by

no test coverage detected