()
| 533 | * Call this after the REPL has been rendered. |
| 534 | */ |
| 535 | export function startDeferredPrefetches(): void { |
| 536 | // This function runs after first render, so it doesn't block the initial paint. |
| 537 | // However, the spawned processes and async work still contend for CPU and event |
| 538 | // loop time, which skews startup benchmarks (CPU profiles, time-to-first-render |
| 539 | // measurements). Skip all of it when we're only measuring startup performance. |
| 540 | if ( |
| 541 | isEnvTruthy(process.env.CLAUDE_CODE_EXIT_AFTER_FIRST_RENDER) || |
| 542 | // --bare: skip ALL prefetches. These are cache-warms for the REPL's |
| 543 | // first-turn responsiveness (initUser, getUserContext, tips, countFiles, |
| 544 | // modelCapabilities, change detectors). Scripted -p calls don't have a |
| 545 | // "user is typing" window to hide this work in — it's pure overhead on |
| 546 | // the critical path. |
| 547 | isBareMode() |
| 548 | ) { |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | // Process-spawning prefetches (consumed at first API call, user is still typing) |
| 553 | void initUser(); |
| 554 | void getUserContext(); |
| 555 | prefetchSystemContextIfSafe(); |
| 556 | void getRelevantTips(); |
| 557 | if (isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK) && !isEnvTruthy(process.env.CLAUDE_CODE_SKIP_BEDROCK_AUTH)) { |
| 558 | void prefetchAwsCredentialsAndBedRockInfoIfSafe(); |
| 559 | } |
| 560 | if (isEnvTruthy(process.env.CLAUDE_CODE_USE_VERTEX) && !isEnvTruthy(process.env.CLAUDE_CODE_SKIP_VERTEX_AUTH)) { |
| 561 | void prefetchGcpCredentialsIfSafe(); |
| 562 | } |
| 563 | void countFilesRoundedRg(getCwd(), AbortSignal.timeout(3000), []); |
| 564 | |
| 565 | // Analytics and feature flag initialization |
| 566 | void initializeAnalyticsGates(); |
| 567 | |
| 568 | void refreshModelCapabilities(); |
| 569 | |
| 570 | // File change detectors deferred from init() to unblock first render |
| 571 | void settingsChangeDetector.initialize(); |
| 572 | if (!isBareMode()) { |
| 573 | void skillChangeDetector.initialize(); |
| 574 | } |
| 575 | |
| 576 | // Event loop stall detector — logs when the main thread is blocked >500ms |
| 577 | if (process.env.USER_TYPE === 'ant') { |
| 578 | void import('./utils/eventLoopStallDetector.js').then(m => m.startEventLoopStallDetector()); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | function loadSettingsFromFlag(settingsFile: string): void { |
| 583 | try { |
no test coverage detected