MCPcopy Index your code
hub / github.com/codeaashu/claude-code / spawn

Method spawn

src/utils/swarm/backends/InProcessBackend.ts:72–143  ·  view source on GitHub ↗

* Spawns an in-process teammate. * * Uses spawnInProcessTeammate() to: * 1. Create TeammateContext via createTeammateContext() * 2. Create independent AbortController (not linked to parent) * 3. Register teammate in AppState.tasks * 4. Start agent execution via startInProcessTeamma

(config: TeammateSpawnConfig)

Source from the content-addressed store, hash-verified

70 * 5. Return spawn result with agentId, taskId, abortController
71 */
72 async spawn(config: TeammateSpawnConfig): Promise<TeammateSpawnResult> {
73 if (!this.context) {
74 logForDebugging(
75 `[InProcessBackend] spawn() called without context for ${config.name}`,
76 )
77 return {
78 success: false,
79 agentId: `${config.name}@${config.teamName}`,
80 error:
81 'InProcessBackend not initialized. Call setContext() before spawn().',
82 }
83 }
84
85 logForDebugging(`[InProcessBackend] spawn() called for ${config.name}`)
86
87 const result = await spawnInProcessTeammate(
88 {
89 name: config.name,
90 teamName: config.teamName,
91 prompt: config.prompt,
92 color: config.color,
93 planModeRequired: config.planModeRequired ?? false,
94 },
95 this.context,
96 )
97
98 // If spawn succeeded, start the agent execution loop
99 if (
100 result.success &&
101 result.taskId &&
102 result.teammateContext &&
103 result.abortController
104 ) {
105 // Start the agent loop in the background (fire-and-forget)
106 // The prompt is passed through the task state and config
107 startInProcessTeammate({
108 identity: {
109 agentId: result.agentId,
110 agentName: config.name,
111 teamName: config.teamName,
112 color: config.color,
113 planModeRequired: config.planModeRequired ?? false,
114 parentSessionId: result.teammateContext.parentSessionId,
115 },
116 taskId: result.taskId,
117 prompt: config.prompt,
118 teammateContext: result.teammateContext,
119 // Strip messages: the teammate never reads toolUseContext.messages
120 // (runAgent overrides it via createSubagentContext). Passing the
121 // parent's conversation would pin it for the teammate's lifetime.
122 toolUseContext: { ...this.context, messages: [] },
123 abortController: result.abortController,
124 model: config.model,
125 systemPrompt: config.systemPrompt,
126 systemPromptMode: config.systemPromptMode,
127 allowedTools: config.permissions,
128 allowPermissionPrompts: config.allowPermissionPrompts,
129 })

Callers 2

ripgrep.tsFile · 0.45
safeSpawnFunction · 0.45

Calls 3

logForDebuggingFunction · 0.85
spawnInProcessTeammateFunction · 0.85
startInProcessTeammateFunction · 0.85

Tested by

no test coverage detected