How agentseal/codeburn works
1. What this repository is
- CodeBurn is a Node.js 20+ TypeScript CLI that reads local AI coding tool data from disk and turns it into cost/usage analytics.
- It is not an API server or wrapper around the tools; it is a read-only offline analyzer.
2. Core data flow
- The app starts from the CLI, selects a command and provider scope, discovers session files/databases on the local machine, parses them into a common internal event model, enriches them with pricing and currency, classifies activity, then renders one of several outputs: TUI dashboard, status line, export file, or menu bar plugin.
3. Provider boundary
- The main architectural seam is the provider system in src/providers/.
- Each provider adapts one AI tool’s storage format into a shared interface: session discovery, parsing, tool normalization, and display names.
- Supported providers are Claude Code, Codex, Cursor, OpenCode, and Pi; Cursor and OpenCode are lazily loaded because they need SQLite support.
4. Parsing and normalization layer
- src/parser.ts orchestrates reading session data, deduping messages, filtering by date range, and merging provider-specific records into a unified view.
- This is where provider differences are hidden from the rest of the app, so downstream code works with one normalized event stream.
- The parser also applies provider-specific deduplication strategies because each tool records sessions differently.
5. Cost and model enrichment
- src/models.ts calculates costs using LiteLLM pricing data and handles token categories like input, output, cache read/write, and search-related costs.
- src/currency.ts converts USD pricing into the selected ISO currency and fetches exchange rates from Frankfurter, with local caching.
- src/config.ts stores the user’s currency preference under ~/.config/codeburn/, while price/rate caches live under ~/.cache/codeburn/.
6. Activity classification
- src/classifier.ts maps each turn into one of 13 task categories using deterministic rules over tool usage patterns and user text keywords.
- This subsystem feeds the “one-shot” success analysis and the breakdown panels, so it is central to the product’s interpretation layer.
- The classifier depends on normalized tool names coming from providers, especially where tools differ across vendors.
7. Output surfaces
- src/dashboard.tsx is the interactive terminal UI built with Ink/React for terminal rendering.
- src/format.ts provides compact text formatting for status output.
- src/export.ts generates CSV/JSON exports across multiple time windows.
- src/menubar.ts generates a SwiftBar/xbar plugin for macOS menu bar display.
8. Storage and caching boundaries
- The app is intentionally read-only against source data, but it does maintain its own caches.
- src/cursor-cache.ts stores parsed Cursor results in a file cache and invalidates them when the underlying database changes.
- src/sqlite.ts is a lazy adapter around better-sqlite3, keeping SQLite-specific work isolated to providers that need it.
9. Command-line and runtime structure
- src/cli.ts is the Commander.js entry point and routes commands such as report, today, month, status, export, currency, and menubar install/uninstall.
- The CLI is the orchestration layer; it does not do parsing or rendering itself, it delegates to the domain modules above.
- Tests cover the command surface, provider registry, exports, dashboard behavior, and provider parsers.
10. Provider registry and extensibility
- src/providers/index.ts and src/providers/types.ts define the plugin contract and registry behavior.
- This is the primary extension boundary: adding a new AI tool generally means implementing one provider module without changing the rest of the system.
- The README’s “single file provider” claim is reflected in this architecture.
11. Platform-specific data access
- The repo mixes JSONL file ingestion and SQLite database reads depending on provider.
- Claude, Codex, and Pi are file-based; Cursor and OpenCode require database access; Cursor additionally relies on extracted language/code block data rather than per-tool logs.
- This affects both data discovery paths and the shape of the displayed breakdowns.
12. External dependencies that materially affect architecture
- LiteLLM pricing data drives all cost calculations, and Frankfurter drives currency conversion.
- better-sqlite3 is an optional dependency that only becomes relevant for SQLite-backed providers.
- SwiftBar/xbar is the only external UI integration outside the terminal.
13. How to diagram it
- A useful architecture diagram would show: local AI tool data sources on disk on the left, provider adapters in the middle, a shared parse/classify/pricing core above them, and four output channels on the right: TUI dashboard, CLI/status text, export files, and SwiftBar menu bar plugin.
Main entry points: parser.ts Parser · cli.ts CLI · index.ts Provider registry · models.ts Cost model
Components 20
CLI runtime
Command entrypoints and orchestration
- CLI · Commander.js entrypoint that routes commands and orchestrates the app
src/cli.ts
Provider layer
Adapters for each AI tool storage format
- Provider registry · Selects and loads provider implementations
src/providers/index.ts - Provider types · Shared provider interface and extension boundary
src/providers/types.ts - Claude · Reads Claude Code session data from local files
src/providers/claude.ts - Codex · Reads Codex session data from local files
src/providers/codex.ts - Copilot · Reads Copilot session data from local files
src/providers/copilot.ts - Cursor · Loads Cursor data through SQLite-backed discovery and caching
src/providers/cursor.ts - OpenCode · Loads OpenCode data from SQLite-backed storage
src/providers/opencode.ts - Pi · Reads Pi session data from local files
src/providers/pi.ts
Analysis core
Parsing, normalization, pricing, classification, and config
- Parser · Discovers sessions, dedupes messages, merges provider records, and filters by date range
src/parser.ts - Classifier · Maps turns into task categories using tool patterns and user text
src/classifier.ts - Cost model · Calculates token costs from pricing data and model metadata
src/models.ts - Currency · Converts USD pricing into the selected currency and fetches exchange rates
src/currency.ts - Config · Stores user currency preferences and cache locations
src/config.ts - Cursor cache · Caches parsed Cursor results and invalidates on database changes
src/cursor-cache.ts - SQLite adapter · Isolates better-sqlite3 access for SQLite-backed providers
src/sqlite.ts
Outputs
Terminal, export, and menu bar renderers
- Dashboard · Interactive terminal dashboard built with Ink/React
src/dashboard.tsx - Status text · Produces compact text output for status surfaces
src/format.ts - Export · Generates CSV and JSON exports across time windows
src/export.ts - Menubar · Builds a SwiftBar/xbar macOS menu bar plugin
src/menubar.ts
Connections 35
- CLI → Provider registry: select provider · CLI resolves provider scope through the registry
- CLI → Parser: run analysis · CLI delegates parsing and normalization to the core parser
- CLI → Classifier: classify · Command flows require activity classification
- CLI → Dashboard: open tui · Interactive report command renders the terminal dashboard
- CLI → Status text: status output · Status commands use compact text formatting
- CLI → Export: export data · Export commands produce files from normalized data
- CLI → Menubar: build plugin · Menubar commands generate the macOS plugin
- CLI → Currency: set currency · Currency commands update preferences used by pricing
- Provider registry → Provider types: implements · Registry is defined by the shared provider contract
- Provider registry → Claude: loads · Registry exposes Claude support
- Provider registry → Codex: loads · Registry exposes Codex support
- Provider registry → Copilot: loads · Registry exposes Copilot support
- Provider registry → Cursor: loads · Registry exposes Cursor support
- Provider registry → OpenCode: loads · Registry exposes OpenCode support
- Provider registry → Pi: loads · Registry exposes Pi support
- Parser → Provider types: uses contract · Parser works against the normalized provider interface
- Parser → Claude: reads · Parses Claude session data
- Parser → Codex: reads · Parses Codex session data
- Parser → Copilot: reads · Parses Copilot session data
- Parser → Cursor: reads · Parses Cursor session data
- Parser → OpenCode: reads · Parses OpenCode session data
- Parser → Pi: reads · Parses Pi session data
- Parser → Classifier: feeds turns · Normalized turns are classified into task categories
- Parser → Cost model: feeds usage · Parsed usage data is priced into costs
- Cost model → Currency: convert currency · Cost calculations are converted from USD to the selected currency
- Currency → Config: reads prefs · Currency selection comes from stored configuration
- Cursor → Cursor cache: cache parsed data · Cursor provider persists parsed results in a local cache
- Cursor → SQLite adapter: query db · Cursor provider uses the lazy SQLite adapter
- OpenCode → SQLite adapter: query db · OpenCode provider uses the lazy SQLite adapter
- Dashboard → Classifier: breakdowns · Dashboard presents classified activity and one-shot analysis
- Dashboard → Cost model: cost views · Dashboard shows cost and token summaries
- Status text → Cost model: summarize · Status text is derived from cost and usage totals
- Export → Parser: consume data · Exports are generated from normalized session data
- Export → Cost model: include costs · Exports include priced usage summaries
- Menubar → Status text: reuse text · Menu bar output reuses compact formatting rules