- Add one folder
- Define one descriptor + strategies
- Add one implementation (UI hooks only)
- Done (tests + docs)
Architecture Overview
CodexBar’s provider system is descriptor-driven:- Providers: Sources of usage/quota/status data (Codex, Claude, Gemini, Antigravity, Cursor, etc.)
- Descriptors: Single source of truth for labels, URLs, defaults, and fetch strategies
- Fetch strategies: Concrete ways to obtain usage (CLI, web cookies, OAuth API, local probe, etc.)
- Host APIs: Shared capabilities provided to providers (Keychain, browser cookies, PTY, HTTP, WebView scrape, token-cost)
- Identity fields: Email/org/plan/loginMethod - must stay siloed per provider
Key Principles
Descriptor-Driven
Descriptor-Driven
All provider metadata lives in the descriptor:
- Display labels, URLs, default enablement
- UI branding (icon, color)
- Capabilities (credits, token cost, status polling, login)
- Fetch pipeline (ordered strategies with fallback)
- CLI metadata (name, aliases, version provider)
Strategy Pipeline
Strategy Pipeline
A provider declares strategies in priority order:
- Each strategy advertises a
kind(cli, web cookies, oauth, api token, local probe, web dashboard) - Declares availability (checks settings, cookies, env vars, installed CLI)
- Fetches
UsageSnapshot(and optional credits/dashboard) - Can be filtered by CLI
--sourceor app settings - Pipeline resolves to best available strategy with fallback on failure
Host APIs
Host APIs
Providers use narrow, explicit APIs:
KeychainAPI- Read-only, allowlisted service/account pairsBrowserCookieAPI- Import cookies by domain listPTYAPI- Run CLI interactions with timeoutsHTTPAPI- URLSession with domain allowlistWebViewScrapeAPI- WKWebView lease + evaluateJavaScriptTokenCostAPI- Cost Usage local-log integrationStatusAPI- Status polling helpersLoggerAPI- Scoped logger + redaction
FileManager, Security, or “browser internals” directly.Identity Silo
Identity Silo
Never display identity/plan fields from provider A inside provider B UI. Each provider’s identity is kept separate.
Building Blocks
Common utilities already exist:- PTY:
TTYCommandRunner - Subprocess:
SubprocessRunner - Cookie import:
BrowserCookieImporter(Safari/Chrome/Firefox adapters) - Web scrape:
OpenAIDashboardFetcher(WKWebView + JS) - Cost usage: Local log scanner (Codex + Claude)
Provider Code Layout
Minimal Provider Example
Here’s a complete minimal provider you can copy and modify:Adding a New Provider: Checklist
Add Provider Case
Add a case to
UsageProvider enum in Sources/CodexBarCore/Providers/Providers.swift:Create Descriptor Folder
Create
Sources/CodexBarCore/Providers/<ProviderID>/ with:<ProviderID>Descriptor.swift- DefineProviderDescriptor+ fetch pipeline<ProviderID>Strategies.swift- ImplementProviderFetchStrategy<ProviderID>Probe.swift- Concrete fetcher logic<ProviderID>Models.swift- Snapshot structs<ProviderID>Parser.swift- Text/HTML parsing (if needed)
Attach Macros
Attach
@ProviderDescriptorRegistration + @ProviderDescriptorDefinition to your descriptor type.
Implement static func makeDescriptor() -> ProviderDescriptor.Macros auto-register the descriptor - no manual list edits needed.Create Implementation
Create
Sources/CodexBar/Providers/<ProviderID>/<ProviderID>ProviderImplementation.swift:- Attach
@ProviderImplementationRegistrationmacro (auto-registers) - Implement
ProviderImplementationprotocol for settings/login UI hooks only
Add Branding Assets
Add icons + color in descriptor:
iconNamemust matchProviderIcon-<id>asset inAssets.xcassets- Color used in menu cards + switcher
CLI Support (Optional)
If CLI-specific behavior is needed:
- Add
cliName,cliAliases,sourceModes,versionProviderin descriptor - Strategies decide which
--sourcemodes apply
Write Tests
Add tests to
Tests/CodexBarTests/:UsageSnapshotmapping unit tests- Strategy availability + fallback tests
- CLI provider parsing (aliases + —source validation)
Fetch Strategy Types
CLI PTY Strategy
Web API with Cookies
OAuth API
Local Probe
Guardrails (Non-Negotiable)
Testing Your Provider
Unit Tests
Integration Testing
Common Patterns
Fallback Strategy Pipeline
Browser Cookie Import
Local Cost Usage
UI Customization (Optional)
For provider-specific UI needs, implementProviderImplementation:
Troubleshooting
Descriptor not found
Descriptor not found
Ensure
@ProviderDescriptorRegistration and @ProviderDescriptorDefinition macros are attached to your descriptor type.Check that makeDescriptor() is implemented and returns a valid ProviderDescriptor.Strategy never runs
Strategy never runs
Check
isAvailable() implementation - it may be returning false.Verify the strategy is included in the pipeline for the current source mode.Cookies not importing
Cookies not importing
Icon not showing
Icon not showing
Icon asset must be named
ProviderIcon-<id> in Assets.xcassets.Ensure iconResourceName in descriptor matches the asset name.Related Documentation
Providers Overview
Learn about existing providers and authentication methods
Configuration
Configure provider settings and API keys
CLI Reference
Test your provider with the CLI
Architecture
Understand CodexBar’s internal structure
