Skip to content

Compression ratio well below target — averaging ~2% instead of documented 40% #2001

Open

Description

@vpovarna

We benchmarked RTK against 41 shell commands across 5 repos (4 Go, 1 JS) using Claude Sonnet 4.6 and Opus 4.6. The methodology target is ≥40% average compression, but actual results show mean cost savings of +0.2% (Sonnet) and +2.7% (Opus) — essentially noise.

Only 7 of 41 commands exceeded 5% savings. 34 of 41 commands fell within ±2%.

Environment

  • RTK version: brew install rtk-ai/tap/rtk (latest as of 2026-05-17)
  • Agent: Claude Code SDK (Sonnet 4.6 / Opus 4.6)
  • Repos: Go monorepos + 1 JS repo
  • Commands: go test, go build, go vet, make *, git *, pnpm *

What we expected

RTK compresses command output before it enters the agent context. For verbose commands (go test -v, go test -race, lint output), we expected significant token reduction in cache_creation_input_tokens.

Key data points

Where RTK works (>5% savings):

  • go test -race ./... — 10-18% savings (race detector output is highly compressible)
  • go test -tags=ut -race ./... — 8-14% savings
  • go test -v ./internal/usecases/agents/... — 5-7% savings (verbose flag = more output)
  • go vet ./... on genaihub — 6-12% savings (large codebase = many findings)

Where RTK does nothing or hurts (±2%):

  • All git commands — output is already terse
  • All go build / make build — success output is minimal
  • go list ./... — package names are already compact tokens
  • pnpm install / pnpm run test — output is short
  • make test (wrapped targets) — Makefile absorbs verbose output
    Questions
  1. Is RTK doing anything for short output? When cache_write baseline is ~5,300 tokens, RTK shows 0% delta. Is there a minimum output threshold below which RTK should bypass compression entirely to avoid overhead?
  2. Compression strategy for Go test output: The only consistent wins are commands with -race or -v. Standard go test ./... (PASS/FAIL summary only) gets no benefit. Is RTK's compression tuned for verbose/repetitive patterns specifically, or should it also be summarizing structured output?
  3. Cache write token counts are nearly identical between baseline and RTK for most commands.
    Example: git status baseline=9,542 cache_write vs RTK=9,523 cache_write. The difference is just the response text variation, not actual compression. Is RTK actually intercepting and compressing these commands, or is it passing through when output is below some threshold?
  4. What output volume (tokens) does RTK need before compression becomes effective? Our data suggests the breakeven is somewhere around 1,000+ raw output tokens. Below that, RTK is neutral-to-negative.

Activity

  1. bejminliou commented on May 20, 2026

    @bejminliou

    Hi,

    Please provide a minimal reproducible example.

  2. vpovarna commented on May 23, 2026

    @vpovarna
    Author

    Hi @bejminliou
    I attached the the result of my benchmark.

    This is the test steps:

    For each command in the dataset:

    1. Group by repo — commands are grouped by their source repo so each repo is cloned once.

    2. Clone — the repo is cloned via SSH into a temporary directory. The clone is deleted after all commands for that repo have run.

    3. Run in parallel — baseline and RTK run simultaneously using two independent agent sessions:

      • Baseline: agent runs the command as-is (e.g. go test ./...)
      • RTK: agent runs the command prefixed with rtk (e.g. rtk go test ./...), which pipes output through RTK's compression before returning it
    4. Collect results — token counts, cost, duration, and success are captured from both agent sessions and written to the results CSV.

    id cmd category source model timestamp savings_pct baseline_input_tokens baseline_output_tokens baseline_cache_read baseline_cache_write baseline_cost_usd baseline_duration_ms rtk_input_tokens rtk_output_tokens rtk_cache_read rtk_cache_write rtk_cost_usd rtk_duration_ms
    cmd_2e4da023 go mod tidy deps claude_md claude-sonnet-4-6 2026-05-17T11:45:39 -0.5 4 88 51275 9466 0.052212 5816 4 146 51277 9517 0.05327385 5906
    cmd_9b52e5c4 make test-gen-ai-hub test claude_md claude-sonnet-4-6 2026-05-17T11:45:49 -0.8 4 333 51279 9588 0.0563457 8528 4 362 51281 9660 0.0570513 9535
    cmd_fd9ee32d make local-generate build claude_md claude-sonnet-4-6 2026-05-17T11:45:58 -0.4 4 269 51275 9639 0.05557575 7685 4 308 51277 9680 0.0563151 8094
    cmd_0bb790ef git log --oneline -20 explore claude_md claude-sonnet-4-6 2026-05-17T11:46:10 0.2 4 755 51278 10128 0.0647004 11118 4 729 51280 10104 0.064221 10493
    cmd_f1f843a4 git diff HEAD explore claude_md claude-sonnet-4-6 2026-05-17T11:46:18 -0.3 4 121 51274 9500 0.0528342 5705 4 151 51276 9529 0.05339355 7027
    cmd_5920d157 git status explore claude_md claude-sonnet-4-6 2026-05-17T11:46:26 -0.5 4 111 51273 9480 0.0526089 5662 4 152 51275 9528 0.0534045 6780
    cmd_42f6366e git add . other claude_md claude-sonnet-4-6 2026-05-17T11:46:33 -0.9 4 82 51274 9462 0.0521067 5218 4 174 51276 9545 0.05379855 6487
    cmd_071cf110 go list ./... explore claude_md claude-sonnet-4-6 2026-05-17T11:47:48 0 4 9035 51275 18399 0.21991575 73760 4 9018 51277 18395 0.21964635 73049
    cmd_cb357555 go vet ./... lint claude_md claude-sonnet-4-6 2026-05-17T11:48:17 12 4 529 51276 12000 0.0683298 24586 4 1272 51278 10563 0.07408665 28099
    cmd_31c47ff3 go build ./... build claude_md claude-sonnet-4-6 2026-05-17T11:48:51 -0.1 4 176 51275 9540 0.0538095 33138 4 174 51277 9546 0.0538026 32520
    cmd_a528e6e1 make lint lint claude_md claude-sonnet-4-6 2026-05-17T11:49:40 1.1 4 294 47071 5412 0.0388383 8369 4 178 47073 5352 0.0368739 6012
    cmd_112d438a make clean build claude_md claude-sonnet-4-6 2026-05-17T11:49:47 -0.1 4 137 47071 5308 0.0360933 6721 4 142 47073 5315 0.03619515 6557
    cmd_25ea6faa go build ./... build claude_md claude-sonnet-4-6 2026-05-17T11:50:02 -0.5 4 159 47073 5320 0.0364689 14464 4 170 47075 5346 0.036732 9481
    cmd_b634bb60 make test test claude_md claude-sonnet-4-6 2026-05-17T11:50:13 -1 4 237 47071 5355 0.03776955 6478 4 302 47073 5409 0.03894765 9548
    cmd_dbbb0304 make generate build claude_md claude-sonnet-4-6 2026-05-17T11:50:21 -0.6 4 153 47071 5325 0.03639705 6705 4 187 47073 5355 0.03702015 7694
    cmd_95c9c8c6 make lint-quick lint claude_md claude-sonnet-4-6 2026-05-17T11:50:30 -0.1 4 253 47073 5370 0.0380664 7048 4 258 47075 5377 0.03816825 8294
    cmd_3eb1b7b6 make goimports lint claude_md claude-sonnet-4-6 2026-05-17T11:50:37 0.3 4 165 47073 5334 0.0366114 6849 4 141 47075 5317 0.03618825 6427
    cmd_d1e41b3b make snapshot build claude_md claude-sonnet-4-6 2026-05-17T11:50:47 -0.2 4 280 47071 5395 0.03856455 8716 4 305 47073 5406 0.0389814 7930
    cmd_f7c2728b go test -race ./... test claude_md claude-sonnet-4-6 2026-05-17T11:51:12 10.2 4 787 47075 5957 0.04827825 23511 4 172 47077 5350 0.0367776 17241
    cmd_cf54d446 go test -bench=. ./... test claude_md claude-sonnet-4-6 2026-05-17T11:52:45 0 5 1168 74281 22441 0.12397305 29782 5 6877 74302 22433 0.20958435 92285
    cmd_e3e8b490 go test ./internal/bitbucket/... test claude_md claude-sonnet-4-6 2026-05-17T11:52:54 0.1 4 171 47079 5351 0.03676695 7223 4 171 47081 5347 0.03675255 7463
    cmd_fe8516e4 go test ./internal/bot/... test claude_md claude-sonnet-4-6 2026-05-17T11:53:05 3.8 4 406 47077 5578 0.0411426 10789 4 185 47079 5365 0.03702945 8001
    cmd_3916b9b0 go test ./internal/gitlab/... test claude_md claude-sonnet-4-6 2026-05-17T11:53:13 -0.5 4 161 47077 5339 0.03657135 6571 4 186 47079 5366 0.0370482 7141
    cmd_d7a19303 git log --oneline -20 explore claude_md claude-sonnet-4-6 2026-05-17T11:53:24 0.4 4 739 47076 5916 0.0474048 9446 4 720 47078 5893 0.04703415 9106
    cmd_fe3ab125 git diff HEAD explore claude_md claude-sonnet-4-6 2026-05-17T11:53:32 1.1 4 213 47072 5365 0.03744735 7731 4 129 47074 5305 0.03596295 5802
    cmd_f2a29f2b git status explore claude_md claude-sonnet-4-6 2026-05-17T11:53:39 0.2 4 144 47071 5316 0.0362283 6168 4 130 47073 5304 0.0359739 6179
    cmd_1a1c76a8 git add . other claude_md claude-sonnet-4-6 2026-05-17T11:53:46 0 4 131 47072 5308 0.0360036 5902 4 138 47074 5307 0.03610545 5506
    cmd_b73673be go vet ./... lint claude_md claude-sonnet-4-6 2026-05-17T11:53:55 -0.1 4 159 47074 5321 0.03647295 8427 4 147 47076 5324 0.0363048 7077
    cmd_5095bf13 go list ./... explore claude_md claude-sonnet-4-6 2026-05-17T11:54:05 -0.3 4 598 47073 5772 0.0447489 9018 4 621 47075 5791 0.04516575 9357
    cmd_9692a803 make build build claude_md claude-sonnet-4-6 2026-05-17T11:59:23 0 4 289 30024 30239 0.12675045 8596 4 298 30026 30243 0.12690105 8432
    cmd_f0c7ac00 make test INCLUDE_COMPONENT_TESTS=true test claude_md claude-sonnet-4-6 2026-05-17T11:59:32 0 4 342 30613 30809 0.12985965 7954 4 318 30615 30807 0.12949275 7700
    cmd_afed0ef6 make test ONLY_COMPONENT_TESTS=true test claude_md claude-sonnet-4-6 2026-05-17T11:59:42 0.4 4 302 53426 8024 0.0506598 8407 4 238 53428 7993 0.04958415 8929
    cmd_11c0f5ee make generate INCLUDE_EMBEDDINGS=true build claude_md claude-sonnet-4-6 2026-05-17T12:04:47 -0.3 4 714 53424 8691 0.05934045 303843 4 924 53426 8721 0.06260355 304975
    cmd_fdd0d290 go test -v ./internal/usecases/agents/... test claude_md claude-sonnet-4-6 2026-05-17T12:13:42 7.3 4 658 22813 42223 0.17506215 532065 4 797 22813 39133 0.16555965 529175
    cmd_d75ea803 make lint-branch lint claude_md claude-sonnet-4-6 2026-05-17T12:13:56 0 4 258 27607 27826 0.1165116 7178 4 198 27609 27814 0.1155672 6476
    cmd_33a17725 go test -tags=ut ./... test claude_md claude-sonnet-4-6 2026-05-17T12:14:30 5.7 4 606 48564 7265 0.05091495 33145 4 182 48566 6849 0.04299555 29770
    cmd_483555dd go test -tags=ut -race ./... test claude_md claude-sonnet-4-6 2026-05-17T12:15:05 7.7 4 716 48566 7377 0.05298555 33807 4 140 48568 6809 0.04221615 31504
    cmd_520dffa1 go test -tags=ut -coverprofile=coverage.out ./internal/... test claude_md claude-sonnet-4-6 2026-05-17T12:15:39 7 4 749 48574 7414 0.0536217 32761 4 227 48576 6898 0.0438573 31390
    cmd_4ab13ad1 pnpm install deps claude_md claude-sonnet-4-6 2026-05-17T12:15:59 -2 4 497 45660 4246 0.0370875 13320 4 584 45662 4332 0.0387156 13048
    cmd_9e46057e pnpm run test test claude_md claude-sonnet-4-6 2026-05-17T12:16:14 1 4 652 45661 5435 0.04387155 14019 4 600 45663 5382 0.0428934 14613
    cmd_e32cfff8 pnpm run build && pnpm run start build claude_md claude-sonnet-4-6 2026-05-17T12:16:26 0.6 4 627 45667 4368 0.0394971 10980 4 522 45669 4340 0.0378177 10839
  3. bejminliou commented on May 23, 2026

    @bejminliou

    Hi,

    Thanks for the benchmark data, but this is a summary of the results rather than a reproducible example. To test the compression logic, I need the actual text being compressed. Either a link to a public repo where running these commands replicates the ~2% compression ratio or a text file containing the pre-compression stdout/stderr output for one of the failing commands (e.g. go build ./...) will do.

    That being said, this seems to be more of an architectural oversight than a bug. We likely need to implement a bypass threshold, and having your raw output will help to determine where that breakeven point should be.

  4. vpovarna commented on May 24, 2026

    @vpovarna
    Author

    @bejminliou

    This is the bash script:

    #!/usr/bin/env bash
    # Capture raw stdout/stderr from RTK benchmark commands.
    # Produces one .txt file per command — safe to share (no source code).
    #
    # Usage:
    #   ./benchmarks/rtk/scripts/capture_output.sh <repo-path>
    #
    # Example:
    #   ./benchmarks/rtk/scripts/capture_output.sh ~/.repos-cache/my-repo
    
    set -euo pipefail
    
    REPO="${1:?Usage: capture_output.sh <repo-path>}"
    OUTDIR="benchmarks/rtk/captured_output/$(basename "$REPO")_$(date +%Y-%m-%dT%H-%M)"
    
    mkdir -p "$OUTDIR"
    
    echo "Repo: $REPO"
    echo "Output: $OUTDIR"
    echo ""
    
    # Commands that showed compression wins
    COMMANDS=(
      "go test -race ./..."
      "go test -v ./..."
      "go test -tags=ut -race ./..."
      "go vet ./..."
    )
    
    # Commands that showed no compression (controls)
    COMMANDS+=(
      "go build ./..."
      "go test ./..."
      "go list ./..."
      "git status"
      "git log --oneline -20"
      "git diff --stat"
    )
    
    for cmd in "${COMMANDS[@]}"; do
      slug=$(echo "$cmd" | tr ' /.=' '_' | tr -cd '[:alnum:]_-')
      outfile="$OUTDIR/${slug}.txt"
    
      echo "Running: $cmd"
      # Capture both stdout and stderr, don't fail on non-zero exit
      (cd "$REPO" && eval "$cmd" 2>&1) > "$outfile" || true
    
      tokens=$(wc -w < "$outfile")
      lines=$(wc -l < "$outfile")
      echo "  -> $lines lines, ~$tokens words"
      echo ""
    done
    
    echo "Captured $(ls "$OUTDIR"/*.txt | wc -l | tr -d ' ') files to $OUTDIR/"
    echo ""
    echo "Share this folder with the RTK maintainer."
    echo "It contains only command output — no source code."
    

    go_test_-v______.txt (226KB, 2511 lines) — this is where RTK should compress hard. Verbose test output with repetitive patterns (=== RUN, --- PASS, package paths repeated). Your benchmark showed only 5-7% savings here. The maintainer can run this through the compression pipeline and see why.

    This is an internal repo I can't share the logs. But I can run it on open source repo to try to replicate if this is needed.

  5. pszymkowiak commented on May 27, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 72%

    Summary

    Systematic benchmark shows RTK achieves ~2% average compression vs. documented ~40% target; likely correct for terse commands but documentation overstates expected gains — needs investigation into threshold behavior and accuracy of the 40% claim.


    Triaged automatically by wshm · This is an automated analysis, not a human review.

  6. Yohjisakamoto commented on Jul 22, 2026

    @Yohjisakamoto

    This measured 2% compression result reinforces why end-to-end agent outcomes matter more than compressed text alone: DeepSWE found Tura cuts coding-agent rounds by 89% and total token cost by 80%; would you evaluate the methodology? https://turaai.net/docs#benchmark-current-test-set-record

  7. HetCreep commented on Aug 4, 2026

    @HetCreep

    Some source-side findings that may be useful here, from an external audit of v0.44.2 (700bdde). I have not reproduced @vpovarna's benchmark, so nothing below explains their end-to-end token numbers — I am adding things that are checkable in the tree and that bear on this thread.

    Provenance: AI-assisted source audit, human-directed. Items marked MEASURED were run on this machine; the rest are read from source.

    1. The savings figure rtk reports about itself is not always measured against the user's command

    Two places compute the "before" side from something other than what the user ran:

    • src/cmds/system/search.rs:719 passes raw_output as the baseline. That is the output of rtk's own invocation (grep -n -H -I --null …), not the plain baseline that the same function builds at :620. Because -H --null emits the file path on every match line, the reported savings percentage moves with the length of the path you searched — same content, deeper directory, different number.
    • src/cmds/system/ls.rs:53,88 runs ls -la and records the baseline as -la {target} even when the user typed plain ls.

    This matters for this issue in a specific way: any comparison between "documented 40%" and observed results is comparing two different denominators, so the two numbers were never on the same footing to begin with.

    2. The savings floor is written down twice, with different values, and neither one gates anything

    • .claude/rules/cli-testing.md:124 calls ≥60% "the release blocker".
    • CONTRIBUTING.md:268 states the floor as ">=20%".
    • scripts/benchmark.sh:693-694 prints WARNING: …% good (target 60%) without touching EXIT_CODE. Only negative savings and empty output actually fail the script.

    So a broad compression regression would not stop a release, and would not turn a check red. That seems worth knowing in a thread about compression being far below target — it is the mechanism by which such a drift can persist unnoticed. There is a related shape in src/cmds/system/pipe_cmd.rs:574,595, where two filters ship with savings >= 40.0 and a // TODO: grep pipe filter below 60% target.

    3. Some of the exact commands in this benchmark take a path with no output cap

    The dataset here is go test, go build, go vet, make *, git *, pnpm *. make is one of the 63 builtin TOML filters, and that generic path (src/main.rs:1330,1337,1351) uses a bare .output() — the 10 MiB RAW_CAP at src/core/stream.rs:245 guards run_streaming only and is bypassed here — then makes several more full copies (toml_filter.rs:512 builds a Vec<String> per line, :541 rejoins it).

    4. MEASURED: rtk grep costs far more resources than the command it replaces

    Not a compression-ratio point, but it is the cost side of the same ledger, and it was measured rather than reasoned:

    peak working set wall clock
    real grep (20 MB input) 7.9 MiB 289 ms
    rtk grep (same job) 246.8 MiB 1410 ms

    Peak memory scales linearly at roughly 12× the input (5 MB → 69.8 MiB, 20 MB → 246.9 MiB, 40 MB → 481.4 MiB) — to emit 2,579 bytes of output. The cause is in src/cmds/system/search.rs:565-630,682: the uncapped exec_capture result is copied about four times (raw_output = result.stdout.clone() at :568, a HashMap holding one owned String per match at :595-605, a full re-render into plain at :621-630, then match_block per file), and :641-645 adds a fifth by accumulating the full text of every file past the display cap. max_results caps the display, never the intake.

    What I would suggest checking first

    If the goal is to explain the benchmark, item 1 is the one I would test first, because it means rtk's self-reported savings and an external token count are measuring different things — and any tuning done against the internal number would be tuning against a moving target. Items 2–4 are separate and stand on their own.

    Happy to provide the exact repro steps for the memory measurement, or to be corrected on any of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions