()
| 1393 | * (which don't hit the keychain), and only uses async for storage reads. |
| 1394 | */ |
| 1395 | export async function getClaudeAIOAuthTokensAsync(): Promise<OAuthTokens | null> { |
| 1396 | if (isBareMode()) return null |
| 1397 | |
| 1398 | // Env var and FD tokens are sync and don't hit the keychain |
| 1399 | if ( |
| 1400 | process.env.CLAUDE_CODE_OAUTH_TOKEN || |
| 1401 | getOAuthTokenFromFileDescriptor() |
| 1402 | ) { |
| 1403 | return getClaudeAIOAuthTokens() |
| 1404 | } |
| 1405 | |
| 1406 | try { |
| 1407 | const secureStorage = getSecureStorage() |
| 1408 | const storageData = await secureStorage.readAsync() |
| 1409 | const oauthData = storageData?.claudeAiOauth |
| 1410 | if (!oauthData?.accessToken) { |
| 1411 | return null |
| 1412 | } |
| 1413 | return oauthData |
| 1414 | } catch (error) { |
| 1415 | logError(error) |
| 1416 | return null |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | // In-flight promise for deduplicating concurrent calls |
| 1421 | let pendingRefreshCheck: Promise<boolean> | null = null |
no test coverage detected