MCPcopy
hub / github.com/claude-code-best/claude-code / prefetchFastModeStatus

Function prefetchFastModeStatus

src/utils/fastMode.ts:410–535  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

408}
409
410export async function prefetchFastModeStatus(): Promise<void> {
411 // Skip network requests if nonessential traffic is disabled
412 if (isEssentialTrafficOnly()) {
413 return
414 }
415
416 if (!isFastModeEnabled()) {
417 return
418 }
419
420 if (inflightPrefetch) {
421 logForDebugging(
422 'Fast mode prefetch in progress, returning in-flight promise',
423 )
424 return inflightPrefetch
425 }
426
427 // Service key OAuth sessions lack user:profile scope → endpoint 403s.
428 // Resolve orgStatus from cache and bail before burning the throttle window.
429 // API key auth is unaffected.
430 const apiKey = getAnthropicApiKey()
431 const hasUsableOAuth =
432 getClaudeAIOAuthTokens()?.accessToken && hasProfileScope()
433 if (!hasUsableOAuth && !apiKey) {
434 const isAnt = process.env.USER_TYPE === 'ant'
435 const cachedEnabled = getGlobalConfig().penguinModeOrgEnabled === true
436 orgStatus =
437 isAnt || cachedEnabled
438 ? { status: 'enabled' }
439 : { status: 'disabled', reason: 'preference' }
440 return
441 }
442
443 const now = Date.now()
444 if (now - lastPrefetchAt < PREFETCH_MIN_INTERVAL_MS) {
445 logForDebugging('Skipping fast mode prefetch, fetched recently')
446 return
447 }
448 lastPrefetchAt = now
449
450 const fetchWithCurrentAuth = async (): Promise<FastModeResponse> => {
451 const currentTokens = getClaudeAIOAuthTokens()
452 const auth =
453 currentTokens?.accessToken && hasProfileScope()
454 ? { accessToken: currentTokens.accessToken }
455 : apiKey
456 ? { apiKey }
457 : null
458 if (!auth) {
459 throw new Error('No auth available')
460 }
461 return fetchFastModeStatus(auth)
462 }
463
464 async function doFetch(): Promise<void> {
465 try {
466 let status: FastModeResponse
467 try {

Callers 2

runFunction · 0.85
callFunction · 0.85

Calls 8

isEssentialTrafficOnlyFunction · 0.85
isFastModeEnabledFunction · 0.85
getAnthropicApiKeyFunction · 0.85
getGlobalConfigFunction · 0.85
doFetchFunction · 0.85
nowMethod · 0.80
logForDebuggingFunction · 0.70
hasProfileScopeFunction · 0.70

Tested by

no test coverage detected