← Catalog

omp-tokenmunchers

Reports Oh My Pi token usage (metadata only) to your friend group's tokenmunchers leaderboard

Package

Install

Install with PiG

pig install npm:omp-tokenmunchers

Install with Pi

pi install npm:omp-tokenmunchers
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

README

Written by the package's publisher, shown as published in version 0.3.0 (README.md). PiG does not review it.

omp-tokenmunchers

The Oh My Pi plugin that reports per-call token usage to a tokenmunchers leaderboard.

Requires OMP running on Bun 1.3.14 or newer. New users should follow the setup guide.

Install

omp plugin install omp-tokenmunchers

Create an API key on the dashboard's Settings page, then run this inside OMP:

/munch login tm_…

munch install (see the munch program) can do this for you: it installs this plugin and gives it your API key (omp-tm).

/munch is the OMP plugin command. The terminal command munch backfill imports observed Codex or Claude Code history, not OMP history. For OMP history, use /munch backfill inside OMP.

If OMP is routed through the munch proxy and this plugin is enabled, each call is counted twice. munch install prevents this by recording omp_via_plugin, so the omp wrapper from munch env runs omp without the proxy variables.

Commands

Everything is under one command, /munch, with tab completion:

CommandDescription
/munch, /munch statusKey prefix, reporting state, queued events, external usage waiting, last error, "live since" time and gap-fill progress
/munch login [key]Saves the API key (asks for it if omitted) and checks it against the server
/munch pauseStops reporting for this OMP process
/munch resumeResumes after a pause
/munch syncRefreshes OMP's stats database (omp stats) and re-sends recent calls that didn't get through
/munch backfill [--exclude a,b] [--yes]Shows a preview, then uploads daily totals of usage from before this machine started reporting

--exclude skips projects whose name contains any of the comma-separated text. --yes skips the confirmation dialog; it's required when OMP runs without a UI.

0.2.0 replaced /usage-login, /usage-pause, /usage-resume and /usage-status with /munch.

Data sent

Per call (ingest)

FieldDescription
event_idUUIDv5 computed from the call (see Event identity)
session_idOMP session id
tsWhen the call finished (start + duration)
provider, modele.g. anthropic, claude-opus-5-5
input_tokens, output_tokens, cache_read_tokens, cache_write_tokensIntegers
cost_usdCost as OMP reports it (0 on subscription plans)
is_subagenttrue for subagent and swarm calls
client_versionPlugin version

Presence events (session_start, heartbeat) send the session id, provider, model and session start time; session_end sends just the session id.

History import (history)

/munch backfill sends one row per UTC day, provider, model and subagent flag, containing the call count, the four token counts and cost. It also sends a random device id for this install.

Costs in imported history come from OMP's stats database. That database estimates subscription usage at public API prices, so imported days can show a cost where live events report $0.

Never sent

Prompts, responses, code, file paths, repository or project names, tool calls or their output, and the working directory. Both Edge Functions check every request against a fixed list of allowed fields and reject the whole request if it contains anything else.

Behavior

Live reporting

  • Hooks message_end and sends one event per finished assistant message, right away (no batching).
  • Sends session_start on start, a heartbeat every 30 s while a turn runs, and session_end on shutdown. These drive the dashboard's "Live now" strip.
  • Subagent calls (ctx.agent.kind === "sub") are sent with is_subagent: true.
  • Network calls never block the agent: the plugin doesn't wait for them, and each times out after 3 s.
  • Failed usage events are written to queue.jsonl and retried with backoff (1 min, doubling up to 15 min), or immediately after the next successful send. Queued events older than ~7 days are dropped, because the server rejects them.

Event identity

Each event id is a UUIDv5 of the session transcript's file name, the call's start timestamp, the provider and the model. The same call always gets the same id, whether it's sent live, retried, or re-sent from OMP's stats database. The server ignores ids it already has.

Only the transcript's file name goes into the hash, never its directory, because the directory name encodes the working directory. Subagent transcripts are keyed under their parent session.

Pausing

/munch pause records the paused time range for each session in pauses.json. This file never leaves the machine. Gap fill and backfill skip every call inside a paused range, including calls from subagents of a paused session.

Usage from other tools

Some agents call models outside OMP, for example a wrapper script that runs another vendor's CLI from an OMP agent. message_end never sees those calls. Such a tool can report them by appending one JSON line per finished call to external-usage.jsonl in the plugin's folder:

