docs/refactor/claude-current-baseline.md
This document is the current-state parity reference for Claude behavior in CodexBar.
Use it when later tickets need to preserve or intentionally change Claude behavior. When the refactor plan, summary docs, and running code disagree, treat current code plus characterization coverage as authoritative, and use this document as the human-readable summary of that current state.
This baseline captures the current behavior surface that later refactor work must preserve unless a future ticket changes it intentionally:
Current Claude behavior is defined by several active owners, not one central planner:
Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift
owns the main provider-pipeline strategy order and fallback rules.Sources/CodexBarCore/Providers/Claude/ClaudeUsageFetcher.swift
still owns a separate direct .auto path, delegated refresh, prompt/cooldown handling, and web-extra enrichment.Sources/CodexBar/Providers/Claude/ClaudeSettingsStore.swift
owns app-side token-account routing into cookie or OAuth behavior.Sources/CodexBarCLI/TokenAccountCLI.swift
owns CLI-side token-account routing and effective source-mode overrides.Sources/CodexBarCore/TokenAccountSupport.swift
owns the current string heuristics that distinguish Claude OAuth access tokens from cookie/session-key inputs.The generic provider pipeline currently resolves Claude strategies in this order:
| Runtime | Selected mode | Ordered strategies | Fallback behavior |
|---|---|---|---|
| app | auto | oauth -> cli -> web | OAuth can fall through to CLI/Web. CLI can fall through to Web only when Web is available. Web is terminal. |
| app | oauth | oauth | No fallback. |
| app | cli | cli | No fallback. |
| app | web | web | No fallback. |
| cli | auto | web -> cli | Web can fall through to CLI. CLI is terminal. |
| cli | oauth | oauth | No fallback. |
| cli | cli | cli | No fallback. |
| cli | web | web | No fallback. |
This behavior is owned by Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift
through ProviderFetchPlan and ProviderFetchPipeline.
.auto decision sitesThe codebase still contains multiple active .auto decision sites:
| Owner | Current behavior |
|---|---|
ClaudeProviderDescriptor.resolveUsageStrategy(...) | Chooses oauth, then cli, then web, with final cli fallback when none are available. |
ClaudeUsageFetcher.loadLatestUsage(.auto) | Chooses oauth, then web, then cli, with final oauth fallback. |
This inconsistency is intentional to record here. RAT-107 directly characterizes the active direct-fetcher branches it can reach cleanly in tests and records the remaining current-state behavior without reconciling it.
Current behavior that later refactor work must preserve:
onlyOnUserAction.securityFramework.onlyOnUserAction,onlyOnUserAction and the caller did not explicitly
allow background delegated refresh.never blocks delegated refresh attempts..claudeCLI: delegated refresh path,.codexbar: direct refresh path,.environment: no auto-refresh.Accepted Claude token-account input shapes today:
sk-ant-oat... prefix,Bearer sk-ant-oat... input,Current routing rules:
Cookie: or =..off), clears the manual cookie
header, and relies on environment-token injection.sessionKey=<value>.auto to oauth, disables cookie mode, omits a
manual cookie header, and injects CODEXBAR_CLAUDE_OAUTH_TOKEN.Claude Web enrichment is cost-only when the primary source is OAuth or CLI:
providerCost when it is missing.accountEmail, accountOrganization, or loginMethod from the primary source.This behavior is implemented in Sources/CodexBarCore/Providers/Claude/ClaudeUsageFetcher.swift
inside applyWebExtrasIfNeeded.
Stable automated coverage for this baseline lives in:
Tests/CodexBarTests/ClaudeBaselineCharacterizationTests.swiftTests/CodexBarTests/ClaudeOAuthFetchStrategyAvailabilityTests.swiftTests/CodexBarTests/ClaudeUsageTests.swiftTests/CodexBarTests/TokenAccountEnvironmentPrecedenceTests.swiftTests/CodexBarTests/SettingsStoreCoverageTests.swiftClaudeUsageTests.swift now directly characterizes the reachable ClaudeUsageFetcher(.auto) branches for:
The successful CLI-selected branch and the CLI-failure-to-OAuth fallback remain documented from code inspection plus surrounding Claude probe/regression coverage, because the current CLI-availability decision is sourced from process-wide binary discovery with no stable test seam that would keep RAT-107 in scope.