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

Function handleSpawn

source code/tools/shared/spawnMultiAgent.ts:1042–1080  ·  view source on GitHub ↗

* Handle spawn operation - creates a new Claude Code instance. * Uses in-process mode when enabled, otherwise uses tmux/iTerm2 split-pane view. * Falls back to in-process if pane backend detection fails (e.g., iTerm2 without * it2 CLI or tmux installed).

(
  input: SpawnInput,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

1040 * it2 CLI or tmux installed).
1041 */
1042async function handleSpawn(
1043 input: SpawnInput,
1044 context: ToolUseContext,
1045): Promise<{ data: SpawnOutput }> {
1046 // Check if in-process mode is enabled via feature flag
1047 if (isInProcessEnabled()) {
1048 return handleSpawnInProcess(input, context)
1049 }
1050
1051 // Pre-flight: ensure a pane backend is available before attempting pane-based spawn.
1052 // This handles auto-mode cases like iTerm2 without it2 or tmux installed, where
1053 // isInProcessEnabled() returns false but detectAndGetBackend() has no viable backend.
1054 // Narrowly scoped so user cancellation and other spawn errors propagate normally.
1055 try {
1056 await detectAndGetBackend()
1057 } catch (error) {
1058 // Only fall back silently in auto mode. If the user explicitly configured
1059 // teammateMode: 'tmux', let the error propagate so they see the actionable
1060 // install instructions from getTmuxInstallInstructions().
1061 if (getTeammateModeFromSnapshot() !== 'auto') {
1062 throw error
1063 }
1064 logForDebugging(
1065 `[handleSpawn] No pane backend available, falling back to in-process: ${errorMessage(error)}`,
1066 )
1067 // Record the fallback so isInProcessEnabled() reflects the actual mode
1068 // (fixes banner and other UI that would otherwise show tmux attach commands).
1069 markInProcessFallback()
1070 return handleSpawnInProcess(input, context)
1071 }
1072
1073 // Backend is available (and now cached) - proceed with pane spawning.
1074 // Any errors here (user cancellation, validation, etc.) propagate to the caller.
1075 const useSplitPane = input.use_splitpane !== false
1076 if (useSplitPane) {
1077 return handleSpawnSplitPane(input, context)
1078 }
1079 return handleSpawnSeparateWindow(input, context)
1080}
1081
1082// ============================================================================
1083// Main Export

Callers 1

spawnTeammateFunction · 0.85

Calls 9

isInProcessEnabledFunction · 0.85
handleSpawnInProcessFunction · 0.85
detectAndGetBackendFunction · 0.85
logForDebuggingFunction · 0.85
markInProcessFallbackFunction · 0.85
handleSpawnSplitPaneFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected