Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: bun run lint

- name: Test
run: bun test
run: bun run test
23 changes: 15 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: bun run lint

- name: Test
run: bun test
run: bun run test

# ==========================================================================
# Job 2: Publish — only after verify succeeds
Expand Down Expand Up @@ -88,12 +88,19 @@ jobs:
- name: Build
run: bun run build

- name: Publish @sriinnu/tokmeter
run: cd packages/tokmeter && npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish @sriinnu/drishti
run: cd packages/mcp && npm publish --provenance --access public
- name: Prepare and publish verified package artifacts
run: |
bash scripts/prepare-packages.sh "$RUNNER_TEMP/tokmeter-packages"
for package in tokmeter mcp; do
name=$(node -p "require('./packages/$package/package.json').name")
version=$(node -p "require('./packages/$package/package.json').version")
# A local signed release can publish npm before creating the
# GitHub release. Never attempt to overwrite that version.
if npm view "$name@$version" version 2>/dev/null | grep -Fx "$version"; then
echo "$name@$version is already published"
continue
fi
npm publish "$RUNNER_TEMP/tokmeter-packages/$package-$version.tgz" --provenance --access public
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.10.0] — 2026-09-06

### Changed

- The macOS opening view now leads with today's tokens, separates estimated API cost from tool-reported amounts, and shows today's projects. Secondary gauges and lifetime metrics live under Usage details.
- Model lists open on Today and retain all models behind Show all. Missing cost data is labeled Unavailable; an explicit known zero stays zero.
- Added a compatibility table, pricing methodology, synthetic-data walkthrough, and a one-week tester guide.

### Fixed

- Read Codex `token_usage_record` receipts, deduplicate mirrored legacy counters and repeated response IDs, and skip replayed parent receipts in subagents.
- Keep SQLite fallback usage separate from sessions covered by JSONL, including receipts buried before long tool output.
- Correct reasoning percentages and preserve explicit zero cache/reasoning rates and tool-reported zero costs.
- An idle local day no longer inherits the previous active day's totals in the macOS header.
- npm and macOS artifacts now include the application/core license texts and matching source; the macOS app also includes Sparkle notices and a Licenses & source control.

### Validation

