MCPcopy
hub / github.com/codeaashu/claude-code / runHeadless

Function runHeadless

src/cli/print.ts:455–974  ·  view source on GitHub ↗
(
  inputPrompt: string | AsyncIterable<string>,
  getAppState: () => AppState,
  setAppState: (f: (prev: AppState) => AppState) => void,
  commands: Command[],
  tools: Tools,
  sdkMcpConfigs: Record<string, McpSdkServerConfig>,
  agents: AgentDefinition[],
  options: {
    continue: boolean | undefined
    resume: string | boolean | undefined
    resumeSessionAt: string | undefined
    verbose: boolean | undefined
    outputFormat: string | undefined
    jsonSchema: Record<string, unknown> | undefined
    permissionPromptToolName: string | undefined
    allowedTools: string[] | undefined
    thinkingConfig: ThinkingConfig | undefined
    maxTurns: number | undefined
    maxBudgetUsd: number | undefined
    taskBudget: { total: number } | undefined
    systemPrompt: string | undefined
    appendSystemPrompt: string | undefined
    userSpecifiedModel: string | undefined
    fallbackModel: string | undefined
    teleport: string | true | null | undefined
    sdkUrl: string | undefined
    replayUserMessages: boolean | undefined
    includePartialMessages: boolean | undefined
    forkSession: boolean | undefined
    rewindFiles: string | undefined
    enableAuthStatus: boolean | undefined
    agent: string | undefined
    workload: string | undefined
    setupTrigger?: 'init' | 'maintenance' | undefined
    sessionStartHooksPromise?: ReturnType<typeof processSessionStartHooks>
    setSDKStatus?: (status: SDKStatus) => void
  },
)

Source from the content-addressed store, hash-verified

453}
454
455export async function runHeadless(
456 inputPrompt: string | AsyncIterable<string>,
457 getAppState: () => AppState,
458 setAppState: (f: (prev: AppState) => AppState) => void,
459 commands: Command[],
460 tools: Tools,
461 sdkMcpConfigs: Record<string, McpSdkServerConfig>,
462 agents: AgentDefinition[],
463 options: {
464 continue: boolean | undefined
465 resume: string | boolean | undefined
466 resumeSessionAt: string | undefined
467 verbose: boolean | undefined
468 outputFormat: string | undefined
469 jsonSchema: Record<string, unknown> | undefined
470 permissionPromptToolName: string | undefined
471 allowedTools: string[] | undefined
472 thinkingConfig: ThinkingConfig | undefined
473 maxTurns: number | undefined
474 maxBudgetUsd: number | undefined
475 taskBudget: { total: number } | undefined
476 systemPrompt: string | undefined
477 appendSystemPrompt: string | undefined
478 userSpecifiedModel: string | undefined
479 fallbackModel: string | undefined
480 teleport: string | true | null | undefined
481 sdkUrl: string | undefined
482 replayUserMessages: boolean | undefined
483 includePartialMessages: boolean | undefined
484 forkSession: boolean | undefined
485 rewindFiles: string | undefined
486 enableAuthStatus: boolean | undefined
487 agent: string | undefined
488 workload: string | undefined
489 setupTrigger?: 'init' | 'maintenance' | undefined
490 sessionStartHooksPromise?: ReturnType<typeof processSessionStartHooks>
491 setSDKStatus?: (status: SDKStatus) => void
492 },
493): Promise<void> {
494 if (
495 process.env.USER_TYPE === 'ant' &&
496 isEnvTruthy(process.env.CLAUDE_CODE_EXIT_AFTER_FIRST_RENDER)
497 ) {
498 process.stderr.write(
499 `\nStartup time: ${Math.round(process.uptime() * 1000)}ms\n`,
500 )
501 // eslint-disable-next-line custom-rules/no-process-exit
502 process.exit(0)
503 }
504
505 // Fire user settings download now so it overlaps with the MCP/tool setup
506 // below. Managed settings already started in main.tsx preAction; this gives
507 // user settings a similar head start. The cached promise is joined in
508 // installPluginsAndApplyMcpInBackground before plugin install reads
509 // enabledPlugins.
510 if (
511 feature('DOWNLOAD_USER_SETTINGS') &&
512 (isEnvTruthy(process.env.CLAUDE_CODE_REMOTE) || getIsRemoteMode())

Callers 1

runFunction · 0.85

Calls 15

isEnvTruthyFunction · 0.85
featureFunction · 0.85
getIsRemoteModeFunction · 0.85
downloadUserSettingsFunction · 0.85
applySettingsChangeFunction · 0.85
isFastModeEnabledFunction · 0.85
isQualifiedForGroveFunction · 0.85
gracefulShutdownSyncFunction · 0.85
getStructuredIOFunction · 0.85

Tested by

no test coverage detected