MCPcopy Create free account
hub / github.com/T-Lab-CUHKSZ/claude-code / startDeferredPrefetches

Function startDeferredPrefetches

src/main.tsx:401–444  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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