Modules
CodexBar uses a multi-module architecture powered by Swift Package Manager:-
CodexBarCore: Core functionality for fetching and parsing provider data
- Codex RPC client and PTY fallback
- Claude CLI probes and OAuth flows
- OpenAI web scraping utilities
- Status polling and provider abstractions
- Located at
Sources/CodexBarCore
-
CodexBar: Main application with state management and UI
UsageStorefor provider usage/credits stateSettingsStorefor user preferencesStatusItemControllerfor menu bar integration- Menu rendering and icon generation
- Located at
Sources/CodexBar
-
CodexBarWidget: WidgetKit extension
- Mirrors menu card snapshots to home screen widgets
- Shares data via app group containers
- Located at
Sources/CodexBarWidget
-
CodexBarCLI: Standalone command-line interface
- Bundled with the app for scripting and CI
- Supports
codexbar cost --provider codex|claude - Located at
Sources/CodexBarCLI
-
CodexBarMacros: SwiftSyntax-based compile-time macros
- Automated provider registration
- Located at
Sources/CodexBarMacros
-
CodexBarMacroSupport: Shared macro utilities
- Used across app, core, and CLI targets
- Located at
Sources/CodexBarMacroSupport
-
CodexBarClaudeWatchdog: Helper process
- Ensures Claude CLI PTY sessions terminate cleanly
- Prevents orphaned processes on app crash/kill
- Located at
Sources/CodexBarClaudeWatchdog
-
CodexBarClaudeWebProbe: Diagnostic CLI
- Helps troubleshoot Claude web authentication
- Located at
Sources/CodexBarClaudeWebProbe
Entry Points
CodexBarApp
The main SwiftUI application entry point:- Manages app lifecycle and keepalive
- Hosts the Settings window scene
- Uses modern
@Observablepatterns (notObservableObject)
AppDelegate
Handles system integration:- Wires
StatusItemControllerfor menu bar presence - Configures Sparkle updater for automatic updates
- Manages notification permissions and delivery
Data Flow
CodexBar follows a unidirectional data flow pattern:Provider probes
UsageFetcher executes provider-specific probes:- Codex: RPC client or PTY fallback
- Claude: OAuth API or browser cookies
- Others: CLI commands, browser cookies, or OAuth flows
State update
Results flow into
UsageStore, updating:- Session and weekly usage meters
- Credit balances
- Optional web dashboard data (for Codex)
Settings flow
- User toggles in Settings update
SettingsStore SettingsStorechanges affect:- Refresh cadence and timing
- Enabled providers
- Feature flags (merge icons, overview tab, etc.)
- Authentication methods per provider
Concurrency Model
CodexBar uses Swift 6 strict concurrency throughout:Best Practices
- Prefer
Sendabletypes for shared state - Use explicit
@MainActorannotations for UI updates - Background fetchers run off-main to avoid blocking
- All async operations are properly isolated
Platform Requirements
- macOS 14+ (Sonoma) for the GUI app
- Avoids deprecated APIs in favor of modern alternatives
- Uses Observation framework (
@Observable) instead of Combine
Provider Architecture
Each provider implements a common protocol pattern:- Fetcher: Executes provider-specific data retrieval
- Parser: Converts raw responses to structured usage data
- Store integration: Updates
UsageStorewith normalized results - Registration: Macro-based provider discovery
Related Documentation
- Refresh Loop - Background update mechanics
- Building from Source - Build instructions and dev setup
- Contributing - Guidelines for contributors
