Expand description
OAuth credential resolution for the OAuth /api/oauth/usage
endpoint. Reads the access token from macOS Keychain (primary +
multi-account fallback) or from a file cascade
($CLAUDE_CONFIG_DIR, XDG, ~/.claude/).
Canonical spec: docs/specs/credentials.md.
Sensitivity contract. The token never appears in Debug or
[Display] output anywhere in this module. Credentials wraps
the token in secrecy::SecretString with manual Debug that
redacts it. CredentialError::ParseError carries a
serde_json::Error whose Display would include a snippet of the
source bytes — our Display impl prints only the path and line /
column, never the cause’s Display. std::error::Error::source
still chains to the raw cause so callers who opt in (with caution)
can inspect it.
Structs§
- Credentials
- Resolved OAuth credentials. Clone-on-Arc across segments; the
underlying
SecretStringis cheap to clone. - File
Cascade Env - Environmental inputs for the file-cascade portion of credential
resolution. macOS Keychain probes shell out to
securityand don’t depend on these fields, so only the file-cascade env vars live here. Treats empty string as unset percredentials.md§Edge cases.
Enums§
- Credential
Error - Failure modes for
resolve_credentials.DebugandDisplaydeliberately avoid forwardingserde_json::Error’s Display because its context snippet may include token bytes; the raw cause is still reachable viastd::error::Error::sourcefor callers who need it. - Credential
Source - Where
resolve_credentialsfound the token.
Functions§
- resolve_
credentials - Resolve the OAuth access token via the cascade in
docs/specs/credentials.md§Resolution cascade: macOS Keychain (primary + multi-account) on macOS, then file-based cascade on all platforms. Memoization for process-lifetime reuse is the caller’s responsibility; each invocation re-runs the full cascade. - resolve_
credentials_ with - Same cascade as
resolve_credentialsbut with an explicitFileCascadeEnv. Lets doctor and tests pin the file-cascade inputs without mutating process env, which is racy under Rust’s default parallel test execution.