()
| 1454 | * (which don't hit the keychain), and only uses async for storage reads. |
| 1455 | */ |
| 1456 | export async function getClaudeAIOAuthTokensAsync(): Promise<OAuthTokens | null> { |
| 1457 | if (isBareMode()) return null |
| 1458 | |
| 1459 | // Env var and FD tokens are sync and don't hit the keychain |
| 1460 | if ( |
| 1461 | process.env.CLAUDE_CODE_OAUTH_TOKEN || |
| 1462 | getOAuthTokenFromFileDescriptor() |
| 1463 | ) { |
| 1464 | return getClaudeAIOAuthTokens() |
| 1465 | } |
| 1466 | |
| 1467 | try { |
| 1468 | const secureStorage = getSecureStorage() |
| 1469 | const storageData = await secureStorage.readAsync() |
| 1470 | const oauthData = storageData?.claudeAiOauth |
| 1471 | if (!oauthData?.accessToken) { |
| 1472 | return null |
| 1473 | } |
| 1474 | return oauthData |
| 1475 | } catch (error) { |
| 1476 | logError(error) |
| 1477 | return null |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | // In-flight promise for deduplicating concurrent calls |
| 1482 | let pendingRefreshCheck: Promise<boolean> | null = null |
no test coverage detected