Skip to content
EN中

Token usage

agent-presence usage reports token consumption per source, in the spirit of ccusage: it does not hook the agents, it scans their local transcripts after the fact.

agent-presence usage # today + last 7 days
agent-presence usage --days 7 # a single window
agent-presence usage --json # structured output

Windows are calendar-day aligned (since local midnight, inclusive of today). 今日 counts from 00:00 and resets at midnight — it never shrinks mid-day the way a rolling 24h window would.

Usage is a capability of the same source table that drives presence: every built-in except dsh is decoded from its local transcripts by @rivus/agent-kit, and a third-party source plugin can scan its own.

Source Token tracking
Claude Code yes — decoded per model request, deduped by request id, <synthetic> excluded; priced from the table
Codex yes — decoded per model call, each record priced with its rollout’s own service tier
Pi yes — uses the cost Pi records
opencode yes — reads the local SQLite store (legacy JSON store only when no database exists); uses the cost opencode records
Gemini CLI yes — reads the local chat transcripts under $GEMINI_CLI_HOME/.gemini/tmp; priced from the table
Grok yes — decoded per completed turn, with the cost Grok logged
dsh yes — the managed dsh plugin reports each model call’s usage in real time; priced from the table

Each decoder decides when a record is complete: Claude Code reports a request once four newer requests have been written in its conversation lane or the session has been quiet for 30 minutes, and opencode counts a database message once it completes (a quiet database settles its last running messages). Gemini CLI, Pi, and Codex count a request as soon as its record is complete.

The badge adds its own rule on top: it refreshes at a session boundary’s time and, within a day, only that boundary’s source. Requests Claude Code still held at the day’s last Claude boundary therefore count only at the next Claude boundary more than 30 quiet minutes later — when there is none, they stay out of the badge for the rest of the day. agent-presence usage scans to the current time and reports them sooner.

Cost shows n/a for models with no pricing entry; token counts are always exact. Pi, opencode, and Grok log a real cost, so those are used as-is. Other sources are priced from the LiteLLM price table that ships with @rivus/agent-kit (its /cost/prices entry) and updates with each kit version. It covers the chat models of Anthropic, OpenAI, Google Gemini, xAI, DeepSeek, Z.ai, Moonshot, and MiniMax, matched by exact model id or the id with a date suffix. A small fallback table prices ids the table does not name. A suffixed variant of a Claude, GPT-5, or DeepSeek V4 model in the table, such as gpt-5.5-codex, gpt-5.6-high, claude-sonnet-5[1m], or a Bedrock us.anthropic.…-v1:0 id, takes that model’s price. Claude Opus 4, Opus 4.1, and Claude 3 Opus keep their last list price, and other Claude Opus, Sonnet, and Haiku ids take the price of Claude Opus 4.8, Sonnet 4.6, and Haiku 4.5. A new model whose name extends one in the table, such as claude-opus-5-6, takes that older model’s price until a kit update adds it; any other unlisted model, such as a GPT version newer than the table (gpt-5.7), shows n/a. Override pricing per model in ~/.agent-presence/config.json when your deployment uses a private or unlisted model.

dsh is the one source that does not scrape transcripts: agent-presence setup prompts to install a small Cordis plugin into ~/.dsh/plugins/ (registered in the home-level ~/.dsh/cordis.patch.yml, which applies to every profile). The plugin reports each model call’s token usage alongside the presence heartbeat, and agent-presence appends it to a local usage log that the usage command and signature badge read back. Install or remove it any time with pnpm run install:dsh-plugin / pnpm run uninstall:dsh-plugin (or node dist/scripts/install-dsh-plugin.js).

Compose your own label with template variables:

agent-presence config render --many "{total} 个 AI 牛马 | {details} | 今日 {usage_1d}"

{usage_1d} is today; {usage_7d} (or any {usage_Nd}) is N calendar days.

A badge whose window has rolled over renders as —: {usage_1d} after one local midnight, {usage_Nd} after N, and the bare {usage} when its default window rolls over (one midnight unless configured). The usage.showInSignature label is dropped instead. The number returns once session boundaries or agent-presence update have given every built-in source a snapshot for the day. A refresh whose scan fails keeps the previous cache, so the badge stays — until a later boundary or update succeeds. Only this machine renders and writes the signature (after hook events, update, deferred flushes and reset, including the resets macOS power events trigger), so when nothing writes after midnight — the machine is idle, asleep or off — the published signature keeps the last value, including yesterday’s 今日, until the next write.