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