MCPcopy Create free account
hub / github.com/oboard/claude-code-rev / handleInitializeRequest

Function handleInitializeRequest

src/cli/print.ts:4341–4523  ·  view source on GitHub ↗
(
  request: SDKControlInitializeRequest,
  requestId: string,
  initialized: boolean,
  output: Stream<StdoutMessage>,
  commands: Command[],
  modelInfos: ModelInfo[],
  structuredIO: StructuredIO,
  enableAuthStatus: boolean,
  options: {
    systemPrompt: string | undefined
    appendSystemPrompt: string | undefined
    agent?: string | undefined
    userSpecifiedModel?: string | undefined
    [key: string]: unknown
  },
  agents: AgentDefinition[],
  getAppState: () => AppState,
)

Source from the content-addressed store, hash-verified

4339}
4340
4341async function handleInitializeRequest(
4342 request: SDKControlInitializeRequest,
4343 requestId: string,
4344 initialized: boolean,
4345 output: Stream<StdoutMessage>,
4346 commands: Command[],
4347 modelInfos: ModelInfo[],
4348 structuredIO: StructuredIO,
4349 enableAuthStatus: boolean,
4350 options: {
4351 systemPrompt: string | undefined
4352 appendSystemPrompt: string | undefined
4353 agent?: string | undefined
4354 userSpecifiedModel?: string | undefined
4355 [key: string]: unknown
4356 },
4357 agents: AgentDefinition[],
4358 getAppState: () => AppState,
4359): Promise<void> {
4360 if (initialized) {
4361 output.enqueue({
4362 type: 'control_response',
4363 response: {
4364 subtype: 'error',
4365 error: 'Already initialized',
4366 request_id: requestId,
4367 pending_permission_requests:
4368 structuredIO.getPendingPermissionRequests(),
4369 },
4370 })
4371 return
4372 }
4373
4374 // Apply systemPrompt/appendSystemPrompt from stdin to avoid ARG_MAX limits
4375 if (request.systemPrompt !== undefined) {
4376 options.systemPrompt = request.systemPrompt
4377 }
4378 if (request.appendSystemPrompt !== undefined) {
4379 options.appendSystemPrompt = request.appendSystemPrompt
4380 }
4381 if (request.promptSuggestions !== undefined) {
4382 options.promptSuggestions = request.promptSuggestions
4383 }
4384
4385 // Merge agents from stdin to avoid ARG_MAX limits
4386 if (request.agents) {
4387 const stdinAgents = parseAgentsFromJson(request.agents, 'flagSettings')
4388 agents.push(...stdinAgents)
4389 }
4390
4391 // Re-evaluate main thread agent after SDK agents are merged
4392 // This allows --agent to reference agents defined via SDK
4393 if (options.agent) {
4394 // If main.tsx already found this agent (filesystem-defined), it already
4395 // applied systemPrompt/model/initialPrompt. Skip to avoid double-apply.
4396 const alreadyResolved = getMainThreadAgentType() === options.agent
4397 const mainThreadAgent = agents.find(a => a.agentType === options.agent)
4398 if (mainThreadAgent && !alreadyResolved) {

Callers 1

runHeadlessStreamingFunction · 0.85

Calls 15

parseAgentsFromJsonFunction · 0.85
getMainThreadAgentTypeFunction · 0.85
setMainThreadAgentTypeFunction · 0.85
isBuiltInAgentFunction · 0.85
parseUserSpecifiedModelFunction · 0.85
setMainLoopModelOverrideFunction · 0.85
getCwdFunction · 0.85
getAccountInformationFunction · 0.85
registerHookCallbacksFunction · 0.85
setInitJsonSchemaFunction · 0.85
getAPIProviderFunction · 0.85

Tested by

no test coverage detected