Skip to main content

Local-first AI token usage tracker for coding assistants

Project description

aitrack

Local-first AI token usage tracker for coding assistants (Opencode, Kiro, and more).

Tracks token consumption, estimates costs, and provides live usage monitoring — all on your machine, no cloud needed.

Features

  • Discovery — automatically finds AI tool data sources on your machine
  • Incremental scanning — avoids duplicate imports with SHA-256 dedup
  • Daily/weekly/monthly/lifetime stats — tokens and cost summaries
  • Breakdowns — by tool, model, and provider
  • Cost calculator — configurable pricing for all major models
  • Live dashboard — Textual-based real-time UI
  • File watching — auto-rescans when data files change
  • Session analytics — top sessions by tokens/duration/cost
  • Export — CSV and JSON export for any period

Supported Tools

Tool Data Source Tokens Model
Opencode ~/.local/share/opencode/opencode.db Full (input/output/reasoning/cache) Full
Opencode logs ~/.local/share/opencode/log/*.log Full Full
Kiro ~/.local/share/kiro-cli/data.sqlite3 Estimated from word count Full
Generic JSON/NDJSON/log files in search paths When available When available

Installation

# Clone the repo
git clone <url> aitrack
cd aitrack

# Install with pip
pip install -e .

# Or use the Makefile
make install

Requires Python 3.12+.

Quick Start

# Discover AI tool data sources on your machine
aitrack discover

# Import all discovered data
aitrack scan

# View today's usage
aitrack today

# View lifetime stats
aitrack lifetime

# View cost breakdown
aitrack cost

# Launch the live dashboard
aitrack live

# Watch for file changes and auto-rescan
aitrack watch

# Export data for this month
aitrack export csv --period month

CLI Reference

aitrack discover

Detects AI tools and their data sources on the local machine.

Output: tool name, source type, path, parser compatibility, record count.

aitrack scan

Reads all discovered sources and imports usage records. Skips duplicates using content hashing. Creates the SQLite database at ~/.local/share/aitrack/usage.db.

aitrack today / week / month / lifetime

Shows:

  • Total input, output, reasoning, cache read/write tokens
  • Estimated cost
  • Breakdown by tool, model, and provider

aitrack cost

  • Pricing configuration for all models
  • Cost summary by period (today, week, month, lifetime)
  • Cost breakdown by provider

aitrack watch

Monitors Opencode and Kiro data directories for file changes. Automatically rescans when changes are detected (debounced at 5s).

aitrack live

Launches a Textual-based terminal dashboard that auto-refreshes every 5 seconds. Shows:

  • Today/week/month/lifetime stats panels
  • Model leaderboard
  • Tool leaderboard

aitrack sessions

Lists all tracked sessions with duration, token count, request count, and cost.

aitrack top-sessions

aitrack top-sessions --sort-by tokens --limit 10

Sort by: tokens (default), duration, or cost.

aitrack export

aitrack export csv --period lifetime --output ./my_data.csv
aitrack export json --period month

Periods: today, week, month, lifetime.

aitrack status

Quick health check: database path, size, total record count, last activity, and tools tracked.

aitrack reset

Deletes the local usage database. Prompts for confirmation unless --force/-f is passed. Use this to clear bad data and re-scan from scratch.

aitrack reset          # prompts for confirmation
aitrack reset --force  # skips confirmation

Global options

  • --version — print the installed version and exit.
  • --verbose / -v — enable debug logging to stderr (in addition to the log file at ~/.local/share/aitrack/log/aitrack.log).

Pricing Configuration

Pricing is stored at ~/.config/aitrack/pricing.json. You can edit this file to add or update model pricing.

Default pricing includes:

  • GPT-5, Claude Sonnet 4, Claude Opus 4, Claude Haiku 4.5, Gemini 2.5 Pro
  • OpenRouter models (catch-all with $0 default)
  • Kiro models (auto, claude-haiku-4.5, claude-opus-4.8, glm-5)
  • Opencode big-pickle (free)

Database Schema

~/.local/share/aitrack/usage.db

Column Type Description
id INTEGER Primary key
timestamp DATETIME When the usage occurred
tool_name TEXT Source tool (opencode, kiro, etc.)
provider TEXT AI provider (openai, anthropic, etc.)
model TEXT Model ID
input_tokens INTEGER Prompt/input tokens
output_tokens INTEGER Completion/output tokens
reasoning_tokens INTEGER Reasoning tokens
cache_read_tokens INTEGER Cache read tokens
cache_write_tokens INTEGER Cache write tokens
total_tokens INTEGER Sum of all token types
estimated_cost FLOAT Calculated cost
session_id TEXT Session or conversation ID
source_file TEXT Original data source path
source_hash TEXT SHA-256 dedup hash

Example Output

$ aitrack today

          Today Usage
╭─────────────┬────────┬───────╮
│ Item        │ Tokens │ Cost  │
├─────────────┼────────┼───────┤
│ Input       │ 70.0K  │ $0.00 │
│ Output      │ 28.7K  │ $0.00 │
│ Reasoning   │ 2.5K   │ -     │
│ Cache Read  │ 2.6M   │ -     │
│ Cache Write │ 0      │ -     │
│ Total       │ 2.7M   │ $0.00 │
╰─────────────┴────────┴───────╯
           Records: 3

             Today by Tool
╭──────────┬────────┬───────┬─────────╮
│ Name     │ Tokens │     % │    Cost │
├──────────┼────────┼───────┼─────────┤
│ opencode │  50.2M │ 99.8% │   $0.00 │
│ kiro     │  84.2K │  0.2% │ $0.3791 │
╰──────────┴────────┴───────┴─────────╯

Architecture

aitrack/
├── src/aitrack/
│   ├── cli.py                  # Typer CLI entry point
│   ├── collectors/             # Data source collectors
│   │   ├── opencode.py         # Opencode DB + log scanner
│   │   ├── kiro.py             # Kiro DB scanner
│   │   └── generic.py          # Generic JSON/NDJSON/log scanner
│   ├── commands/               # CLI command implementations
│   │   ├── discover.py         # Source discovery
│   │   ├── scan.py             # Data import
│   │   ├── stats.py            # today/week/month/lifetime
│   │   ├── cost.py             # Cost summaries
│   │   ├── watch.py            # File watcher
│   │   ├── sessions.py         # Session analytics
│   │   ├── status.py           # DB health check
│   │   ├── reset.py            # Clear local database
│   │   └── export_.py          # CSV/JSON export
│   ├── database/               # SQLAlchemy + Repository
│   │   ├── models.py           # ORM models
│   │   └── repository.py       # Data access layer
│   ├── dashboard/              # Textual live dashboard
│   │   └── live_app.py         # Real-time UI
│   ├── models/                 # Pydantic models
│   │   ├── usage_record.py     # Usage data schema
│   │   ├── discovery.py        # Discovery schema
│   │   └── pricing.py          # Pricing schema
│   └── utils/                  # Utilities
│       ├── pricing.py          # Cost calculator
│       ├── formatters.py       # Rich terminal formatting
│       └── logging.py          # Logging setup
├── tests/                      # Test suite (57 tests)
├── pyproject.toml
├── Makefile
└── README.md

Platform Support

Currently tested on Linux (~/.local/share, ~/.config paths). macOS uses different standard paths (~/Library/Application Support, ~/Library/Preferences) which are not yet auto-detected — contributions welcome.

Testing

make test        # Run all tests
make lint        # Lint with ruff
make format      # Format with ruff

Development

make dev    # Install with dev dependencies
make build  # Build distribution packages
make clean  # Clean build artifacts

See CONTRIBUTING.md for details on adding new collectors and the development workflow.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

local_ai_track-1.0.0.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

local_ai_track-1.0.0-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file local_ai_track-1.0.0.tar.gz.

File metadata

  • Download URL: local_ai_track-1.0.0.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for local_ai_track-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3a4049d9fb64bd3a4f533903a768f6f022a54a98742f3adc22a337396989c550
MD5 3c0446f9dc9346ff4f164464ea8022d8
BLAKE2b-256 c9f24b6e5e0422c39cb13d4739fc0235bd4d97b100280905da4364315a0c1bbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for local_ai_track-1.0.0.tar.gz:

Publisher: publish.yml on ayushks1ngh/ai-track

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file local_ai_track-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: local_ai_track-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for local_ai_track-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39470862bc49e2748bee05935f3a004996777f883ff9b8b3e2a1a1a78d355f52
MD5 09486ef94d83d192b68d1592d96d89ac
BLAKE2b-256 5e4d6ca98e4406c3a8ad39c590ada941d8adb35f2b4a1aa0165a4cd8454d0cc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for local_ai_track-1.0.0-py3-none-any.whl:

Publisher: publish.yml on ayushks1ngh/ai-track

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page