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

Function processSessionStartHooks

source code/utils/sessionStart.ts:37–177  ·  view source on GitHub ↗
(
  source: 'startup' | 'resume' | 'clear' | 'compact',
  {
    sessionId,
    agentType,
    model,
    forceSyncExecution,
  }: SessionStartHooksOptions = {},
)

Source from the content-addressed store, hash-verified

35
36// Note to CLAUDE: do not add ANY "warmup" logic. It is **CRITICAL** that you do not add extra work on startup.
37export async function processSessionStartHooks(
38 source: 'startup' | 'resume' | 'clear' | 'compact',
39 {
40 sessionId,
41 agentType,
42 model,
43 forceSyncExecution,
44 }: SessionStartHooksOptions = {},
45): Promise<HookResultMessage[]> {
46 // --bare skips all hooks. executeHooks already early-returns under --bare
47 // (hooks.ts:1861), but this skips the loadPluginHooks() await below too —
48 // no point loading plugin hooks that'll never run.
49 if (isBareMode()) {
50 return []
51 }
52 const hookMessages: HookResultMessage[] = []
53 const additionalContexts: string[] = []
54 const allWatchPaths: string[] = []
55
56 // Skip loading plugin hooks if restricted to managed hooks only
57 // Plugin hooks are untrusted external code that should be blocked by policy
58 if (shouldAllowManagedHooksOnly()) {
59 logForDebugging('Skipping plugin hooks - allowManagedHooksOnly is enabled')
60 } else {
61 // Ensure plugin hooks are loaded before executing SessionStart hooks.
62 // loadPluginHooks() may be called early during startup (fire-and-forget, non-blocking)
63 // to pre-load hooks, but we must guarantee hooks are registered before executing them.
64 // This function is memoized, so if hooks are already loaded, this returns immediately
65 // with negligible overhead (just a cache lookup).
66 try {
67 await withDiagnosticsTiming('load_plugin_hooks', () => loadPluginHooks())
68 } catch (error) {
69 // Log error but don't crash - continue with session start without plugin hooks
70 /* eslint-disable no-restricted-syntax -- both branches wrap with context, not a toError case */
71 const enhancedError =
72 error instanceof Error
73 ? new Error(
74 `Failed to load plugin hooks during ${source}: ${error.message}`,
75 )
76 : new Error(
77 `Failed to load plugin hooks during ${source}: ${String(error)}`,
78 )
79 /* eslint-enable no-restricted-syntax */
80
81 if (error instanceof Error && error.stack) {
82 enhancedError.stack = error.stack
83 }
84
85 logError(enhancedError)
86
87 // Provide specific guidance based on error type
88 const errorMessage =
89 error instanceof Error ? error.message : String(error)
90 let userGuidance = ''
91
92 if (
93 errorMessage.includes('Failed to clone') ||
94 errorMessage.includes('network') ||

Callers 8

runFunction · 0.85
clearConversationFunction · 0.85
REPLFunction · 0.85
loadInitialMessagesFunction · 0.85
compactConversationFunction · 0.85

Calls 10

isBareModeFunction · 0.85
logForDebuggingFunction · 0.85
withDiagnosticsTimingFunction · 0.85
loadPluginHooksFunction · 0.85
getMainThreadAgentTypeFunction · 0.85
executeSessionStartHooksFunction · 0.85
updateWatchPathsFunction · 0.85
createAttachmentMessageFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected