trs stats: token savings dashboardEvery trs invocation logs an entry to ~/.trs/history.jsonl:
timestamp, command, input bytes, output bytes, duration. trs stats
reads that log and produces a dashboard of cumulative savings.
The active file rolls into a month-stamped archive
(~/.trs/history.YYYY-MM.jsonl) at the first append of each new month.
trs stats reads the active file plus every archive transparently, so
your cumulative numbers don’t reset. Use trs history --prune
--older-than 90 to retire archives older than your retention window.
trs stats --history lists commands newest first (top of output is
the most recent run). Same ordering in --json mode.
trs stats # summary dashboard (top 15 commands)
trs stats --history # per-command log (most recent 20)
trs stats -n 30 # override row cap (top 30 in summary, last 30 in --history)
trs stats --by-agent # breakdown by which AI agent triggered the run
trs stats --by-command # breakdown by normalized command family (e.g. "git diff", "npm run lint")
trs stats --coverage # parser-gap analysis (what compresses well, what falls through)
trs stats --days 7 # scope every view to the last N days
trs stats --json # machine-readable summary (combines with any of the above)
Two questions live in this command, and they need different windows:
Period, Total commands
and Tokens saved cover the whole history. A running total is not
distorted by one bad day; it only grows.Last 7 days / Last 30 days
lines and the efficiency bar track the last 30 days.That split exists because of a real incident: two aws s3 --recursive
calls pushed 367 MB through at 0% in one afternoon and dropped the
lifetime efficiency ~14 points. A cumulative mean never forgets, so for
weeks it reported a three-week-old event as today’s performance while the
actual weekly numbers ran at 81-86%.
--days N overrides the window everywhere, including --coverage:
trs stats # lifetime totals, bar on the last 30d
trs stats --days 7 # every line scoped to 7 days
trs stats --coverage --days 90 # widen the gap analysis
--coverage defaults to 30 days for the same reason: after a parser
ships, the bytes it used to waste are still in the history forever. A
to-do list that never forgets stops being a to-do list.
trs Token Savings
===================================
Period: Apr 15 23:04 → Aug 26 18:24 (133 days)
Total commands: 69523
Input tokens: 313.8M
Output tokens: 204.3M
Tokens saved: 109.5M (34.9%)
Tokens per day: 823.0K (avg)
Today: 6.7M saved across 468 commands
Last 7 days: 11.9M saved · 94%
Last 30 days: 32.8M saved · 82%
Efficiency: ████████████████░░░░ 82% (last 30d)
Last: git diff origin/main..HEAD (2m ago)
Top Commands
───────────────────────────────────
cargo test 91x -99% 95k saved
git status 203x -76% 42k saved
cargo clippy 34x -89% 38k saved
…
For full history: trs stats --history
The first block is cumulative and answers “was this worth installing?”.
The Last 7 days / Last 30 days lines and the efficiency bar answer
“is it healthy now?”, which is a different question with a different
window (see Time windows above). The lifetime
percentage sitting well below the recent one, as it does here, is the
normal shape after a bad day early in the history: the cumulative mean
never forgets it.
Failed runs and runs over 30 KB raw are left out of the totals (the line
under the table says how many). A Saved-output pointers line counts the runs
that printed [trs] full output: <path> and the shell commands that later read
a saved file; a read through the agent’s own file tool is not visible, so the
second number is a lower bound.
Two more lines come from the same local history, no new hook:
Same command rerun within 120 s: how often the next command in a directory
repeats the previous one, after a cut of 50% or more against after a cut
under 10%. A fixed compression that makes the agent ask again can cost more
than it saves, so the two rates are shown together (shown from 20 runs each).
A rerun after an edit (tests) is normal; compare the two numbers, not the
absolute one. It is an
association, not a cause: heavy cuts happen on builds and tests, which are
rerun anyway.Failing command repeated right after failing: the same failing command
run again in the same directory within 120 s.trs stats --history # last 20 (default)
trs stats --history -n 50 # last 50
Shows the most recent commands (default 20, override with -n):
Recent Commands (today: 23 commands)
────────────────────────────────────────────────────────────────
Apr 20 16:40 trs git status 124 -> 104 -16% 34ms
Apr 20 16:40 trs cargo build 55K -> 58 -99% 4484ms
Apr 20 16:45 cargo build 169 -> 16 -90% 4484ms
…
If a logged command’s first token is an absolute path (e.g. a hook
invoking /Users/you/.local/bin/trs …), the display collapses it to
the basename so you still see what was run. The full path is preserved
in ~/.trs/history.jsonl if you need it.
--by-agent: attribution breakdowntrs stats --by-agent
Shows which AI agent triggered each execution. Added in v0.5.8. It covers
the whole history unless you narrow it with --days N; the Period: line
under the title says which stretch you are looking at.
trs Token Savings: by agent
============================================================
Period: Sep 21 22:48 → Oct 21 19:07 (30 days)
AGENT CALLS SHARE AVG -% SAVED BYPASS
────────────────────────────────────────────────────────────
claude 1247 58.2% 71% 720K 3 (0.2%)
cursor 403 18.8% 68% 190K 0
opencode 210 9.8% 77% 145K 0
gemini 89 4.2% 65% 48K 1 (1.1%)
kilo 12 0.6% 72% 8K 0
(untagged) 182 8.5% 44% 31K 0
Labels come from the TRS_AGENT env var that trs rewrite and the
OpenCode / Kilo plugin templates inject into the rewritten command
before the shell runs it. The shell strips the env-var assignment,
so it’s transparent to git/cargo/etc downstream, and trs’s tracker
picks it up when the rewritten invocation eventually logs.
With --json it prints its own payload, not the summary: total_commands,
period_start, period_end and a by_agent array, one object per row
(agent, count, input_bytes, output_bytes, saved_bytes,
saved_tokens, avg_reduction_pct, bypass_count), sorted by bytes saved.
--by-command --json has the same shape with a by_command array keyed by
command; JSON lists every row unless -n caps it. With no history the
period fields are null. --days N narrows both:
trs stats --by-agent --json --days 7
BYPASS counts how many commands the agent prefixed with
TRS_SKIP=1, those skip trs entirely, so we never see the output
and can’t compress it. The column shows the count plus the rate as
a fraction of the agent’s total calls (3 (0.2%)); 0 is rendered
as a plain zero so the eye skips over the common case.
We log bypass observations even though we don’t see the output, so
the dashboard can answer: “is this agent reaching for the escape
hatch on routine commands?” High rates (>5%) usually mean the
agent’s prompt promotes bypass too aggressively, refresh
~/.<agent>/trs.md via trs output-saver --refresh to ship the
current minimal template.
Bypass entries carry zero in/out byte counts, so they don’t affect SAVED / AVG -%: they only contribute to CALLS and BYPASS.
| Agent | Signal | Label |
|---|---|---|
| Claude Code | hook_event_name: PreToolUse |
claude |
| Gemini CLI | hook_event_name: BeforeTool |
gemini |
| Cursor | hook_event_name: preToolUse |
cursor |
| OpenCode | plugin template | opencode |
| Kilo Code | plugin template | kilo |
| Factory Droid | trs rewrite --caller droid in its hook |
droid |
Antigravity IDE / CLI (agy) |
rules-only, no programmatic hook (see notes); env fallback | antigravity when the env is set, else (untagged) |
| Codex | PreToolUse hook carries TRS_AGENT=codex (codex-cli ≥ 0.134) |
codex (rules-only fallback: (untagged)) |
| Windsurf | no programmatic signal (rules-only) | (untagged) |
(untagged) is also where these land: trs git status typed by hand,
scripts and CI, and other tools’ test suites that call trs against your
real ~/.trs (one project’s tests logged 3,276 digest runs in a month).
Because of that its AVG -% can look odd (those runs save 100%); narrow with
--days, or read claude, codex and the other labelled rows as the
agent traffic. We don’t invent a label where we don’t have honest data.
An agent whose hook or plugin never loads leaves no row at all: its
commands never reach trs, so they are not untagged, they are missing.
--by-command: command family breakdowntrs stats --by-command
Groups history entries by normalized command family (binary + up to 2 meaningful subcommands) and ranks by total tokens saved. Useful for spotting which commands run most and which give the best reduction.
trs Token Savings: by command
==================================================
COMMAND CALLS SHARE AVG -% SAVED
──────────────────────────────────────────────────
find 555 42.1% 48% 3.3M
git diff 102 7.7% 91% 1.2M
npm run lint 48 3.6% 82% 420K
gh pr checks 31 2.4% 78% 310K
…
Normalization strips paths, flags, and IDs, git diff HEAD~1 and
git diff main..feature both count as git diff. npm run lint
and pnpm run lint are separate entries (binary is kept).
--coverage: parser-gap analysistrs stats --coverage # human-readable, three tiers
trs stats --coverage --json # machine-readable (use this to share)
trs stats --coverage -n 20 # row cap per tier (default 15)
Aggregates every entry by (binary, subcommand) and surfaces three
tiers:
poetry run count=769 avg_in=11186 %low=51%.src/command_registry.rs
(the unified command registry) ensures even that minimum kicks in.%low rate. Confirmation
the existing parsers are doing their job.A row qualifies as “low” when its saved_pct < 10. A row enters tier 1
or 2 only if at least 40% of its entries are low AND the average input
is ≥ 256 bytes (small outputs intrinsically can’t be compressed much).
Run --coverage --json and paste the output into an issue:
trs stats --coverage --json > coverage.json
gh issue create --repo dPeluChe/trs --title "parser-gap: poetry run" --body-file coverage.json
The JSON is self-contained (trs_version, entry range, tier rows with
binary/sub/count/in_bytes/avg_in/low_pct/sample).
sample is a real command line off your machine, truncated to 70
chars. It routinely contains home paths and internal hostnames: a
sweep of one developer’s report found ssh <internal-host> sudo cat
/etc/nftables.conf and a full /Users/<name>/... path among eleven
samples. Use trs report coverage, which redacts what is
mechanically detectable and shows you the whole payload before
anything is sent.
trs stats --json
Structured output suitable for dashboards or CI:
{
"total_commands": 1247,
"period_start": "2026-04-15",
"period_end": "2026-04-20",
"period_days": 5,
"tokens_per_day": 160000,
"input_bytes": 4200000,
"output_bytes": 930000,
"saved_bytes": 3270000,
"input_tokens": 1050000,
"output_tokens": 232500,
"saved_tokens": 817500,
"avg_reduction_pct": 77.8,
"bypass_count": 4,
"top_commands": [
{
"cmd": "npm run build",
"count": 651,
"input_bytes": 2011785,
"output_bytes": 273143,
"saved_bytes": 1738642,
"saved_tokens": 434660,
"avg_reduction_pct": 86.4,
"bypass_count": 0
}
]
}
top_commands holds the commands that saved the most bytes (15 by default,
-n changes it). --history adds a history array of recent runs.
bypass_count is the number of TRS_SKIP=1 observations across the
window, same signal as the BYPASS column in --by-agent, but
aggregated. Useful for dashboards that want a single bypass-rate
metric (bypass_count / total_commands).
Every invocation of trs that produces output (compressed or not) writes a line to history.jsonl. Commands that failed, commands routed through the generic fallback, commands that emitted zero savings, all logged, so the dashboard reflects real usage rather than only the “wins.”
Failed passthrough (when a parser errors out and trs falls back to raw output) is logged with identical input/output bytes so the reduction shows as 0%. That’s intentional, lying about savings would defeat the point of the dashboard.
rm ~/.trs/history.jsonl # start over
No built-in retention policy yet, history grows indefinitely. A log rotation helper is on the roadmap. Typical sizes: a few MB after a few months of heavy use.
trs doctor: reports history.jsonl size and
writability.trs discover: scans your prior shell history
for commands where trs would have saved tokens but wasn’t used.trs report coverageThe coverage view answers “which commands should trs learn next”, which is only useful to a maintainer if someone sends it. This does both steps:
trs report coverage # build it, print it, save it, send nothing
trs report coverage --submit # same, then offer to open a public issue
trs report coverage --days 90 # widen the window
It is worth running after a week of normal work, not on day one: the value is in what you actually run and how badly it compresses, and one day of history answers neither.
sample fields are real command lines off your machine. The report rewrites
your home directory to ~ and masks credential shapes (tokens, -u user:pass,
Authorization: headers), then prints the entire payload before anything
happens.
That printing is the point. Redaction catches patterns; it cannot know that
ssh prod-db-01 names your infrastructure or that a directory is a client’s
name. Read it. Nothing is sent without --submit and a y at the prompt, and
without --submit the command just tells you the gh issue create line so
you can post it yourself.
trs report bugSame posture, different payload: version, platform, doctor results, recent history and the most recent tee logs.
trs report bug --summary "gh api output comes back empty"
trs report bug --summary "..." --submit
The tee-log excerpts are real command output, which is what makes the report useful and also what makes it worth reading first.