All plugins

token-lens

Token consumption analytics for Hermes: records exact per-call usage from pre/post_api_request hooks, decomposes every request into categories (system prompt, built-in and per-MCP-server tool schemas, skills, memory, history, tool results, output, reasoning) calibrated to billed totals, and adds a Token Lens dashboard tab plus a Sessions-page card with deterministic and AI-evaluated token-reduction suggestions; hermes token-lens refresh runs a suggestion refresh from the CLI. Disclosure — records per-API-call token counts (no message text) from pre/post_api_request hooks into token_lens.db at the Hermes home root (per-call rows kept 90 days, rollups kept), and reads Hermes's state.db read-only for session token totals and, during the optional dashboard history import, message text for estimation only; after 10 recorded sessions it automatically calls your configured main model through Hermes's plugin LLM facade every 5 sessions (up to two calls per refresh, capped at 50,000 tokens by meta_budget_tokens), sending aggregated token statistics plus the names of your enabled MCP servers and plugins, and auto-applies the model's proposed category regex rules and rubric changes (logged to token_lens.EVOLUTION.md; evolve_rules: false turns this off); the dashboard's refresh button spawns a detached hermes token-lens refresh process that logs to logs/token-lens-refresh.log; its data paths follow the HERMES_HOME environment variable rather than the active profile, so in a multi-profile gateway every profile records into the launch profile's database; no third-party network calls, no telemetry.

patrickluvsoj7Generalv0.1.0Updated 29 days ago

About

Token consumption analytics for Hermes: records exact per-call usage from pre/post_api_request hooks, decomposes every request into categories (system prompt, built-in and per-MCP-server tool schemas, skills, memory, history, tool results, output, reasoning) calibrated to billed totals, and adds a Token Lens dashboard tab plus a Sessions-page card with deterministic and AI-evaluated token-reduction suggestions; hermes token-lens refresh runs a suggestion refresh from the CLI. Disclosure — records per-API-call token counts (no message text) from pre/post_api_request hooks into token_lens.db at the Hermes home root (per-call rows kept 90 days, rollups kept), and reads Hermes's state.db read-only for session token totals and, during the optional dashboard history import, message text for estimation only; after 10 recorded sessions it automatically calls your configured main model through Hermes's plugin LLM facade every 5 sessions (up to two calls per refresh, capped at 50,000 tokens by meta_budget_tokens), sending aggregated token statistics plus the names of your enabled MCP servers and plugins, and auto-applies the model's proposed category regex rules and rubric changes (logged to token_lens.EVOLUTION.md; evolve_rules: false turns this off); the dashboard's refresh button spawns a detached hermes token-lens refresh process that logs to logs/token-lens-refresh.log; its data paths follow the HERMES_HOME environment variable rather than the active profile, so in a multi-profile gateway every profile records into the launch profile's database; no third-party network calls, no telemetry.

Token Lens

Token consumption analytics + reduction suggestions for Hermes Agent.

Core Analytics tells you how much you spend. Token Lens tells you where the tokens go and what to change — every category bucket calibrated so it sums exactly to your billed totals, and every suggestion shipped with evidence and a copy-paste plan executable in a Hermes chat.

Token Lens tab — suggestion work surface with waste map

The entry card on your Sessions page leads with the findings:

Entry card on the Sessions page

Install

git clone https://github.com/patrickluvsoj/hermes-token-lens ~/.hermes/plugins/token-lens
hermes plugins enable token-lens

Then — both restarts are required:

  1. Restart the dashboard (hermes dashboard): plugin API routes mount only at startup. The rescan endpoint refreshes UI discovery only.
  2. Restart any running gateway / CLI session: recorder hooks load at process start. Until you restart, Token Lens records nothing (the dashboard will show a "Token Lens isn't recording" banner if it detects this).

Open the dashboard → Token Lens tab. With zero data you'll get a first-run screen offering to import your last 30 days of history (estimated attribution, honestly badged).

What you get

  • Where tokens go — per-call capture of exact billed usage, decomposed into stable categories: system prompt, tool schemas (built-in / per-MCP-server), skill loading, memory, history, tool results, output, reasoning. Estimated buckets are rescaled per API call so they sum exactly to billed prompt tokens.
  • Suggestions — deterministic detectors (unused MCP servers, low cache hit rate, oversized system prompt, runaway turns) fire after 3 recorded sessions; AI-evaluated suggestions unlock at 10. Every suggestion: evidence, expected savings, capability-risk note, copy-paste plan.
  • Acted-on tracking — mark a suggestion done and Token Lens shows predicted vs observed change (per-session category average, labeled "change since acted").
  • Honest data — exact vs estimated precision badged everywhere; backfilled history hatched; calibration drift monitored in /health.

Config (~/.hermes/config.yaml → plugins.entries.token-lens.*)

KeyDefaultMeaning
min_sessions10sessions before AI suggestions unlock
detector_min_sessions3sessions before deterministic findings show
refresh_every5new sessions between suggestion refreshes
max_suggestions_shown5display cap
score_threshold6evaluator gate (0–10)
evolve_rulestrueallow category mapping-rule evolution (logged to EVOLUTION.md)
backfill_window_days30historical import window
meta_budget_tokens50000hard cap per suggestion refresh
recorder_enabledtruemaster switch for the hook recorder
retention_days90per-call row retention (rollups kept forever)

Uninstall

hermes plugins disable token-lens
rm -rf ~/.hermes/plugins/token-lens ~/.hermes/token_lens.db

No core residue beyond the plugin's own DB file.

Development

~/.hermes/hermes-agent/venv/bin/python -m pytest    # run tests

Architecture: two processes share ~/.hermes/token_lens.db (WAL). The recorder (__init__.py) runs agent-side via hooks and never blocks the conversation loop (fail-open + circuit breaker). The dashboard API (dashboard/plugin_api.py) runs in the dashboard process. Shared logic lives in token_lens_core.py.

README from the reviewed commit a6f20c2; it updates when the author re-pins.

Developer Mode

Explore built-in Hermes toolsets and actions.

HermesAgent

Developer?

Create a Hermes extension for Desktop or agent workflows.

Developer Section