How nazmussayad/mytokens works
mytokens is a CLI for collecting coding-agent token usage, estimating costs, and presenting reports. The main workflow parses local histories from multiple tools, normalizes usage records, enriches them with model pricing, then renders selectable terminal views. A parallel export workflow produces overview reports as SVG/PNG and can display or copy images. The README describes OpenCode and OpenRouter, while sampled current source shows many parsers and a models.dev pricing fetch; unsampled parser and export internals are represented only where the tree or excerpts support them.
Main entry points: export/index.ts Export workflow · parsers Agent parsers · app.ts Dashboard runner · src/index.ts CLI entry
Components 26
CLI entrypoints
- CLI entry
src/index.ts - Dashboard runner
src/app.ts - Export commands
src/export/cli.ts - Cache commands
src/cache-cli.ts
Usage ingestion
- Agent parsers
src/parsers - Parsing helpers
src/helpers/parser.ts - Parse cache
src/helpers/parse-cache.ts - Normalized usage
src/core/types.ts
Analysis and display
- Screen selection
src/constants/screen.ts - Usage screens
src/screens - Terminal renderer
src/render/render-screen.ts - Price detection
src/core/price-detector.ts - Pricing fetch
src/core/fetch-models-dot-dev.ts - Model grouping
src/helpers/model-groups.ts
Report export
- Export workflow
src/export/index.ts - Overview aggregation
src/export/overview.ts - SVG rendering
src/export/overview-svg.ts - Image output
src/export/image.ts - Clipboard image
src/export/clipboard.ts - Terminal image
src/export/terminal-image.ts
Other components
- CLI user
- Local usage histories
- OpenCode SQLite
- Terminal output
- models.dev
- Report file
Connections 30
- CLI user → CLI entry: runs
- CLI entry → Dashboard runner: runs dashboard
- CLI entry → Export commands: attaches commands
- CLI entry → Cache commands: attaches commands
- Dashboard runner → Agent parsers: invokes parsers
- Agent parsers → Local usage histories: reads histories
- Agent parsers → OpenCode SQLite: reads OpenCode DB
- Agent parsers → Parsing helpers: normalizes records
- Agent parsers → Parse cache: uses file cache
- Agent parsers → Normalized usage: returns records
- Dashboard runner → Screen selection: selects screen
- Dashboard runner → Usage screens: constructs screen
- Dashboard runner → Parse cache: flushes cache
- Usage screens → Terminal renderer: extends renderer
- Terminal renderer → Normalized usage: aggregates records
- Terminal renderer → Model grouping: loads groups
- Terminal renderer → Terminal output: prints views
- Usage screens → Price detection: estimates costs
- Price detection → Pricing fetch: loads price data
- Pricing fetch → models.dev: fetches catalog
- Export commands → Export workflow: invokes reports
- Export workflow → Agent parsers: loads usage
- Export workflow → Parse cache: flushes cache
- Export workflow → Overview aggregation: computes overview
- Export workflow → SVG rendering: renders overview
- Export workflow → Image output: converts PNG
- Export workflow → Report file: writes report
- Export workflow → Terminal image: displays image
- Export workflow → Clipboard image: copies image
- Cache commands → Parse cache: manages cache