MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / executeSessionEndHooks

Function executeSessionEndHooks

source code/utils/hooks.ts:4099–4143  ·  view source on GitHub ↗
(
  reason: ExitReason,
  options?: {
    getAppState?: () => AppState
    setAppState?: (updater: (prev: AppState) => AppState) => void
    signal?: AbortSignal
    timeoutMs?: number
  },
)

Source from the content-addressed store, hash-verified

4097 * @returns Promise that resolves when all hooks complete
4098 */
4099export async function executeSessionEndHooks(
4100 reason: ExitReason,
4101 options?: {
4102 getAppState?: () => AppState
4103 setAppState?: (updater: (prev: AppState) => AppState) => void
4104 signal?: AbortSignal
4105 timeoutMs?: number
4106 },
4107): Promise<void> {
4108 const {
4109 getAppState,
4110 setAppState,
4111 signal,
4112 timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
4113 } = options || {}
4114
4115 const hookInput: SessionEndHookInput = {
4116 ...createBaseHookInput(undefined),
4117 hook_event_name: 'SessionEnd',
4118 reason,
4119 }
4120
4121 const results = await executeHooksOutsideREPL({
4122 getAppState,
4123 hookInput,
4124 matchQuery: reason,
4125 signal,
4126 timeoutMs,
4127 })
4128
4129 // During shutdown, Ink is unmounted so we can write directly to stderr
4130 for (const result of results) {
4131 if (!result.succeeded && result.output) {
4132 process.stderr.write(
4133 `SessionEnd hook [${result.command}] failed: ${result.output}\n`,
4134 )
4135 }
4136 }
4137
4138 // Clear session hooks after execution
4139 if (setAppState) {
4140 const sessionId = getSessionId()
4141 clearSessionHooks(setAppState, sessionId)
4142 }
4143}
4144
4145/**
4146 * Execute permission request hooks if configured

Callers 3

gracefulShutdownFunction · 0.85
clearConversationFunction · 0.85
REPLFunction · 0.85

Calls 5

createBaseHookInputFunction · 0.85
executeHooksOutsideREPLFunction · 0.85
getSessionIdFunction · 0.85
clearSessionHooksFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected