CodexBar uses a flexible strategy pattern to fetch usage data from different sources. Each provider defines a fetch plan with an ordered pipeline of strategies that are tried in sequence until one succeeds.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/steipete/codexbar/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The fetch system has three layers:- Fetch Plan: Declares which source modes are supported
- Fetch Pipeline: Resolves and executes strategies in priority order
- Fetch Strategies: Individual implementations that fetch from specific sources
Source Modes
Source Mode Filtering
- App runtime: Always uses
.automode (tries all strategies) - CLI runtime: Respects
--sourceflag to filter strategies - Strategies check
context.sourceModeto determine availability
ProviderFetchPlan
Set of source modes this provider supports
The strategy resolution and execution pipeline
ProviderFetchPipeline
The pipeline resolves strategies dynamically based on the fetch context:Pipeline Execution
- Resolve strategies for the current context
- For each strategy in order:
- Check if strategy is available
- If available, attempt to fetch
- If successful, return result immediately
- If error occurs and
shouldFallbackreturns true, continue to next strategy - If error occurs and
shouldFallbackreturns false, return error
- If no strategies succeed, return
ProviderFetchError.noAvailableStrategy
ProviderFetchStrategy Protocol
Unique identifier for this strategy (e.g., “claude.cli”, “codex.web”)
The kind of fetch this strategy performs
Required Methods
isAvailable
- Installed CLI binaries
- Available browser cookies
- API tokens in settings
- Source mode compatibility
fetch
shouldFallback
true: Try next strategy (soft error like “CLI not found”)false: Stop immediately (hard error like “authentication failed”)
ProviderFetchKind
ProviderFetchContext
Context passed to all strategies containing runtime configuration:Whether running in app or CLI mode
Requested source mode (auto, web, cli, oauth, api)
Whether to fetch credit information
Timeout for web operations
Whether to log verbose debug info
Provider-specific settings
Shared fetcher for Codex-specific operations
Browser cookie detection helper
ProviderFetchResult
The fetched usage data
Credit information if available
Dashboard data for OpenAI providers
Human-readable label for data source (e.g., “cli”, “web”)
ID of strategy that produced this result
Kind of strategy that produced this result
ProviderFetchOutcome
Complete result of a fetch attempt including all strategy attempts:Success or failure result
History of all strategy attempts
ProviderFetchAttempt
ID of attempted strategy
Kind of strategy attempted
Whether strategy reported itself as available
Error message if fetch failed
Example: Implementing a Strategy
Example: Multi-Strategy Pipeline
Best Practices
- Implement timeout bounds for all network and subprocess operations
- Check
context.sourceModeinisAvailableto respect CLI flags - Return
truefromshouldFallbackfor recoverable errors (missing binary, no cookies) - Return
falsefromshouldFallbackfor auth failures (don’t spam other strategies) - Use descriptive
strategyIDvalues for debugging (e.g., “claude.cli.status”) - Provide helpful error messages that guide users to fix the issue
Related
- ProviderDescriptor - Learn about provider definitions
- Usage Models - Understand data structures returned by strategies
