MCPcopy
hub / github.com/claude-code-best/claude-code / executeWorktreeCreateHook

Function executeWorktreeCreateHook

src/utils/hooks.ts:5096–5126  ·  view source on GitHub ↗
(
  name: string,
)

Source from the content-addressed store, hash-verified

5094 * Callers should check hasWorktreeCreateHook() before calling this.
5095 */
5096export async function executeWorktreeCreateHook(
5097 name: string,
5098): Promise<{ worktreePath: string }> {
5099 const hookInput = {
5100 ...createBaseHookInput(undefined),
5101 hook_event_name: 'WorktreeCreate' as const,
5102 name,
5103 }
5104
5105 const results = await executeHooksOutsideREPL({
5106 hookInput,
5107 timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS,
5108 })
5109
5110 // Find the first successful result with non-empty output
5111 const successfulResult = results.find(
5112 r => r.succeeded && r.output.trim().length > 0,
5113 )
5114
5115 if (!successfulResult) {
5116 const failedOutputs = results
5117 .filter(r => !r.succeeded)
5118 .map(r => `${r.command}: ${r.output.trim() || 'no output'}`)
5119 throw new Error(
5120 `WorktreeCreate hook failed: ${failedOutputs.join('; ') || 'no successful output'}`,
5121 )
5122 }
5123
5124 const worktreePath = successfulResult.output.trim()
5125 return { worktreePath }
5126}
5127
5128/**
5129 * Execute WorktreeRemove hooks if configured.

Callers 3

createWorktreeForSessionFunction · 0.85
createAgentWorktreeFunction · 0.85
execIntoTmuxWorktreeFunction · 0.85

Calls 2

createBaseHookInputFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Tested by

no test coverage detected