Documentation
¶
Overview ¶
Package identity resolves an OAuth token to the account it belongs to and classifies that account.
One call to GET /api/oauth/profile answers both questions at once: it carries the email that labels the account AND the organization fields that decide whether the account is subscription-billed or credit-billed.
Index ¶
- Variables
- func APIKeyApproval(key string) string
- func AuthEnvironmentVars() []string
- func HostAPIKeyFilePresent() bool
- func PrimaryByDefault(p *Profile) bool
- func TruthyEnv(v string) bool
- type APIKeyEnvironment
- type APIKeySource
- type AntProfile
- type Client
- type HostContext
- type Kind
- type Login
- type OAuthEnvironment
- type OAuthSource
- type Profile
- type StatusError
- type UsageShape
Constants ¶
This section is empty.
Variables ¶
var ( HostOAuthTokenFile = "/home/claude/.claude/remote/.oauth_token" HostAPIKeyFile = "/home/claude/.claude/remote/.api_key" )
HostOAuthTokenFile and HostAPIKeyFile are the two paths Claude Code compiles in as literals -- one base directory (grep: `/home/claude/.claude/remote`) with a token file and a key file under it. They are not derived from a home directory, and no CLAUDE_CONFIG_DIR or CLAUDE_SECURESTORAGE_CONFIG_DIR moves them.
They are VARS rather than consts, and the reason is sharper than the usual one: they are absolute and outside the home directory, so no t.Setenv can sandbox them. Without this seam a test suite's answer depends on whether the machine running it happens to have a /home/claude, and that failure reads as a flake rather than as an unsandboxed input. Exported because more than one package has to neutralise them.
var ErrForbidden = errors.New("the profile endpoint refused this credential")
ErrForbidden is a 403, and it is deliberately NOT ErrUnauthorized -- the same split internal/usage already makes, for a reason this endpoint makes sharper. A token minted by `claude setup-token` authenticates perfectly well and is refused here on SCOPE: the lookup asks for any_of(user:profile, user:office) and that token carries neither. Folding the two together makes every setup token read as a dead credential, which is the one kind of token `ccdad add-token` exists to register.
ErrUnauthorized means the endpoint rejected the credential itself, as opposed to failing for a reason a retry could fix. A dead token must not be stored as an account.
var UsableLogin = Login{HasAccessToken: true, Scopes: []string{oauth.ScopeInference}}
UsableLogin is what a caller passes when the question is "would anything outrank a WORKING login" rather than "what does this machine's login resolve to". A switch about to WRITE a login asks the first: whether that write survives cannot depend on the login already in the file.
Functions ¶
func APIKeyApproval ¶
APIKeyApproval is the value Claude Code stores in, and looks up from, customApiKeyResponses.approved: the last twenty characters of the trimmed key (`Cbe(e){return e.trim().slice(-20)}`).
It is duplicated from cclink rather than imported because identity must not depend on the package that writes Claude Code's files; both spell the same rule and TestAPIKeyApprovalAgreesWithCclink pins that they agree.
func AuthEnvironmentVars ¶ added in v0.3.0
func AuthEnvironmentVars() []string
AuthEnvironmentVars is every environment variable the two resolvers in this package read. It exists for ONE purpose: a test suite that means to describe a machine has to neutralise all of them, and three packages now reach a resolver -- internal/cli, internal/switcher and internal/daemon.
A list copied into three isolate helpers drifts, and the drift is silent: the suite keeps passing on CI, where none of these are set, and fails only on the shell of whoever exports one. This is that list in one place, so adding a variable to a resolver adds it to every sandbox at once.
It does NOT include the two well-known FILE paths. Those are HostOAuthTokenFile and HostAPIKeyFile, they are package vars precisely because no environment variable can move them, and a sandbox has to repoint them separately.
func HostAPIKeyFilePresent ¶ added in v0.3.0
func HostAPIKeyFilePresent() bool
HostAPIKeyFilePresent is the API-KEY half of the same well-known-file rule, and it lives here because it is the same mechanism read from the same base directory.
Claude Code's API-key resolver eB() calls DDn(), and DDn() is the same reader as mbe() with a different path and a different cache (grep: `wellKnownPath:`) -- so the descriptor variable and this file are two ways into ONE branch, and Claude Code reports both under the source name ANTHROPIC_API_KEY. ccdad modelled only the variable, which meant a machine with this file and no variable had a key that displaces the login and a report that said nothing.
It is a bare function rather than a field of OAuthEnvironment because it belongs to the other axis; APIKeyEnvironment.FileDescriptorKey is where it lands.
func PrimaryByDefault ¶ added in v0.9.0
PrimaryByDefault reports whether a newly added account should start with the primary flag already set.
The flag means "this account's credits are its ORDINARY metering rather than an overage", and it exempts the account from credit.max_auto_spend. That exemption is the whole reason the flag was manual: a ceiling is an opt-in to SPENDING PAST paid quota, and bypassing it should be deliberate.
A seat with no plan-window entitlement is the case where that reasoning inverts. There is no quota for its credits to be an overage of, so the ceiling is not gating an overage — it is gating the only way the account can be used at all, and at its shipped default of 0 it gates it shut forever. Adding such an account IS the deliberate act, because nothing else about it is usable.
It is deliberately the NARROW predicate rather than "was classified credit": an account that reaches KindCredit through a metered billing_type may well have quota behind it, and starting that one exempt from the ceiling would spend money the user never authorized.
func TruthyEnv ¶ added in v0.3.0
TruthyEnv is Un() (grep: `function Un(`): a value counts as true only when it trims and lowercases to one of "1", "true", "yes", "on".
Both axes need it. Treating any non-empty string as true -- which is what claudeAPIKeyEnvironment did for CLAUDE_CODE_SIMPLE -- puts ccdad in bare mode for CLAUDE_CODE_SIMPLE=0 while Claude Code is not, and bare mode changes the answer on both axes.
Types ¶
type APIKeyEnvironment ¶
type APIKeyEnvironment struct {
// Bare is CLAUDE_CODE_SIMPLE or the --bare flag: a stripped-down mode that
// reads only the environment variable and the helper.
Bare bool
// Interactive is whether the session is a terminal session rather than
// `claude -p`. It changes the answer -- see Resolve.
Interactive bool
// EnvKey is ANTHROPIC_API_KEY.
EnvKey string
// FileDescriptorKey reports that a key WILL come from the session host:
// CLAUDE_CODE_API_KEY_FILE_DESCRIPTOR is set, or -- when it is not --
// identity.HostAPIKeyFile stats non-empty. Both reach the same branch of
// eB() and both are reported by Claude Code under the source name
// ANTHROPIC_API_KEY.
//
// The key itself lives behind a descriptor ccdad cannot read, or in a file
// it must not read, so this is a presence flag: enough to know a key WILL
// resolve and displace the login, not enough to say whose it is.
FileDescriptorKey bool
// Helper reports whether the apiKeyHelper setting is configured. As with
// the descriptor, the value would come from running a command, which a
// read-only question must not do.
Helper bool
// Approved is customApiKeyResponses.approved from ~/.claude.json.
Approved []string
// ManagedKey is primaryApiKey from ~/.claude.json.
ManagedKey string
}
APIKeyEnvironment is what the resolution reads. ccdad fills it from the process environment, Claude Code's settings, and ~/.claude.json.
Two things Claude Code consults are deliberately NOT modelled, and both are absent rather than guessed: CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST and the third-party provider switches (Bedrock, Vertex, Foundry), which mean the session is not talking to Anthropic's first-party API at all. On a machine with any of those set, no answer ccdad gives about accounts is meaningful, so the caller checks for them separately rather than this returning a key that will not be used.
func (APIKeyEnvironment) EnvKeyNeedsApproval ¶
func (e APIKeyEnvironment) EnvKeyNeedsApproval() bool
EnvKeyNeedsApproval reports the one case where the answer depends on how Claude Code is started: an ANTHROPIC_API_KEY that a scripted session would use and an interactive one would refuse.
It exists so a caller can say so instead of picking one of the two answers and being wrong half the time.
func (APIKeyEnvironment) Resolve ¶
func (e APIKeyEnvironment) Resolve() (key string, source APIKeySource)
Resolve answers which key Claude Code would use, and from where.
A key is returned only when ccdad can actually see it. The file-descriptor and helper sources resolve to a source with an EMPTY key: something will resolve and it will displace the login, but reading it would mean reading another process's descriptor or running a user-configured command, and this question is read-only.
type APIKeySource ¶
type APIKeySource uint8
APIKeySource names where Claude Code would take a session's API key from.
const ( // APIKeyNone means no key resolves and the session is on its OAuth login, // or on nothing. APIKeyNone APIKeySource = iota // APIKeyEnv is the ANTHROPIC_API_KEY environment variable. APIKeyEnv // APIKeyFileDescriptor is a key a SESSION HOST injected: either through // CLAUDE_CODE_API_KEY_FILE_DESCRIPTOR, or -- when that variable is unset -- // through the well-known file identity.HostAPIKeyFile. One branch of eB() // covers both, and Claude Code reports both under the same source NAME as // the environment variable, so both displace an OAuth login the same way. // // ONE constant for two routes, deliberately: a second one would be two // names for a rule that is identical on every axis a caller can ask about. APIKeyFileDescriptor // APIKeyHelper is the apiKeyHelper setting, a command Claude Code runs. APIKeyHelper // APIKeyManaged is primaryApiKey in ~/.claude.json -- what Claude Code's // own `/login` writes when the user picks an API key, and what `ccdad // switch` writes for an api-key account. It is the ONLY source that does // not displace an OAuth login. APIKeyManaged )
func (APIKeySource) DisplacesOAuth ¶
func (s APIKeySource) DisplacesOAuth() bool
DisplacesOAuth reports whether a key from this source makes Claude Code ignore the credentials file entirely.
This is one term of `BE()` -- `source === "ANTHROPIC_API_KEY" || source === "apiKeyHelper"` -- and the host-injected branch returns the former name, which is why it is on this side of the line too. The file header lists the other three terms, all of which can turn the gate off for reasons no API key controls; an Anthropic CLI profile is one of them, and oauth.go's OAuthProfile is where that is modelled.
func (APIKeySource) Remedy ¶ added in v0.3.0
func (s APIKeySource) Remedy() string
Remedy is what to do about a key from this source. It is ccdad's own wording and NOT the table oauth.go's OAuthSource.Remedy reproduces, and the difference is the point: Claude Code's table is keyed by the name eB() reports, which collapses the variable, the descriptor and the well-known file into one "ANTHROPIC_API_KEY" arm whose remedy is "unset the ANTHROPIC_API_KEY environment variable". On a host-injected machine that variable is not set, so mirroring the table there would send a user after nothing.
func (APIKeySource) String ¶
func (s APIKeySource) String() string
type AntProfile ¶ added in v0.3.0
type AntProfile struct {
// Precedence is HY(): "", "profile-explicit", "env-quad" or
// "profile-implicit".
Precedence string
// AuthType is the profile's authentication.type: "", "oidc_federation" or
// "user_oauth".
AuthType string
}
AntProfile is what Claude Code learned about the Anthropic CLI's configuration. Both fields are plain strings rather than Go enums, because they are another program's vocabulary and inventing names for them would hide which string came from where.
func (AntProfile) Configured ¶ added in v0.3.0
func (p AntProfile) Configured() bool
Configured reports whether the Anthropic CLI has a profile that applies at all -- wVo(), which is `HY() !== null`.
func (AntProfile) LosesToLogin ¶ added in v0.3.0
func (p AntProfile) LosesToLogin() bool
LosesToLogin is MLn(): an IMPLICIT profile whose auth type is user_oauth gives way to a real claude.ai login. It is the one place the two branches genuinely interact, and it is why an explicit ANTHROPIC_PROFILE, the federation variable pair, and an implicit oidc_federation profile all beat a login while an implicit user_oauth one does not.
type Client ¶
Client calls the profile endpoint.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with a bounded timeout and the stdlib transport, so proxy environment variables keep working.
func (*Client) FetchProfile ¶
FetchProfile resolves accessToken to its account.
Errors name the HTTP status and the network cause, never the token and never the response body: the token is a live credential and the body is upstream text, and neither belongs in a message that reaches stderr or a log file.
type HostContext ¶ added in v0.3.0
type HostContext struct {
// Remote is CLAUDE_CODE_REMOTE parsed by TruthyEnv, NOT tested for presence.
// Claude Code reads its environment through a typed accessor and declares
// this variable bool there, so `CLAUDE_CODE_REMOTE=0` is not a host.
Remote bool
// Entrypoint is CLAUDE_CODE_ENTRYPOINT, TRIMMED: the accessor's string
// schema trims and turns a blank into nothing, and the membership test runs
// on that value.
Entrypoint string
// HostAuthEnvVar is CLAUDE_CODE_HOST_AUTH_ENV_VAR, non-empty.
HostAuthEnvVar bool
}
HostContext is the three environment variables that decide whether Claude Code believes it is running inside a session host.
Filled from ccdad's OWN environment, and that is an assumption stated rather than hidden: a launcher that injects CLAUDE_CODE_ENTRYPOINT into the child it starts is invisible from here. When ccdad's environment carries none of these, the child it would start inherits none either, which is the case on every machine a user runs `ccdad which` on by hand.
func (HostContext) IsHosted ¶ added in v0.3.0
func (h HostContext) IsHosted() bool
IsHosted is Wer(): `V.CLAUDE_CODE_REMOTE||BF()`.
func (HostContext) SuppressesAuthToken ¶ added in v0.3.0
func (h HostContext) SuppressesAuthToken() bool
SuppressesAuthToken is XMn() (grep: `CLAUDE_CODE_HOST_AUTH_ENV_VAR`): hosted, no CLAUDE_CODE_HOST_AUTH_ENV_VAR, and the entrypoint is not "claude-desktop-3p". When it holds, Claude Code SKIPS ANTHROPIC_AUTH_TOKEN entirely -- the one place on this axis where setting a credential variable makes less difference rather than more.
type Kind ¶
type Kind uint8
Kind is how an account pays for inference, which decides how the auto-switch engine ranks it.
const ( // KindSubscription is metered by the five-hour and seven-day windows. KindSubscription Kind = iota // KindCredit is metered in money. The engine treats these as a last resort: // subscription quota is already paid for, credits are not. KindCredit // KindAPIKey has no quota concept, so the usage-aware strategies never // consider it. KindAPIKey )
func Classify ¶
func Classify(p *Profile, u UsageShape, isAPIKey bool) Kind
Classify decides how an account is metered.
Subscription windows win outright: an account with an active five-hour or seven-day window is ranked on those windows, even when overage credits are also enabled, because credits are not spent while a window still has room.
The default when there is no evidence is KindSubscription, deliberately. Guessing KindCredit for an account we cannot read would put it on the far side of the credit gate, which is the side that spends money.
func ParseKind ¶
ParseKind is String's inverse, used to read a persisted kind back.
An unrecognized name — an accounts.toml written before the field existed, a typo, or a kind a future release adds — reads as a subscription for the same reason Classify's default does: credit is the side that spends money.
func ReclassifyOnUsage ¶
func ReclassifyOnUsage(current Kind, u UsageShape) (Kind, bool)
ReclassifyOnUsage revises an account's stored Kind in the light of a SUCCESSFUL usage reading, and reports whether the reading was evidence at all.
It is not simply Classify re-run. Classify's no-evidence default — KindSubscription — is a FIRST-classification default: guessing subscription for an account nothing is known about only costs a wasted rotation, while guessing credit would put it on the money-spending side of the gate. Applied to an account that has ALREADY been classified, that same default is destructive: a credit account that has run out of credits reports overage off and no plan windows, and re-running Classify on it would file it as a subscription at exactly the moment it went broke.
So an absence of evidence leaves the stored Kind where it is, and only the two positive signals — plan windows, or overage actually switched on — move it. A failed poll must not reach here at all; that is the caller's job, and it is a different rule from this one.
type Login ¶ added in v0.3.0
Login is the two fields BT()'s last branch tests, and nothing else.
The access token is a PRESENCE flag: BT() only asks whether one exists, and holding a live bearer token to answer that is what this package's credentials rule forbids.
func (Login) SignsInForInference ¶ added in v0.3.0
SignsInForInference is fPn (grep: `IZ(e?.scopes)&&!!e?.accessToken`), whose IZ is `Array.isArray(e)&&e.includes(qte)` with qte the literal "user:inference".
It is the rule this tree used to approximate with "is there a claudeAiOauth object". A Console-flow login stores org:create_api_key and user:profile and no user:inference, so BT() falls straight past it -- Claude Code has no OAuth credential while a login object sits in the file.
type OAuthEnvironment ¶ added in v0.3.0
type OAuthEnvironment struct {
// Bare is CLAUDE_CODE_SIMPLE, parsed by TruthyEnv. Only the variable half
// of cg() is filled -- the other half reads process.argv of a `claude` that
// has not started. See the refusal at the bottom of this file.
Bare bool
// AuthToken reports that ANTHROPIC_AUTH_TOKEN is set. A PRESENCE flag and
// not the value: ccdad stores nothing under that name, so a value could
// never be attributed to an account, and holding a live bearer token to
// answer a presence question is what the credentials rule forbids.
AuthToken bool
// TokenEnv is CLAUDE_CODE_OAUTH_TOKEN's VALUE, and the asymmetry with
// AuthToken is deliberate: ccdad DOES store credentials under this name --
// every setup-token account -- so the value is what lets attribution name
// the account rather than only the mechanism. APIKeyEnvironment.EnvKey is
// the same trade for the same reason.
TokenEnv string
// TokenDescriptor reports that CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR is
// set. Whether the descriptor yields a token would need a read of
// /proc/self/fd/<n> in a process that has not started, so this over-reports
// for a descriptor that would fail -- in the safe direction.
TokenDescriptor bool
// HostTokenFile reports that HostOAuthTokenFile exists and is non-empty.
//
// Claude Code reads that path on EVERY machine when the descriptor variable
// is unset. Only a CLAUDE_CODE_REMOTE session ever WRITES it -- the writer
// opens `if(!V.CLAUDE_CODE_REMOTE)return` while the reader has no such
// gate -- so a file found on a laptop was put there by something other than
// a local `claude`, and ccdad must not offer to remove it.
//
// A non-empty stat, never a read. The one imprecision it costs: Claude
// Code's reader trims, so a whitespace-only file is nothing to it and
// present here. That over-reports, which is the safe direction.
HostTokenFile bool
// BgSnapshot reports that CLAUDE_BG_AUTH_SNAPSHOT_PATH names a non-empty
// file. Gwb() runs INSIDE mbe(), parses that file's JSON, seeds the very
// cache mbe() returns, and UNLINKS the file. Presence alone cannot decide
// the branch -- it fires only if the JSON carries an accessToken -- so this
// makes Resolve DECLINE rather than guess.
BgSnapshot bool
// Helper reports that an apiKeyHelper is configured, as on the api-key axis.
Helper bool
// Host and Profile are the two gates that are not single variables.
Host HostContext
Profile AntProfile
}
OAuthEnvironment is what BT() reads. ccdad fills it from the process environment, two file stats, and Claude Code's settings.
The refusal APIKeyEnvironment carries applies here too, and is repeated rather than cross-referenced because a reader arrives at one or the other: CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST, ANTHROPIC_UNIX_SOCKET and the third-party provider switches (Bedrock, Vertex, Foundry, the AWS and Google variants, Mantle) are deliberately NOT modelled. On a machine with any of them set the session is not talking to Anthropic's first-party API at all, no answer ccdad gives about accounts is meaningful, and the caller checks for them separately rather than this returning a source that will not be used. They are also most of IP()'s own disqualifier list, which is why profileApplies below has only one gate left to test.
func ProbeOAuthEnvironment ¶ added in v0.3.0
func ProbeOAuthEnvironment() OAuthEnvironment
ProbeOAuthEnvironment fills everything BT() reads EXCEPT Helper, from this process's environment and three stats.
Helper is left false for the caller to fill. The apiKeyHelper lives in Claude Code's settings tree, whose project half resolves against the working directory and already has a reader in internal/cli; a second probe here would be a second answer that can disagree with the first. The consequence is named rather than hidden: a caller that cannot reach that reader does not see a configured helper, which is what it saw before this file existed.
func (OAuthEnvironment) Resolve ¶ added in v0.3.0
func (e OAuthEnvironment) Resolve(login Login) (source OAuthSource, ok bool)
Resolve answers which source Claude Code would take a session's OAuth-shaped credential from, given the login sitting in the credentials file.
ok is false when ccdad DECLINES: the state is real, it is decidable only by reading a credential, and naming a source anyway would be a confident wrong answer. There is exactly one such state, and it is BgSnapshot.
type OAuthSource ¶ added in v0.3.0
type OAuthSource uint8
OAuthSource names where Claude Code would take a session's OAuth-shaped credential from. The order is BT()'s own.
const ( // OAuthNone means no OAuth credential resolves. Claude Code then has // whatever the API-key axis produced, which may be nothing. OAuthNone OAuthSource = iota // OAuthAuthTokenEnv is ANTHROPIC_AUTH_TOKEN. It outranks // CLAUDE_CODE_OAUTH_TOKEN. OAuthAuthTokenEnv // OAuthTokenEnv is CLAUDE_CODE_OAUTH_TOKEN -- what `claude setup-token` // prints and what `ccdad run` exports for a setup-token account. OAuthTokenEnv // OAuthTokenDescriptor is CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR: a // session host passing a token through an open file descriptor. OAuthTokenDescriptor // OAuthHostTokenFile is the well-known path Claude Code reads whenever the // descriptor variable is unset. Claude Code calls this source // CCR_OAUTH_TOKEN_FILE. The path is a compiled-in literal: it is NOT // derived from the home directory and no CLAUDE_CONFIG_DIR moves it. OAuthHostTokenFile // OAuthHelper is the apiKeyHelper setting reached on THIS axis. The same // setting also wins on the api-key axis; which name it is reported under // does not change what a user has to do about it. OAuthHelper // OAuthProfile is an Anthropic CLI profile under ~/.config/anthropic. It is // NOT identity.Profile, which is this package's name for the // /api/oauth/profile HTTP response and has nothing to do with it. OAuthProfile // OAuthLogin is the claudeAiOauth record in the credentials file -- the // login ccdad manages, and the only source on this axis a switch changes. OAuthLogin )
func (OAuthSource) Remedy ¶ added in v0.3.0
func (s OAuthSource) Remedy() string
Remedy is Claude Code's own remedy for this source, reproduced from its per-source table (grep: `injected by the CCR host`) including that table's default arm.
Reproduced rather than invented, because Claude Code prints these sentences to the same user: two programs prescribing two different fixes for one state is worse than either fix on its own. Note how little of the table is "unset the variable" -- which is what the single template ccdad used to print said for every source.
func (OAuthSource) SourceName ¶ added in v0.3.0
func (s OAuthSource) SourceName() string
SourceName is the literal Claude Code compares against and prints in its own diagnostics. It exists for two callers: Remedy's dispatch, and a user who has seen one of these strings come out of `claude` and needs ccdad to use the same word. It is never the whole of a sentence ccdad writes.
func (OAuthSource) String ¶ added in v0.3.0
func (s OAuthSource) String() string
String names the source inside a sentence, for a human. It reads correctly after the word "from", which is the shape doctor's api-key row already uses.
It deliberately never returns "CCR_OAUTH_TOKEN_FILE": see SourceName.
type Profile ¶
type Profile struct {
// AccountUUID is account.uuid from the profile endpoint. The primary key.
AccountUUID string
Email string
OrganizationUUID string
// OrganizationType is the subscription tier as the WIRE spells it, which is
// claude_ prefixed throughout: claude_pro, claude_max, claude_team,
// claude_enterprise. Claude Code compares against the mapped SHORT name
// ("enterprise", "max") everywhere, and internal/cli.subscriptionTypeOf is
// the map -- so a predicate that compares this field against "enterprise"
// is a predicate that never fires. Measured against a live claude_enterprise
// organization on 2026-08-26.
OrganizationType string
// RateLimitTier is the plan-window entitlement, e.g. default_claude_max_20x.
// A seat granted none reports default_claude_zero, which is one of the two
// things noPlanWindowProfile reads.
RateLimitTier string
// SeatTier is the seat's own billing arrangement inside the organization,
// e.g. standard, or enterprise_usage_based for a seat metered in money.
// This is a SEAT fact and BillingType below is an ORGANIZATION fact, and an
// enterprise org can hold a contracted subscription while its seats are
// metered per unit -- which is why the two disagree and why only this one
// answers "how is this account metered".
SeatTier string
// BillingType is the ORGANIZATION's billing arrangement, and it is weaker
// evidence than its name suggests. Claude Code reads a closed set of four
// as subscription -- stripe_subscription, stripe_subscription_contracted,
// apple_subscription, google_play_subscription -- and a money-metered
// enterprise seat reports the SECOND of those, because the organization
// really does hold a contracted subscription. No allowlist on this field
// can reach such an account; see Classify and noPlanWindowProfile.
BillingType string
// HasExtraUsage is the organization's has_extra_usage_enabled overage
// switch. It is recorded as a secondary axis and is deliberately NOT
// classification evidence: subscription organizations turn it on too.
HasExtraUsage bool
}
Profile is what /api/oauth/profile tells us about a token's owner.
type StatusError ¶
type StatusError struct{ Status int }
StatusError is a non-200 from the profile endpoint. It carries the status and nothing else: the token is a live credential and the body is upstream text.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Unwrap ¶
func (e *StatusError) Unwrap() error
Unwrap separates the three answers a caller acts on differently, so none of them needs to inspect the number: a 401 is a credential the endpoint will not accept at all, a 403 is one it accepts and will not answer THIS question for, and everything else is the endpoint having a bad day.
type UsageShape ¶
type UsageShape struct {
// HasSubscriptionWindows is true when the usage response carried a
// five_hour or seven_day window.
HasSubscriptionWindows bool
// ExtraUsageEnabled is extra_usage.is_enabled.
ExtraUsageEnabled bool
}
UsageShape is the part of a usage response that matters for classification.