See [release preparation](docs/release/1.10.0.md) for checks and [the tagged release](https://github.com/sriinnu/tokmeter/releases/tag/v1.10.0) for publication status and downloads.

## [1.9.2] - 2026-07-15

### Fixed
Expand Down
94 changes: 39 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,57 @@
<p align="center">
<img src="logo.svg" alt="Tokmeter" width="120" />
</p>
<p align="center"><img src="logo.svg" alt="Tokmeter" width="88" /></p>

<h1 align="center">tokmeter</h1>
# Tokmeter

<p align="center"><strong>Token Usage Tracker for AI Coding Agents</strong></p>
**See where your AI coding usage goes—across projects, models, and agents.**

<p align="center">
<a href="https://github.com/sriinnu/tokmeter/releases/latest"><img src="https://img.shields.io/badge/release-v1.9.2-39d353?style=flat-square&logo=github" alt="release" /></a>
<a href="https://www.npmjs.com/package/@sriinnu/tokmeter"><img src="https://img.shields.io/badge/npm-@sriinnu/tokmeter-39d353?style=flat-square&logo=npm" alt="npm" /></a>
<img src="https://img.shields.io/badge/node-%3E%3D18-0e4429?style=flat-square&logo=node.js" alt="node" />
<img src="https://img.shields.io/badge/license-AGPL--3.0-26a641?style=flat-square" alt="license" />
<img src="https://img.shields.io/badge/bun-monorepo-39d353?style=flat-square&logo=npm" alt="bun" />
</p>
Tokmeter turns local coding-agent usage into a daily view of tokens, estimated API cost, and the projects driving it. Your history stays on your machine, including saved daily totals after old session logs are removed.

---
Start with Claude Code and Codex on macOS. Other integrations have different levels of evidence; see the [compatibility table](docs/compatibility.md).

Tokmeter parses local session logs from 16+ AI coding agents into per-project / model / provider / day token-and-cost aggregates, and exposes them through five surfaces: CLI, TUI, web dashboard, MCP server, and a macOS menu-bar daemon.
## See it

Pricing is resolved locally via [`@sriinnu/kosha-discovery`](https://www.npmjs.com/package/@sriinnu/kosha-discovery) (20+ providers, 300+ OpenRouter models); nothing leaves the machine.
<p align="center"><img src="docs/assets/demo/scene-01.png" alt="Tokmeter showing today's tokens, estimated API cost, models, and projects with synthetic demo data" width="360" /></p>

How it stores history, keeps "today" live, and stays memory-bounded - the daemon + relay model - is in [`docs/architecture.md`](docs/architecture.md). Package layout is under [Packages](#packages); programmatic use is under [Consume Tokmeter From Other Apps](#consume-tokmeter-from-other-apps).
[Watch the 20-second walkthrough](docs/assets/demo/tokmeter-demo.mp4) · [How the numbers work](docs/how-the-numbers-work.md)

## What it looks like
The walkthrough renders the **1.10.0** macOS views using synthetic data; it is not a recording of a customer's usage. See the [release page](https://github.com/sriinnu/tokmeter/releases/tag/v1.10.0) for downloads.

Below is exactly what tokmeter prints on a real machine - same code you'd `npm install`. Project names are swapped to generic ones for privacy; spend numbers, cache rates, optimization scores, model breakdowns, and everything else are unedited.
## Try one report

<table>
<tr>
<td align="center" width="50%">
<img src="docs/assets/screenshots/bar-popover.png" alt="TokmeterBar popover" width="280" />
<br/><em>macOS menu bar - live signals at a glance.</em>
</td>
<td align="center" width="50%">
<img src="docs/assets/screenshots/cli-digest.png" alt="tokmeter digest --period week" width="380" />
<br/><em><code>tokmeter digest</code> - weekly cost report card with optimization grade.</em>
</td>
</tr>
</table>
Requires Node.js 18+ and local usage from a supported coding agent:

<p align="center">
<img src="docs/assets/screenshots/cli-overview.png" alt="tokmeter overview" width="560" />
<br/><em><code>tokmeter</code> - per-project breakdown across all parsed agents.</em>
</p>
```sh
npx @sriinnu/tokmeter --today
```

Try it on your own data: `npx @sriinnu/tokmeter` (add `--light` to skip pricing on the first scan). More surface shots (TUI, web, Hub, statusline) are tracked in [`docs/assets/screenshots/README.md`](docs/assets/screenshots/README.md).
No provider API key is needed to read Claude Code or Codex's local usage. Pricing lookup can fetch public catalog data. Session contents are not sent to a service. To skip pricing:

## What it computes
```sh
npx @sriinnu/tokmeter --today --light
```

From parsed session logs, per project / model / provider / day:
## Keep it in your macOS menu bar

- Cost and token totals (input / output / cache-read / cache-write / reasoning).
- Cache hit rate and cache savings.
- Daily spend trend and active-day streaks.
- Compaction overhead - the share of today's spend that went to `/compact`.
- Live burn rate and pace vs. your typical spend at this hour (from the relay's `costByHour`).
- Cheaper-model suggestions from the live kosha price registry.
Requires macOS 14+ and the local daemon:

All local; no network calls except the kosha pricing fetch.
1. Install the daemon: `npm install -g @sriinnu/drishti`
2. Start it: `drishti daemon start`
3. Download **TokmeterBar** from [GitHub Releases](https://github.com/sriinnu/tokmeter/releases/latest), move it into Applications, and open it.

## Quick Start
The menu bar shows today's tokens. Open it for estimated API cost, any tool-reported cost, and today's models and projects. Expand **Usage details** for trends and other metrics. The [macOS guide](packages/macos-bar/README.md) covers building locally.

```bash
# Run directly
npx @sriinnu/tokmeter
## Understand the dollars

# Or install globally - gives you both `tokmeter` and `tokmeter-tui`
npm install -g @sriinnu/tokmeter
tokmeter
tokmeter-tui
```
- **Estimated API cost** values recorded usage at model rates. It is not your ChatGPT or Claude subscription bill.
- **Tool-reported cost** is an amount already present in local tool telemetry. It is not independently verified against an invoice.
- **Unavailable** means the price, token breakdown, or source information is missing. A missing price is not a free request.
- Historical totals can combine estimates and tool reports. Older saved days may lack enough information to separate them; normal refreshes preserve those days.

## Help us test it

The first trial focuses on macOS developers using both Claude Code and Codex. [The one-week trial guide](docs/trial/guide.md) explains what to try and how to report a mismatch without sharing a transcript.

For developers integrating Tokmeter: the CLI, TUI, web dashboard, MCP server, and [daemon/relay architecture](docs/architecture.md) share the same accounting core. Details follow.

## Packages

Expand Down Expand Up @@ -230,7 +212,7 @@ The `digest` command gives you a cost report card:
Discipline: F (40)

Tips:
- You spent $620 on GPT-5.4 today - Sonnet would've cost $124
- The same recorded token counts estimate to $620 on model A and $124 on model B; task quality is not evaluated
- Cache efficiency is solid at 98% - keep sessions active
```

Expand Down Expand Up @@ -430,7 +412,7 @@ works whether or not a provider reports a context window. Turn it off for a plai
monochrome icon.

<p align="center">
<img src="docs/assets/screenshots/bar-popover.png" alt="TokmeterBar popover" width="320" />
<img src="docs/assets/demo/scene-01.png" alt="TokmeterBar popover" width="320" />
</p>

```bash
Expand Down Expand Up @@ -668,4 +650,6 @@ bun run format # Format
- Application - AGPL-3.0-only: [LICENSE](./LICENSE)
- Core library `@sriinnu/tokmeter-core` - MPL-2.0: [packages/core/LICENSE](./packages/core/LICENSE)

Release artifacts include the license texts and source snapshot. See [licenses and source](docs/licensing.md) for scope, bundled notices, and build instructions.

Copyright (c) 2026 Srinivas Pendela.
16 changes: 16 additions & 0 deletions docs/assets/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Synthetic-data walkthrough

`tokmeter-demo.mp4` is a 20-second walkthrough rendered from the production SwiftUI `HeroHeader` and `UsageOverview` views. It is not a screen recording of a live customer session.

The four scenes show an idle day, normal usage, a missing price, and tool-reported cost. The amounts and projects are synthetic; the generator reads no local session files or credentials. The scene captions and demo footer are presentation overlays in the renderer, not controls in the app.

Reproduce from the repository root on macOS with Xcode, Bun, and FFmpeg:

```sh
bun scripts/generate-demo.ts
bunx biome format --write docs/assets/demo/snapshots.json
TOKMETER_DEMO_DIR="$PWD/docs/assets/demo" swift test --package-path packages/macos-bar --filter DemoRenderTests
ffmpeg -y -framerate 1/5 -i docs/assets/demo/scene-%02d.png -c:v libx264 -r 24 -pix_fmt yuv420p -movflags +faststart docs/assets/demo/tokmeter-demo.mp4
```

Inspect every PNG for clipped text and missing controls before replacing the public assets. Rendering must use the same production views as the app; do not retouch a screenshot to imply functionality that the build does not have.
Binary file added docs/assets/demo/scene-00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/demo/scene-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/demo/scene-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/demo/scene-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading