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

Function startDeferredPrefetches

src/main.tsx:388–431  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

386 * Call this after the REPL has been rendered.
387 */
388export function startDeferredPrefetches(): void {
389 // This function runs after first render, so it doesn't block the initial paint.
390 // However, the spawned processes and async work still contend for CPU and event
391 // loop time, which skews startup benchmarks (CPU profiles, time-to-first-render
392 // measurements). Skip all of it when we're only measuring startup performance.
393 if (isEnvTruthy(process.env.CLAUDE_CODE_EXIT_AFTER_FIRST_RENDER) ||
394 // --bare: skip ALL prefetches. These are cache-warms for the REPL's
395 // first-turn responsiveness (initUser, getUserContext, tips, countFiles,
396 // modelCapabilities, change detectors). Scripted -p calls don't have a
397 // "user is typing" window to hide this work in — it's pure overhead on
398 // the critical path.
399 isBareMode()) {
400 return;
401 }
402
403 // Process-spawning prefetches (consumed at first API call, user is still typing)
404 void initUser();
405 void getUserContext();
406 prefetchSystemContextIfSafe();
407 void getRelevantTips();
408 if (isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK) && !isEnvTruthy(process.env.CLAUDE_CODE_SKIP_BEDROCK_AUTH)) {
409 void prefetchAwsCredentialsAndBedRockInfoIfSafe();
410 }
411 if (isEnvTruthy(process.env.CLAUDE_CODE_USE_VERTEX) && !isEnvTruthy(process.env.CLAUDE_CODE_SKIP_VERTEX_AUTH)) {
412 void prefetchGcpCredentialsIfSafe();
413 }
414 void countFilesRoundedRg(getCwd(), AbortSignal.timeout(3000), []);
415
416 // Analytics and feature flag initialization
417 void initializeAnalyticsGates();
418 void prefetchOfficialMcpUrls();
419 void refreshModelCapabilities();
420
421 // File change detectors deferred from init() to unblock first render
422 void settingsChangeDetector.initialize();
423 if (!isBareMode()) {
424 void skillChangeDetector.initialize();
425 }
426
427 // Event loop stall detector — logs when the main thread is blocked >500ms
428 if ("external" === 'ant') {
429 void import('./utils/eventLoopStallDetector.js').then(m => m.startEventLoopStallDetector());
430 }
431}
432function loadSettingsFromFlag(settingsFile: string): void {
433 try {
434 const trimmedSettings = settingsFile.trim();

Callers 2

renderAndRunFunction · 0.85
runFunction · 0.85

Calls 12

isEnvTruthyFunction · 0.85
isBareModeFunction · 0.85
initUserFunction · 0.85
getRelevantTipsFunction · 0.85
getCwdFunction · 0.85
initializeAnalyticsGatesFunction · 0.85
prefetchOfficialMcpUrlsFunction · 0.85
refreshModelCapabilitiesFunction · 0.85
initializeMethod · 0.65

Tested by

no test coverage detected