On this page
Manages Claude OAuth credentials including token refresh, macOS Keychain fallback, atomic file writes, and subscription tier detection.
#internal/oauth
#internal/oauth
#OAuthClientID
const OAuthClientID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"#Credentials
type Credentials structCredentials holds the minimal token set needed for OAuth operations.
#OAuthData
type OAuthData structOAuthData represents the claudeAiOauth section of the credentials file.
#CredFile
type CredFile structCredFile represents the full .credentials.json structure. RawFields preserves unknown top-level keys for round-trip fidelity.
#AuthInfo
type AuthInfo structAuthInfo describes the authentication method and subscription tier.
#ReadCredentialsFile
func ReadCredentialsFile(claudeDir string) *CredFileReadCredentialsFile reads and parses
#ReadKeychainCredentials
func ReadKeychainCredentials(claudeDir string) *OAuthDataReadKeychainCredentials reads OAuth credentials from the macOS Keychain. Returns nil on non-macOS platforms or any error.
#GetAuthInfo
func GetAuthInfo(oauth *OAuthData) AuthInfoGetAuthInfo determines auth type and subscription display name from OAuth data.
#ResetCredentialsCache
func ResetCredentialsCache()ResetCredentialsCache clears the per-process credentials cache.
#RefreshToken
func RefreshToken(claudeDir string, credFile *CredFile, oauth *OAuthData) errorRefreshToken refreshes an expired OAuth token and writes updated credentials back to
#GetValidToken
func GetValidToken(claudeDir string) (string, error)GetValidToken returns a valid access token, refreshing if expired. Falls back to Keychain on macOS if refresh fails.
#WriteFileAtomic
func WriteFileAtomic(path string, data []byte) errorWriteFileAtomic writes data to a temporary file in the same directory as path, then renames it atomically. This ensures readers see either the complete old or complete new file.
#CredFile.UnmarshalJSON
func (c *CredFile) UnmarshalJSON(data []byte) error#CredFile.MarshalJSON
func (c *CredFile) MarshalJSON() ([]byte, error)