Skip to content

Usage and session analytics

Usage analytics turn the session data Token Optimizer already collects into answers about how you work: which sessions cost the most, what your compression has saved, which models and skills you actually use, and whether any running sessions have gone stale. Every report reads from the local history database and changes nothing.

Each time a session ends, Token Optimizer parses its transcript and ingests the result into a local SQLite history database (trends.db). Usage analytics query that store. They surface patterns you cannot see from a single session: cost drifting up week over week, a skill that loads on every start but never gets used, a model you reach for more than you meant to.

The analytics split into two jobs. The reporting commands (trends, savings, conversation, pricing-tier) answer “how have my sessions behaved.” The session-health commands (health, kill-stale) answer “are my running sessions in a clean state right now.” Both read data you already have; neither runs the model.

trends reports per-session usage from the history database over a window of days. Each row carries the session’s quality score, cache hit rate, cost, model mix, and the skills it loaded, so a single report shows both your spend curve and what drove it.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py trends # default window
python3 measure.py trends --days 30 # widen the window
python3 measure.py trends --json # machine-readable

Two columns are easy to overlook and worth reading. Model mix shows which models a session invoked, so you can see whether expensive models are doing cheap work. Skill adoption shows which installed skills a session actually loaded, which exposes skills that add startup overhead on every session without earning it.

savings reports the measured token and dollar savings from every active compression feature, kept in three separate tiers so the headline number stays honest.

  • Realized savings are what compression has already saved on real sessions.
  • Estimated savings are modeled where a direct measurement is not available.
  • Opportunity savings are what you could recover but have not, such as prompt-cache expiry waste.

The three tiers are reported apart so an opportunity figure never inflates the realized headline. The report also cross-references savings from subagent dispatch.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py savings # measured, estimated, and opportunity tiers
python3 measure.py savings --days 30
python3 measure.py savings --json

conversation breaks a single session into its individual API calls. Each row shows input tokens, output tokens, cache read and cache write, dollar cost, the model used, and the tools invoked on that turn. This is the view for finding the one expensive turn in an otherwise cheap session.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py conversation # the current or most recent session
python3 measure.py conversation SESSION_ID # a specific session
python3 measure.py conversation --json

Cost figures depend on the pricing tier, covered next.

Every cost and savings figure is computed against a pricing tier. pricing-tier sets which one. Set it to match how you are billed so the dollar numbers in savings, conversation, and trends reflect your real rates.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py pricing-tier # show the current tier
python3 measure.py pricing-tier vertex-global # switch tiers

Accepted tiers: anthropic (default), vertex-global, vertex-regional, bedrock, and subscription. The choice persists in config.json. On a subscription tier, dollar savings read near zero by design, because the plan is flat-rate; subscription users measure value in rate-limit quota instead, through Keep-Warm quota value.

health checks the sessions running on your machine right now and flags the ones that are not in a clean state. It reads process and elapsed-time data; it does not touch the history database.

FlagConditionMeaning
STALEIdle longer than 24 hoursLikely abandoned, still holding a process
ZOMBIEIdle longer than 48 hoursAlmost certainly abandoned
OUTDATEDSession version differs from installedRunning against an older Token Optimizer
TERMINALHas an attached terminalInformational, not a problem
Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py health # flag stale, zombie, and outdated sessions
python3 measure.py kill-stale --dry-run # preview which sessions would be killed
python3 measure.py kill-stale --hours 24 # kill sessions running longer than 24h

health only reports. kill-stale is the action: it terminates sessions older than a threshold that are still marked running. The threshold defaults to 12 hours, and --dry-run shows the kill list without acting.

On demand. Every command here is a read or, in the single case of kill-stale, an explicit action you invoke. None fires automatically except the underlying data collection on SessionEnd, which only populates the database the reports read.

The reports (trends, savings, conversation, pricing-tier, health) are always available and read-only. Data collection that feeds them is on by default for plugin users through the SessionEnd hook. kill-stale never runs on its own.

Platform availability: the reports run anywhere Token Optimizer collects session history. Session health (running-process flags) is most complete on POSIX systems; on Windows without a process creation-time source, sessions are flagged UNKNOWN_AGE rather than mislabeled fresh. See the capability matrix.

Nothing to disable for the reports; they only read history you already have, so to stop seeing them, do not run them. kill-stale only acts when you call it.

To stop the data collection that feeds the reports, remove the SessionEnd data-collection hook. Skill-only users who installed it manually run setup-hook to inspect the hook; plugin users manage it through the plugin. To delete the collected history entirely, use purge. See your data and privacy.

SettingDefaultNotes
Trends/savings windowrecent daysWiden with --days N
Pricing tieranthropicPersisted in config.json
STALE flagidle > 24hReported by health
ZOMBIE flagidle > 48hReported by health
kill-stale threshold12 hoursOverride with --hours N
Savings accountingrealized, estimated, opportunityThree separate tiers
Data collectionon (SessionEnd hook)Backfill with collect --rebuild

None for the reports: they read the local history database and the running process list, and change nothing. Low for kill-stale, which terminates processes; its only failure mode is ending a session you wanted to keep, which --dry-run exists to prevent.

The pricing tier is set with the pricing-tier command rather than an environment variable, and persists in config.json. Dashboard host variables affect where trends render when served. All are defined in the configuration reference.

Reports run on Claude Code, Codex, Copilot, Hermes, OpenCode, and OpenClaw wherever session history is collected. Running-process session health is fullest on POSIX. See the capability matrix.