Tokmeter reads local usage records and keeps daily summaries. It does not inspect your subscription invoice or reconcile charges with a billing account.
Tokens
Input, cached input, cache writes, visible output, and reasoning are separate ledger buckets where the source provides enough information. Codex includes cached input within input, and reasoning within output; Tokmeter separates those buckets before summing them.
New Codex response receipts are preferred within a covered turn. Mirrored cumulative events are excluded, repeated response IDs are deduplicated, and a subagent’s replay of a parent receipt is excluded. Older turns still use their cumulative counters.
Cursor’s local database gives one record per request. Each user message opens a request, and the messages after it, in time order, belong to it. The model comes from that user message, so a conversation that switches models is split correctly. Each later message that carries a token count is its own record, with the model, project and request id of that user message. A conversation with no user message gives each counted message the model unknown. Some requests have no count at all; each scan says how many, and they aren’t guessed. Cursor’s input count is the size of the context when the request was made, not billed input, so it’s marked estimated. Cursor keeps no cache split. Auto mode is logged as cursor-auto, because Cursor doesn’t say which model ran. Until this fix, every request in a conversation got the first model seen in it.
Some tools expose only an activity signal or a lifetime token total. Tokmeter does not invent an input/output breakdown to attach a dollar cost. See coverage and verification.
Cursor’s stop hook
Cursor’s local database often holds no token counts for a turn. tokmeter cursor-hook install adds a stop hook to ~/.cursor/hooks.json that records the counts Cursor itself hands over when a turn ends. It needs no login, key or cookie. Other hooks in that file are kept, and tokmeter cursor-hook uninstall removes only tokmeter’s entry.
Each finished turn adds one line to ~/.tokmeter/cursor-turns/YYYY-MM-DD.jsonl. A line holds the conversation and generation ids, the model, the status, the four counts (input, output, cache read, cache write), Cursor’s version and the first workspace folder. It never holds message text or your email. A turn that ends without usage, such as an error or an abort, still gets a line with its status, so tokmeter can say how many turns had no counts.
Recorded now, counted later. The hook’s numbers haven’t been checked against a live turn yet. Two things are open: does input_tokens include cache reads, and are the counts for the whole turn or only its last step? Until that is settled the hook runs in shadow mode. It records every turn, but the totals come from Cursor’s local database alone, and the ledger below is not read. Each scan says how many turns the hook recorded and how many had usage. tokmeter cursor-hook status lists today’s turns and sums their input, output, cache read and cache write, so a live turn can be compared with what Cursor shows.
The ledger. Install and uninstall are written to ~/.tokmeter/cursor-turns/coverage.jsonl. The ledger, not hooks.json, says whether the hook is installed:
- Install adds “installed” only when no span is open, so a reinstall never moves the start.
- Uninstall adds “uninstalled” whenever a span is open, even if tokmeter’s entry was already removed from
hooks.jsonby hand. - Lines are read in the order they were written, not sorted by time. An event dated earlier than the one before it (a clock that stepped back) is moved up to that time, so spans never overlap.
- A missing ledger means the hook was never installed. A ledger or journal that exists but can’t be read fails the Cursor scan, so the day isn’t sealed on a guess.
Which source counts a turn, once verified. While the hook is installed, its turns are Cursor’s usage and the database’s counts for that time are left out; outside those times the database’s counts are used. The split is decided by when the hook was installed, never by which source showed up first, so a turn’s source never changes later. Tokmeter keeps today’s records as it goes, and one that vanished from a file still on disk would be kept as deleted history and counted twice. A hook line written outside an installed span isn’t used.
Limits:
- Only turns that end after the install are recorded. Earlier turns can’t be recovered this way.
- Cursor gives no reasoning count, so reasoning is not shown separately.
- Cursor gives no cost. Cost is estimated from the counts, like any other agent.
- Subagents end with a different event that carries no counts. Whether a parent turn’s counts include its subagents isn’t known yet.
- The same generation id counts once. A repeat of a conversation’s last counts under a new id counts once too, but only when it lands within 10 seconds of the line before it. Two real turns are further apart than that.
- If
~/.cursor/hooks.jsonis a symlink, its target is written and the link stays. If the file changes while tokmeter is updating it, nothing is written.
Costs
| Display | What supports it | What it does not establish |
|---|---|---|
| Estimated API cost | Token buckets multiplied by catalog or local override rates | Your subscription payment or invoice |
| Tool-reported cost | A numeric cost exposed by the local tool | That the provider actually charged that amount |
| Unavailable | Missing rates, missing breakdown, skipped pricing, or absent provenance | That usage was free |
An explicit zero from the tool or a known zero pricing rate is retained. Two zeros are treated as reported rather than unavailable because they are facts: an OpenCode response on an explicit free tier (-free / :free model, which OpenCode’s own catalog prices at zero), and a custom-source response served by a local runtime (Ollama, LM Studio, llama.cpp, MLX). A coding-plan or subscription zero is not one of these; it is still estimated at API rates. Missing optional cache-read rates currently fall back to 10% of input; reasoning uses output rates unless a dedicated rate exists. Cache writes made with the 1-hour TTL (Claude Code reports the split per response) are billed at the registry’s cacheWrite1hPerMillion when present, else at 2× input when the model id contains claude — Anthropic’s published 1h rule — and at the ordinary write rate otherwise. Anthropic models logged without claude in the id (for example fable-5-1) therefore currently get the ordinary write rate for their 1-hour writes, which understates those writes. These are estimation rules, not provider billing guarantees. Long-context tiers, service tiers, negotiated discounts, and other fees are not fully modeled by the current calculator.
Tokmeter uses kosha’s catalog and optional ~/.tokmeter/pricing-overrides.json overrides. A gateway’s rate can be used when a usable origin rate is absent. This is another reason to read the result as an estimate.
A model whose provider hides the model behind it shows “—”, not $0.00 (since 1.19.7). Codex’s approval reviewer is logged as codex-auto-review; OpenAI doesn’t say which model runs it, so there is no rate to bill it at. Its cost is counted as zero and marked unavailable, and it never trips the unpriced warning. To estimate it anyway, name the model to price it as in the overrides file, { "codex-auto-review": { "as": "gpt-5.6-luna" } }, and it is billed at that model’s live catalog rate. Editing the file reprices today; sealed days keep their cost. The target is looked up as itself, never through another as.
The same model is priced at the rate of whoever served it (since 1.18.0). OpenCode, Kilo and Kilo CLI route one model through many providers and write the provider beside the model, and the rate differs a lot by route: on 2026-11-04 kosha’s saved catalog listed DeepSeek V4.1 Flash at $0.15/$0.60 per million on Ollama Cloud, $0.30/$1.19 on Alibaba and $0.016/$0.89 on OpenRouter. These change; tokmeter pricing <model> shows today’s. Their model ids now carry the route, as model@provider, so breakdowns keep the routes apart and a response the tool didn’t price is billed at that provider’s own catalog rate; failing that, at the model’s rate as before. Costs the tool reported itself are unchanged. An override can name the route ("deepseek-v4.1-flash@ollama-cloud"). Which upstream OpenRouter picked for a call isn’t written anywhere on disk, so OpenRouter routes are priced at OpenRouter’s list rate.
Today exposes cost provenance in /api/statbar-signals: the estimated and reported amounts, unavailable count, and per-model breakdown. Model/project cost totals may combine different bases. Existing historical rollups do not contain enough provenance for a reliable retrospective split, so normal refreshes retain their original values.
DeepSeek is billed by the time of each response (since 1.20.1). DeepSeek charges half price outside 01:00–04:00 and 06:00–10:00 UTC on weekdays. Each response is priced at the rate of its own timestamp, so two responses in one day can bill differently. A projection has no timestamp, so it uses the peak rate. Chinese public holidays are also off-peak for DeepSeek, but that calendar isn’t modelled, so a weekday holiday bills at the peak rate during peak hours. Kosha curates these rates and windows by hand.
Free models
A model whose id ends in -free or :free reads as free when its cost is $0, and the menu bar labels it free with its token count. Any other $0 stays unavailable, shown as “—” or “n/a”, because a catalog’s $0 often means nobody listed a price. Subscription plans that list $0, like zai-coding-plan, and GitLab’s Duo aren’t treated as free. Some other catalog providers list every model at $0, and the catalog alone can’t say whether that’s real. Kosha tags those free, but Tokmeter still only takes the -free and :free ids at $0.
An embedding or rerank model has no output, so a catalog rate for its input alone is its whole price, and its usage is billed at it. Before, any rate without an output price was dropped, so embedding usage counted as $0 and the model was reported unpriced. That holds for the id itself and its plain variants (case, dots for hyphens, a date suffix), never for the loose name match, so a chat model can’t be billed as an embedding model. A saved-catalog row marked chat with no output rate still has no price, even when it’s really a reranker; name its price in the overrides file. Kosha’s live lookup resolves names more loosely, so it can price such an id from the embedding row it maps it to.
A -free or :free route is billed at its own $0 row even when the same provider also sells the plain model: kimi-k2-6:free@kenari used to be billed at kenari’s paid kimi-k2-6, because the lookup dropped the tag before it checked for a free row. A free id with no $0 row anywhere, like deepseek-v4-pro:free@kenari or a bare gpt-5.4:free, has no price: it counts as $0 and shows as unpriced. It used to be billed at the paid model’s rate, which charged for a call that was free.
tokmeter pricing <model> gives one of three answers, the same ones billing uses: a price and where it came from, free (a -free or :free model on its route, like beam-free@opencode, or a $0 override), or no price, which counts as $0 but is a gap rather than a fact. With --json it prints status as priced, free or unpriced, plus the source.
Where prices come from, and when one is held back
Kosha 1.13.0 takes prices from models.dev, LiteLLM and, when it has a key, the provider’s own API. Tokmeter doesn’t give it keys. Providers with their own discovery go in ~/.kosha/registry.json. The rest go in ~/.kosha/catalog-only.json, and Tokmeter reads that file only for a lookup that names its provider, like beam-free@opencode. A bare model name is never priced from it, so a gateway’s rate can’t land on a model you never ran through that gateway.
A price that moves by 75% or more is held at its old value for a while:
| What the sources say | How long it’s held | Flag afterwards |
|---|---|---|
| Two or more agree | 1 day | None |
| Only one lists the model | 3 days | pricing_single_source |
| They disagree by more than 5% | 7 days | pricing_sources_disagree |
| A billed rate falls to $0 | Never accepted | Stays held |
A change in the published rates restarts the wait. A smaller move takes effect at once, and it’s flagged if the sources disagree. The $/M panel in the menu bar says when a price is held back, disputed, or rests on one source.
What this doesn’t catch. Planted prices through real discovery on 2026-11-04 showed:
- A lie under 75% from a lone source goes through at once with no flag.
- A bigger lie from a lone source is accepted after 3 days, with a flag.
- Two catalogs agreeing on the same lie are accepted after 1 day.
Only 174 of 3,419 models in that day’s registry (5%) had a second source, so most prices rest on one catalog’s word. A hold narrows the risk from a bad catalog without closing it. A day seals with the price it was billed at, so a bad price that gets through stays in that day.
Cursor sync (opt-in)
Cursor keeps most of its usage on its servers. Tab completions, cloud agents, other machines and the cost Cursor billed never reach a local file, so a local scan can’t count them. tokmeter cursor sync is the only way Tokmeter gets them, and it is off unless you run it. Nothing runs it automatically: not the daemon, not a scan, not the menu bar.
What is sent where. It reads the session the Cursor app already holds (cursorAuth/accessToken in Cursor’s state.vscdb), read-only, at the moment you run it. It sends that session as a cookie to one endpoint, GET https://cursor.com/api/dashboard/export-usage-events-csv, once per UTC calendar month from the month holding --since (default 90 days ago) to now, and nowhere else. Redirects are refused, so the cookie can’t be sent anywhere else. It never refreshes the session, never writes Cursor’s files and never stores the session; an expired one is refused and you sign in to Cursor again. The session, the cookie and any email are scrubbed from every message it prints. --dry-run sends nothing and reports only whether a session exists and how many hours it has left.
What it keeps. Each month’s export is written owner-only to ~/.cache/tokmeter/cursor-usage/usage-YYYY-MM.csv. Months are fixed, so a later run rewrites the same files. A re-download never replaces a file with fewer rows. A download over 64 MB is cut off while it streams, and nothing is written for that month.
How the rows are counted. The export’s two Input columns are separate buckets: “Input (w/ Cache Write)” is cache write, “Input (w/o Cache Write)” is plain input, and their sum with Cache Read and Output equals Cursor’s Total Tokens on every real row published by tokscale. Total Tokens is a check, never added. A numeric Cost is Cursor’s own figure (tool-reported); “Included” is left to the normal estimate; a row Cursor marked errored or not charged keeps its tokens at cost 0. Rows repeated across files are counted once, and the file written last wins, so a later download’s settled cost replaces an older one. The parser exists and is tested, but the scan doesn’t read these files yet. An export covers time after the fact, so letting it take over a stretch the local sources already counted would make Tokmeter count those records twice; it needs its own place in the ledger first.
Plan quota
tokmeter quota, the daemon’s /api/quota and the menu bar’s Plan quota section show each plan window’s used %, its reset time and whether the current pace reaches 100% before the reset. These are the vendors’ own meters, not tokens, and never feed a token or cost total. Each reading is stored in ~/.cache/tokmeter/quota/<agent>.jsonl; a window keeps its highest reading, and only the newest window per agent and length is shown. A window whose reset time has passed shows as expired, never as its last %.
- Codex: the 5-hour and weekly windows in the tails of its newest session files.
- Claude Code: the 5-hour and weekly windows the statusline is handed. Claude Code writes them nowhere else, so they exist only if the tokmeter statusline is installed.
- Grok Bot: the weekly used %, reset time and plan name from the app’s weekly-usage cache in
~/Library/Application Support/Grok Bot/sand-client-persistence/. Only the file names in that folder are decoded, to find that one cache; no other file there is opened, and the account id in the name is never stored or printed. The cache gives the reset time but not the window length, so the 7-day length is inferred from xAI describing a weekly allowance. With several signed-in accounts, the most recently read cache wins. A cache in an unknown format gives no reading and a notice. Grok Bot’s transcripts have no token, model or cost fields, so this meter is all Tokmeter shows for Grok Bot: a vendor plan meter with no token data.
Claude Duet has no meter of its own. It draws on the same account-wide Claude weekly window that Claude Code reports: the weekly figure in the Claude app’s plan-usage history matched the statusline’s 7-day % within one point at two readings on 2026-11-16 (45% vs 44–45%, and 52% vs 51–52%).
History and corrections
Completed days are stored in the local relay. Normal refreshes update today’s usage and read saved history. Only today is repriced when the price catalog updates; since 1.15.0, editing ~/.tokmeter/pricing-overrides.json also reprices today. Completed days keep the cost they were sealed with. A deliberate rescan can rebuild a bounded historical window; retention guards protect against replacing a day with incomplete input. Back up a day before applying a reviewed correction.
Each day keeps the prices it was billed at (since 1.17.0). The price catalog keeps no history: it is overwritten on every refresh. So a rescan used to bill a past day at the rates of the day the rescan ran, and a day could change cost without one token changing. Each sealed day now stores the rates every model was billed with, and a rescan bills that day with them. A day sealed before 1.17.0 has no stored rates; a rescan derives them from what the day cost, scaling today’s rates so the day’s own tokens cost exactly what was sealed. Those derived rates are marked “implied”. A model the day had no rate for (new in the rescan, or unpriced back then) is billed at today’s rate. Costs a tool reported itself are never repriced.
A deleted or archived thread stays in the day it ran in (since 1.17.1). Today is recounted from the session files on disk every few seconds, so deleting a thread before midnight used to take its usage out of the day, and that smaller day was what got sealed. Tokmeter now keeps the last usage of any file, or database thread, that disappears today and counts it until the day seals, including across a restart and when the daemon was off at midnight (it reads what it kept, in ~/.cache/tokmeter/today/). Moving a file, as a Codex archive does, isn’t counted twice. Usage already lost before 1.17.1 can’t be recovered this way. Since 1.18.0, a file rewritten smaller in place (a transcript pruned by hand) also keeps what it lost, for tools whose responses carry the provider’s own id (Claude Code, Codex, Kimi, Copilot CLI, Muse); tools that number responses by position or not at all (Cline, Roo, Kilo, Gemini, Qwen) are still taken as they are, because a renumbered response would look like a lost one. A rebuild or Deep Rescan of the past week folds the kept usage in too.
Zed and Mux count each day’s growth (since 1.17.1). Both report a running total per thread. Tokmeter used to count the whole total on the day the thread was last used, so reusing a long thread added its history again. It now counts only what the thread added that day. A thread it sees for the first time counts from then on, unless it was created that day.
A day that may be missing usage is flagged (since 1.17.0). A day can only hold what the parsers read. After a day seals, the daemon looks through each tool’s whole data folder for session files that changed that day, contain a real token count, and fed nothing into the ledger, and warns if it finds any. This is how a tool changing where it writes (Codex moving finished sessions to ~/.codex/archived_sessions in October 2026) shows up the next morning instead of weeks later. It does not recount tokens. Run it for any day with tokmeter coverage --date YYYY-MM-DD.
Invariants
These hold the accounting together. Breaking one produces numbers that look plausible and are wrong, which is the failure mode this project cares most about.
One record per API response. Providers do not write one line per call.
Claude Code writes an assistant turn as a separate JSONL line per content block
— thinking, text, and each parallel tool call — all sharing the response’s
usage. Deduplicate on the provider’s own per-response identifier (message.id
for Claude Code, payload.response_id for Codex), never on a timestamp: every
line carries its own.
A record’s time never comes from the clock. Today is rebuilt from each scan, and a session file that changes is parsed again. A line with no usable timestamp used to be stamped with the time of the scan, so it sat on whatever day its file was last read: counted that day, sealed into it at midnight, then counted again on the next day the file changed. Such a record now takes the session’s time where the tool writes one, else the time of the line before it in the same file, else when the file was created, plus 1 ms per such record in a row so identical ones stay apart. Each scan reports how many it dated this way, and how many of those fell on an earlier day. That’s the limit: a record whose inferred day has already been sealed is counted nowhere, since sealed days only grow from that day’s own late records. A session resumed days later whose next line has no time is dated by the old line before it, so it hits this. A file saved by replacing it (written elsewhere, then moved over) gets a new creation time, which moves only a record with no timed line before it. Today’s tools write a time on every usage line, so in practice this is a guard.
Usage is not uniform across a turn’s lines. Subagent transcripts open with a placeholder usage record and only the final line carries real counts. Keep the maximum per bucket across a response’s lines rather than the first value seen, and re-price a record whose counts grow.
Sub-buckets are subsets. The 1-hour share of cache writes is part of the cache-write total, not an additional bucket. Adding a subset into a total counts the same tokens twice and inflates every downstream percentage.
A sealed day keeps its prices. A rebuild bills a day with the rates stored on it, never today’s. A day’s cost changes only when its tokens do.
Sealed days are immutable. The per-day relay files are the durable ledger precisely because raw session files age out — for some providers within days. A rebuild may grow a sealed day; shrinking one requires an explicit forced rescan. A day whose raw source is gone can never be recomputed, so a forced rescan over it destroys rather than corrects. Back up before any repair.
Verify against an independent oracle. Never confirm Tokmeter’s output with Tokmeter. Build a separate ledger directly from the raw session files, deduplicated on the provider’s response identifier, and compare. A shrinking total is not evidence of data loss when a parser bug for that provider was just fixed — it may be the correction.
Bump CACHE_VERSION in packages/core/src/parsers/utils.ts whenever a
parser changes how tokens or cost are derived. Cached records from the previous
logic otherwise survive the fix and keep serving the old numbers.
Reporting a mismatch
Send the app/agent version, local date and timezone, model, expected token count, displayed token count, and whether the source is CLI or desktop. Start with those numeric facts. Do not upload a whole session transcript, database, API key, or credential file.
Something wrong or out of date? This page is generated from its source on GitHub, at the revision this site was checked against.