MCPcopy Create free account
hub / github.com/WJX20/claude-code / executeWorktreeCreateHook

Function executeWorktreeCreateHook

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

Source from the content-addressed store, hash-verified

5025 * Callers should check hasWorktreeCreateHook() before calling this.
5026 */
5027export async function executeWorktreeCreateHook(
5028 name: string,
5029): Promise<{ worktreePath: string }> {
5030 const hookInput = {
5031 ...createBaseHookInput(undefined),
5032 hook_event_name: 'WorktreeCreate' as const,
5033 name,
5034 }
5035
5036 const results = await executeHooksOutsideREPL({
5037 hookInput,
5038 timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS,
5039 })
5040
5041 // Find the first successful result with non-empty output
5042 const successfulResult = results.find(
5043 r => r.succeeded && r.output.trim().length > 0,
5044 )
5045
5046 if (!successfulResult) {
5047 const failedOutputs = results
5048 .filter(r => !r.succeeded)
5049 .map(r => `${r.command}: ${r.output.trim() || 'no output'}`)
5050 throw new Error(
5051 `WorktreeCreate hook failed: ${failedOutputs.join('; ') || 'no successful output'}`,
5052 )
5053 }
5054
5055 const worktreePath = successfulResult.output.trim()
5056 return { worktreePath }
5057}
5058
5059/**
5060 * 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