MCPcopy
hub / github.com/codeaashu/claude-code / processSetupHooks

Function processSetupHooks

src/utils/sessionStart.ts:177–232  ·  view source on GitHub ↗
(
  trigger: 'init' | 'maintenance',
  { forceSyncExecution }: { forceSyncExecution?: boolean } = {},
)

Source from the content-addressed store, hash-verified

175}
176
177export async function processSetupHooks(
178 trigger: 'init' | 'maintenance',
179 { forceSyncExecution }: { forceSyncExecution?: boolean } = {},
180): Promise<HookResultMessage[]> {
181 // Same rationale as processSessionStartHooks above.
182 if (isBareMode()) {
183 return []
184 }
185 const hookMessages: HookResultMessage[] = []
186 const additionalContexts: string[] = []
187
188 if (shouldAllowManagedHooksOnly()) {
189 logForDebugging('Skipping plugin hooks - allowManagedHooksOnly is enabled')
190 } else {
191 try {
192 await loadPluginHooks()
193 } catch (error) {
194 const errorMessage =
195 error instanceof Error ? error.message : String(error)
196 logForDebugging(
197 `Warning: Failed to load plugin hooks. Setup hooks from plugins will not execute. Error: ${errorMessage}`,
198 { level: 'warn' },
199 )
200 }
201 }
202
203 for await (const hookResult of executeSetupHooks(
204 trigger,
205 undefined,
206 undefined,
207 forceSyncExecution,
208 )) {
209 if (hookResult.message) {
210 hookMessages.push(hookResult.message)
211 }
212 if (
213 hookResult.additionalContexts &&
214 hookResult.additionalContexts.length > 0
215 ) {
216 additionalContexts.push(...hookResult.additionalContexts)
217 }
218 }
219
220 if (additionalContexts.length > 0) {
221 const contextMessage = createAttachmentMessage({
222 type: 'hook_additional_context',
223 content: additionalContexts,
224 hookName: 'Setup',
225 toolUseID: 'Setup',
226 hookEvent: 'Setup',
227 })
228 hookMessages.push(contextMessage)
229 }
230
231 return hookMessages
232}
233

Callers 2

runFunction · 0.85
runHeadlessFunction · 0.85

Calls 7

isBareModeFunction · 0.85
logForDebuggingFunction · 0.85
loadPluginHooksFunction · 0.85
executeSetupHooksFunction · 0.85
createAttachmentMessageFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected