trs

trs Benchmarks

Living laboratory for trs. These benchmarks exist to help us learn, measure, and iterate, not to be marketing material or regression gates.

Why this folder exists

Every CLI in this space (rtk, token-saver, ccp, repomix, claw-compactor, pi) ships different tradeoffs. Some compress harder, some preserve more signal, some are faster on specific inputs. Instead of guessing, we run the comparisons here and let the numbers guide the decisions we make in trs.

The goal is internal knowledge: “what do we actually do better, and where should we improve?”, not to publish a leaderboard.

What we learned

output-cost-findings.md records where agent cost actually goes, what the output-saver tests showed and how to run the next one.

What’s in here

Script Purpose
benchmark.sh Comparative runs against rtk and token-saver on a curated set of real-world commands
benchmark-real.sh Longer, more varied workload (slower, more representative)
recovery.py How often a compact output sends the agent back for what it cut, from your own Claude Code transcripts
transcript_output.py Output tokens per assistant message before vs after the output-saver block, from your own Claude Code transcripts, per model, with a bootstrap 95% CI. Observational and labelled estimated
output_saver_ab.py A/B for the output-saver block with a control: no block, “Answer concisely.”, the trs block; isolated claude -p runs, style markers, fidelity cases (negation, number, destructive warning), bootstrap CI. Spends usage, refuses without --yes; --dry-run tests the harness for free
output_saver_agentic.py Agentic A/B for the output-saver block: tools on, small repo tasks with a test as success check, compares arms (--arm NAME=FILE) on total_cost_usd, turns, output tokens and success with a bootstrap CI. Parallel (--jobs), spend caps (--total-cap-usd), no bypassPermissions (scoped Bash allowlist). Spends usage, refuses without --yes
output_saver_stale.py Fixture for output_saver_agentic.py --suite stale: a repo whose docs contradict its code, to score correct answers per arm
truth.py Whether trs kept what the agent needed. Pipelines sent through the real hook must print what the raw pipeline prints; paths, file:line refs, hashes and error lines from the raw output must survive; a plain tail cut to trs’s size is the control; anchors found only in the middle half of the raw output are scored on their own (BLIND when a cut of 50% or more keeps under half of them). Tokens via tiktoken o200k_base when installed
chain-rewrite.sh Verifies the hook rewriter handles A && B chains, pipes, redirections, transparent wrappers (time, nohup, noglob, etc.), and edge cases

How to use

# Quick comparative run (from repo root)
./docs/development/benchmarks/benchmark.sh --all

# Full workload
./docs/development/benchmarks/benchmark-real.sh

# Chain rewriter sanity check (runs in <1s)
./docs/development/benchmarks/chain-rewrite.sh

# Signal survival (exits 1 if any pipeline differs from raw)
python3 docs/development/benchmarks/truth.py

All scripts prefer ./target/release/trs if present (so you’re testing your latest changes), falling back to the trs in $PATH.

What these benchmarks are NOT

What they are

Quick, approximate signals that help us answer questions like:

When in doubt, read the output by eye, not the summary number.

Bytes saved is the easy half. benchmark.sh crowns whoever prints the fewest bytes, so a tool that dropped the failing test’s name would win it, and so did a trs that answered find src | wc -l with 14 instead of 241. truth.py exists for that half. The interesting signal is usually in the cases that surprise you.

Contributing

If you find a command or workflow where trs underperforms, add a case to the relevant script and let the numbers speak. That’s how we learn.

Latest truth run

2026-11-30, trs 0.10.6 with #313, on this repo, tokens counted with o200k_base.

Pipelines through the hook: 9/9 match raw (1/9 on v0.8.1, before #162: the hook compressed the producer of any pipeline, so | grep, | wc -l and | jq parsed trs’s summary).

Anchors (kept is literal anchors, facts reads them for meaning, buried is anchors found only in the middle half of the raw output):

command raw tok trs tok cut anchors kept facts same-size tail buried flag
git log -10 4762 866 82% 77% 100% 23% 100%  
git log --oneline -30 657 657 0% 100% 100% 100% 100%  
git diff HEAD~1 18673 7760 58% 52% 88% 38% 88%  
git diff HEAD~5 45306 7724 83% 47% 89% 39% 97%  
git show HEAD --stat 429 304 29% 92% 92% 50% 100%  
git status 59 18 69% 100% 100% 100% 100%  
ls -la src 3162 1127 64% 100% 100% 35% 100%  
find src -name '*.rs' 2027 262 87% 33% 33% 15% 37% BLIND
grep -rn 'fn main' src 809 672 17% 100% 100% 68% 100%  
grep -rn 'emit_compressed' src 228 232 -2% 100% 100% 87% 100% GREW
cargo clippy --all-targets 59 24 59% 100% 100% 100% 100%  

0 RISK rows (cut of 90% or more with under 70% of facts), 0 SILENT. What the flags mean, read by eye:

Anchor matching tolerates trs regrouping grep under file headers and find under directories, so “kept” is a ceiling: a low number is a real loss.

Context lines in small diffs

git diff keeps only the changed lines and each hunk header (it names the function); the unchanged context lines go. Keeping some was tried against 32 real diffs from this repo (4-500 changed lines each, last 60 commits, anchors from truth.py, tokens counted with o200k_base), by temporarily varying how many context lines surround each change:

context lines kept tokens cut anchors kept (median)
0 (current) 23.7% 58.7%
1 16.1% 60.0%
2 8.5% 61.2%
3 (nearly the raw diff) 1.8% 64.1%

One line of context costs 7.6 points of savings for 1.3 points of anchors, and even the near-raw diff keeps only 64%: the anchors lost are mostly the index abc..def hashes and the diff --git a/x b/x paths, which the file summary replaces on purpose. So the default stays at 0.

trs against similar tools

2026-11-30, one repo state, all tools on one machine, --reps 3. trs 0.10.6 with #313 (moved blocks print once) and #317 (rewrite lock). Versions: rtk 1.2.1 (built from its clone; Homebrew still ships 0.42.3), squeez 1.50.0, token-saver 1.3.1, claw-compactor 7.1.0. Reproduce:

bash docs/development/benchmarks/compare/setup.sh     # builds the others from their clones
python3 docs/development/benchmarks/compare/compare.py

Every hook-based tool runs through its own agent hook: the hook decides (hook ms, paid on every agent call), then the shell runs what it returned (exec +ms over raw). claw-compactor has no hook, so its text API compresses the output instead. Anchors are paths, file:line refs, hashes and error lines taken from the raw output. “pipelines” counts the 9 checks from truth.py, compared after whitespace normalization.

token-optimizer is left out of this run: since v5 its PreToolUse hook is always silent and it compresses in a PostToolUse hook, which compare.py does not drive yet (it scores 2% cut, 98% anchors through the PreToolUse hook). Its 2026-09-24 row was 36% cut, 43% anchors.

The repo state moves with each run: here HEAD~1 and HEAD~5 span a merge of main, so the two git diff rows are 19k and 46k tokens raw (2k and 24k on 2026-11-29). Compare tools within a run, not one run with another.

38 commands, tokens: o200k_base

tool tokens cut anchors kept RISK grew pipelines hook ms exec +ms
trs 87% 57% 1 1 9/9 6.3 15.9
rtk 86% 40% 1 0 8/9 19.6 9.8
token-saver 26% 62% 6 0 8/9 56.6 96.4
squeez 93% 24% 6 0 9/9 5.8 21.4
claw-compactor 40% 90% 0 2 n/a 0.0 0.0

Per command, so no single command decides the score (ps aux alone is 160k of the raw tokens), with facts read for meaning (truth.facts):

tool mean cut median cut facts kept, mean facts kept, pooled commands with no fact left
trs 33% 25% 93% 66% 1
rtk 36% 39% 80% 46% 3
token-saver 36% 35% 76% 69% 2
squeez 34% 20% 67% 27% 1
claw-compactor 19% 17% 92% 95% 0

Per command, cut / anchors kept:

command raw tok trs rtk token-saver squeez claw-compactor
grep -n "fn " src/report.rs 133 0% / 100% 0% / 100% 0% / 100% 0% / 100% 0% / 100%
grep -rn "emit_compressed" src 228 -2% / 100% 0% / 100% 0% / 100% 0% / 100% -8% / 47%
grep -rn "fn main" src 809 17% / 100% 0% / 100% 47% / 63% 70% / 39% 18% / 32%
grep -rn -A3 "pub(crate) fn" src/report.rs 328 9% / 100% 0% / 100% 0% / 100% 0% / 100% 4% / 100%
grep -rn -C2 "is_verbatim_invocation" src 2151 23% / 100% 0% / 100% 67% / 76% 39% / 38% 12% / 100%
grep -rn "TODO\|FIXME" src 596 10% / 100% 0% / 100% 0% / 100% 0% / 100% 11% / 33%
rg -n "captures_output" src 40 2% / 100% 0% / 100% 0% / 100% 0% / 100% -20% / 33%
git log -5 3256 86% / 72% 87% / 39% 97% / 33% 90% / 22% 41% / 67%
git log -20 6785 77% / 80% 75% / 63% 97% / 26% 91% / 24% 45% / 80%
git log --oneline -30 657 0% / 100% 0% / 100% 68% / 31% 58% / 41% 6% / 100%
git log --stat -3 857 0% / 100% 0% / 100% 94% / 40% 64% / 40% 33% / 100%
git diff HEAD~1 19454 60% / 52% 58% / 64% 42% / 63% 97% / 9% 12% / 91%
git diff HEAD~5 46087 83% / 47% 74% / 54% 50% / 57% 99% / 6% 16% / 82%
git diff HEAD~3 --stat 459 23% / 100% 0% / 100% 50% / 56% 0% / 100% 23% / 97%
git show HEAD 120 0% / 100% 0% / 100% 0% / 100% 0% / 100% 8% / 100%
git show HEAD --stat 429 29% / 92% 0% / 100% 0% / 100% 32% / 54% 17% / 96%
git show HEAD~2:src/report.rs 1616 0% / 100% 0% / 100% 0% / 100% 53% / 25% 35% / 100%
git status 141 66% / 100% 61% / 100% 35% / 100% 36% / 100% 28% / 100%
git branch -a 240 48% / 100% 49% / 100% 70% / 100% 5% / 100% 16% / 100%
ls -la 1164 70% / 100% 69% / 100% 75% / 100% 25% / 92% 12% / 100%
ls -la src 3162 64% / 100% 81% / 46% 86% / 46% 72% / 27% 12% / 100%
find src -name "*.rs" 2027 87% / 33% 89% / 0% 90% / 10% 84% / 16% 12% / 100%
find . -name "*.md" -not -path "./target/*" 4473 53% / 98% 90% / 28% 10% / 88% 92% / 17% 5% / 97%
wc -l src/rewrite.rs src/rewrite_decide.rs src/report.rs src/init.rs 38 0% / 100% 40% / 0% 0% / 100% 0% / 100% 29% / 100%
tail -50 src/rewrite_decide.rs 383 0% / 100% 0% / 100% 0% / 100% 35% / 100% 41% / 100%
cargo build 24 0% / 100% 0% / 100% 4% / 100% 0% / 100% 17% / 100%
cargo clippy --all-targets 24 0% / 100% 67% / 100% 4% / 100% 0% / 100% 17% / 100%
gh pr list --state all --limit 30 1260 28% / 100% 59% / 0% 0% / 100% 0% / 100% 11% / 100%
gh pr view 162 922 4% / 100% 0% / 100% 46% / 25% 0% / 100% 22% / 75%
gh run list --limit 10 470 33% / 100% 75% / 100% 0% / 100% 0% / 100% 24% / 100%
ps aux 159863 99% / 0% 99% / 1% 10% / 90% 97% / 4% 54% / 94%
docker ps -a 231 41% / 20% 30% / 80% 35% / 20% 0% / 100% 21% / 100%
docker images 403 13% / 100% 49% / 0% 92% / 0% 0% / 100% 19% / 100%
cargo test 829 76% / 56% 77% / 67% 65% / 100% 75% / 50% 67% / 89%
cargo build 24 0% / 100% 0% / 100% 4% / 100% 0% / 100% 17% / 100%
bun test 548 55% / 70% 58% / 80% 90% / 40% 15% / 90% 22% / 100%
pytest 372 67% / 58% 63% / 42% 41% / 92% 73% / 42% 7% / 100%
pytest -q 223 44% / 64% 38% / 45% 9% / 91% 0% / 91% 8% / 91%

Read by eye before trusting a cell:

Other approaches: images and token-oriented formats

Two ideas from outside per-command compression, read on 2026-11-21. Their figures are their own claims and were not reproduced here. We list them because they are good work, and because saying why trs does or does not follow them is part of the measurement.

Context rendered as images (pxpipe)

A local proxy redraws the bulky part of each request (system prompt, tool docs, old history) as PNG pages in a 5x8 bitmap font. An image is billed by pixel area, not by characters, so dense content packs about 3 characters per image token against about 1 per text token. It reports a 59-70% lower bill on claude-fable-5.

Why trs does not do this:

What we take from it:

Token-oriented formats (TOON)

TOON keeps YAML-style indentation for nested objects and writes a uniform array as a table with the field names once. Its published benchmark (o200k_base, 4 models, 244 retrieval questions):

compared with uniform arrays nested data
indented JSON 42-61% fewer tokens 15-35% fewer
minified JSON 23-37% fewer 2-20% more
CSV 3-9% more CSV cannot hold it

What that means for trs:

--json stays JSON: scripts read it, and structured output is never rewritten. A header-once table for uniform arrays in trs json and trs read, which an agent reads to understand a file, is a candidate once it is measured (roadmap Phase 2.11).

Facts, not literal text

2026-11-05, v0.9.1 against the latest release of the closest similar tool, same corpus, compare.py --only trs,rtk --reps 3. The anchor score counted a reworded line as lost: tests::x: src/main.rs:65:60: ... scored as missing the test x ... FAILED it replaces. truth.facts reads the output for meaning, for every tool alike:

RISK, BLIND and tail-wins now use facts, so they are not comparable with the sections below. anchors kept stays as the old literal column.

  trs 0.9.1 rtk 1.1.0
tokens cut, whole corpus 87% 83%
mean cut per command 32% 34%
median cut per command 23% 33%
facts kept, mean per command 91% 80%
facts kept, pooled 57% 46%
commands with no fact left 1 4
RISK rows 2 1
pipelines 9/9 8/9
hook ms 5.2 18.2

ps aux and git diff HEAD~5 hold 80% of the corpus tokens, so per-command scores say more than the totals. The real loss is git diff HEAD~5: 99% cut, 94 of 367 facts, and BLIND. The corpus runs on this repo, so its diffs move with each commit.

Do agents go back to an output?

2026-11-05, recovery.py --since 2026-06-01, 2,594 transcripts, next 5 calls. Of 35,130 calls, 1.2% asked for the same output again and 1.8% drilled in with a narrower command.

family calls re-fetched tee bypass repeat drill
git show 173 26.0% 0 2 2 41
git diff 2695 22.2% 10 31 7 549
git status 1934 9.9% 1 161 29 0
git log 5577 1.8% 11 12 33 44
gh pr 2887 0.9% 3 24 0 0
ls 6634 0.6% 4 29 10 0
git branch 1129 0.6% 1 6 0 0
grep 12773 0.3% 8 14 16 0

This has no control: a transcript does not say whether trs cut that output, and agents narrow a diff or pipe git status out of habit too. It ranks families; it does not price a cut. The calls span many trs versions.

A large diff shares a budget

2026-11-05, same corpus after the change. Past 500 change lines, git diff used to print a file list and nothing else. It now has one renderer and a 24 KB budget of hunks, with no threshold: code shares it fairly, generated files get what the code leaves, and each hunk of a large file gets a share. A diff that fits prints whole. Each cut says [trs: N lines omitted], and the raw output is saved.

git diff HEAD~5 tokens cut facts kept
trs before 99% 94 of 367
trs now 85% 152 of 383
rtk 1.1.0 85% 155 of 383
  before now rtk 1.1.0
tokens cut, whole corpus 87% 84% 84%
facts kept, pooled 57% 61% 46%
facts kept, mean per command 91% 92% 79%
RISK rows 2 1 1

The whole-corpus cut fell because that one diff now spends tokens on code. BLIND stays on that row: 24 KB cannot carry the middle of a 2,500-line diff.

truth.py adds SILENT: under 70% of facts kept with no way back named. No row has it. Zero context lines in small diffs stays as measured above: nothing is noted there, because the file itself is the way back.

git branch -a drops nothing to gain ground. The tool that cuts more here prints ... +20 more and hides real branches, so trs only nests repeated prefixes.

trs alone on main after v0.10.3

2026-11-22, same corpus and command as below, main at 031dc0a (v0.10.3 plus unindented diff lines and gh issue view). Checks that the post-release fixes kept every pipeline and fact. truth.py: 9/9 pipelines match, 0 RISK rows, 0 SILENT rows, 1 BLIND row (find src -name '*.rs'). compare.py: 1 RISK row (ps aux). chain-rewrite.sh: 43/43.

  tokens cut anchors kept facts kept
all 38 commands (token-weighted) 87% 57% 66%
mean per command 34%   93%
median command 31%    

The BLIND row is the repo, not the compressor: v0.10.0 built and run on this same state prints the same find output byte for byte. Since v0.10.0, 36 files left src/ and 5 arrived (273 to 242), so different names land in the middle, which the per-folder cap (12 names, then +N more and the path to the full output) hides. git diff HEAD~5 is 29,567 raw tokens in this run (12,687 on v0.10.0), which pulls the pooled anchor and fact scores down and the pooled cut up.

trs alone on v0.10.0

2026-11-05, same corpus and command as below. This is what usetrs.dev shows. truth.py: 9/9 pipelines match, 0 RISK rows, 0 SILENT rows, 0 BLIND rows. compare.py: 1 RISK row (ps aux). chain-rewrite.sh: 43/43. Startup: 3.05 ms median over 300 runs of trs --version.

  tokens cut anchors kept facts kept
all 38 commands (token-weighted) 83% 62% 71%
mean per command 31% 79% 94%
median command 27%    
commands cut by half or more 11 of 38    

The repo moved under the corpus, not the compressor: v0.9.2 run on this same state matches v0.10.0 on 36 of 37 distinct commands, and the other is ps aux, which changes between runs. git diff HEAD~5 is now 12,687 raw tokens, not 53,587, so it cuts 38% instead of 85% and weighs less in the pooled row. gh run list keeps 0 of the 2 anchors found in this run; v0.9.2 does the same.

trs alone on v0.9.2

2026-11-05, same corpus and command as below. truth.py: 9/9 pipelines match, 0 RISK rows, 0 SILENT rows, 1 BLIND row (git diff HEAD~5). compare.py: 1 RISK row (ps aux). chain-rewrite.sh: 43/43. Startup: 3.61 ms median over 300 runs of trs --version.

  tokens cut anchors kept facts kept
all 38 commands (token-weighted) 84% 55% 63%
mean per command 32% 84% 92%
median command 24%    
commands cut by half or more 11 of 38    

The cut fell from 85% on v0.9.1 by design: git diff HEAD~5 now prints code from every file instead of a file list. The site shows that row in place of git diff HEAD~1, since a large diff no longer becomes a summary.

trs alone on v0.9.1

2026-11-04, same corpus and command as below. This is what usetrs.dev shows. truth.py: 9/9 pipelines match, 1 RISK row (git diff HEAD~5), 0 BLIND rows. chain-rewrite.sh: 43/43. Startup: 3.65 ms median, against 3.6 ms on v0.9.0 with the same loop.

  tokens cut anchors kept
all 38 commands (token-weighted) 85% 62% (mean 84% per command)
median command 27%  
commands cut by half or more 13 of 38  

Do not compare the rows without ps aux to v0.9.0 (44% then, 61% now): the corpus runs on this repo, and git diff HEAD~5 grew past the 500-changed-line limit, so it became a file summary (22,799 to 640 tokens, 97% cut). That row is the RISK: the file list plus the path to the raw output, not the changes. Corrections that trade savings for truth do not show in this corpus: it has no make target and no translated git status.

Rereads: measured, not built

A cache for repeated reads looked large because sed and cat are 38% of what agents receive. Over 40 days of transcripts (233 MB of tool output, deduplicated by tool-use id, since a resumed session repeats its history):

shape share of tool output
same command, same output 0.04%
sed -n range already seen in full 0.07%
sed -n lines already seen, upper bound 0.15%

Agents read each range once, and a cache would claim “unchanged” to an agent whose context was compacted. Counting lines without that deduplication gives a false 7%.

trs alone on v0.9.0

2026-11-04, same corpus, this repo’s state that day, compare.py --only trs --reps 1, tokens counted with o200k_base. This is what usetrs.dev shows. truth.py: 9/9 pipelines match, 0 RISK rows, 1 BLIND row (git diff HEAD~1). chain-rewrite.sh: 43/43.

  tokens cut anchors kept
all 38 commands (token-weighted) 84% 64% (mean 84% per command)
without ps aux 44%  
median command 29%  
commands cut by half or more 11 of 38  

The “up to 60%” on usetrs.dev

The site said ~70% until v0.8.10. That came from 2026-10-21 data, before trs stats left failed runs and outputs over 30 KB out of its totals. Measured again on 2026-11-04, from the author’s history:

window commands saved
all history (203 days) 84,325 58%
90 days 25,730 48%
30 days 6,030 24%
7 days 1,370 35%

The windows swing with the work: a month of low-output commands saves little. “Up to 60%” is a ceiling from the history, on the output trs handles, not on the bill: see output-cost-findings.md. Quote the table above for a given command. With oversized outputs counted back in, 30 days is 58%, but a few huge outputs carry that number.

trs alone on v0.8.9

2026-10-21, same corpus (now 38 commands: docker ps -a and docker images were added), this repo’s state that day, compare.py --only trs --reps 3, tokens counted with o200k_base.

  tokens cut anchors kept
all 38 commands (token-weighted) 81% 65% (mean 88% per command)
without ps aux 39%  
median command 28%  
commands cut by half or more 12 of 38  

ps aux is 97,702 of the 139,322 raw tokens, so the headline figure is mostly that one row. Every number here moves with the repo state: the September run had a 40k-token git diff HEAD~5 (98% cut) where this one has 7.7k (26%). Quote the per-command rows, not one percentage.

The ~70% that usetrs.dev showed then was a different measurement: the author’s history over 30 days (2026-10-21), only commands run by agents through a hook (3,259, 10.4M input tokens): 73.3% saved. trs stats --days 30 shows 68.9% over 8,359 commands because it also counts test suites and hand-typed runs (3,649 of them are test noise, such as another project’s tests calling trs digest). Same caveat as the table: a few verbose outputs carry the total. Without the top 1% of outputs it is 58.7%, the median command saves 1%, and the last 7 days were 23.6%.