{"v":1,"source":"agy","id":"6322b946-3d6e-4a56-89e4-ea1206abacbf","ts":1795395592000,"provider":"google-antigravity","model":"gemini-4-hydrogen-high","input_tokens":10261,"output_tokens":74,"cache_read_tokens":2048,"session_id":"…","session_file":"…"}
FieldRequiredDescription
vyesFormat version, 1
sourceyesShort lowercase name of the tool (letters, digits, -, _; up to 32 characters)
idyesThe call's unique id from that tool, up to 128 characters. It keys the event id, so a call written twice is stored once.
tsyesWhen the call finished: ms since the epoch, or an ISO 8601 string
provider, modelyesSent as-is, so use the names the dashboard already shows for that provider
input_tokens, output_tokens, cache_read_tokens, cache_write_tokensnoIntegers; missing ones count as 0. Lines with no tokens are dropped.
cost_usdnoDefaults to 0
session_idnoOMP's PI_SESSION_ID from the tool's environment. Without it, the session id is external-<source>.
session_filenoOMP's PI_SESSION_FILE. Used only on this machine, to apply /munch pause windows and set is_subagent, the same way as for OMP's own calls. It is never uploaded.

Every minute (and when a session starts), a non-paused OMP process moves the file aside, turns each valid line into a normal usage event, and adds it to queue.jsonl, so delivery, retries and the ~7-day limit work exactly as for live calls. Invalid, unreadable or too-old lines are dropped. The event id is a UUIDv5 of external|<source>|<id>. /munch status shows how many lines are waiting.

Writers should append whole lines and never rewrite the file. A drain that crashes leaves an external-usage.*.draining file, which the next drain picks up after 5 minutes.

Gap fill and backfill

OMP indexes every session into a local SQLite database, stats.db. omp stats (run by /munch sync) keeps it up to date. The plugin opens it read-only and reads only these columns: id, session_file, folder, timestamp, duration, provider, model, the four token counts, cost_total and agent_type. folder is used only for the backfill preview and --exclude, and is never uploaded. Error messages, prompts and tool data are never read.

state.json records for this install: a random device id, live since (the time of the earliest call this machine delivered live), and how far the gap fill has scanned. Calls before "live since" belong to the history import; calls from then on are reported live. So the two never overlap.

(blank)Gap fillBackfill
TriggerAutomatic, every minute; or /munch sync/munch backfill
CoversCalls after "live since" from the last ~6.5 daysEvery call before "live since"
SendsNormal usage events with the same ids, which the server ignores if it already has themDaily totals, which replace this device's previous upload
LimitsUp to 400 calls per minute, one OMP process per machine at a timeWaits until queued live events are delivered

Upgrading from 0.1.0. 0.1.0 didn't record when a machine started reporting live. So an upgraded install asks the server for the account's first live event and uses that as "live since". If several machines ran 0.1.0, they all get the account's earliest date. Any machine's usage between that date and its own first live event isn't imported. Gap fill also skips the 0.1.0 period, since there are no pause records for it.

Configuration

Config is stored in <agent dir>/tokenmunchers/config.json (file mode 600). Environment variables override the file:

VariableDescription
TOKENMUNCHERS_KEYAPI key
TOKENMUNCHERS_URLIngest URL (defaults to the group's Supabase project). The history URL is derived from it.
TOKENMUNCHERS_STATS_DBPath to OMP's stats.db, if it isn't found automatically

Files

All in <agent dir>/tokenmunchers/ (usually ~/.omp/agent/tokenmunchers/). None of them is ever uploaded.

FilePurpose
config.jsonAPI key and endpoint
state.jsonDevice id, "live since" time, gap-fill progress
pauses.jsonPaused time ranges per session
queue.jsonlUsage events waiting to be retried
external-usage.jsonlCalls logged by other tools, waiting to be queued (see Usage from other tools)
gapfill.lockLets only one OMP process gap-fill at a time

Development

npm install
npm test            # adapter, retry queue, pause log, gap fill and history tests
npm run typecheck   # against @oh-my-pi/pi-coding-agent 18.6.1 types
FileResponsibility
index.tsLifecycle hooks and the /munch command
src/adapter.tsOMP message → event conversion, event ids, session keys. The only file that knows OMP's message format.
src/stats.tsRead-only access to stats.db. The only file that knows its schema.
src/transport.tsSending, retry queue, history client
src/sync.ts, src/syncer.tsGap fill and history import
src/state.ts, src/pauses.ts, src/config.tsLocal files

If an OMP release changes its message format or its stats database, the fix goes in adapter.ts or stats.ts.

Releasing

  1. Bump version in package.json and CLIENT_VERSION in src/adapter.ts.
  2. Deploy any server changes first (see the Supabase README).
  3. npm test && npm run typecheck
  4. npm login (as a maintainer), then npm publish.

License

MIT