token-efficient-scripts // claude code plugin · self-benchmarking

Throwaway commands that return less context

For one-off shell/python that searches, counts, or aggregates data, context use is often dominated by what the command prints back to the harness. Ten deterministic experiments preserved every answer: reach for native Grep/Glob/Read first, then bash, then python — and optimize output first, data flow second, code last. And when a command fails, recover cheapest-first instead of reading the man page. When you only need a verdict — tests, builds, git — ask for the quiet form.

Measured: same answer, "count ERROR lines in a 120k-line log" output tokens returned — 99.999% cut
rg
370,940 tokens  — dumps every matching line
rg -c
3
T1Control output
90.4% avg
7 output experiments

Measured: output reductions ranged from 40.64–99.999%; the median was 99.97%. Return the answer, not the data; cap previews; spill complete results to a file when the harness does not need every row.

grep x f  →  grep -c x f
# need it all? → f>out; head -3 out
T2Push filters early
1.68×
measured filter speedup

Measured: filtering a 300k-row TSV before sorting ran 1.68× faster. rg -c ran 6.99× faster than grep on one literal-search workload. Tool speed is platform- and workload-dependent.

sort f | awk '$4==500'
→ awk '$4==500' f | sort
T3Bash first, then trim
40%
fewer command tokens

Default to bash (grep/awk/jq/find) over Python for search/count/filter — reach for Python only when the task truly needs it. For throwaway Python, drop the ceremony: no comments, docstrings, argparse, or main(). Measured: awk vs ceremony-heavy Python cut code tokens 40% but ran 3.29× slower — brevity is a context win, not a speed promise.

# grep/awk one-liner > 12-line py
# throwaway py: no comments/docstrings
v0.6.0 · when the command FAILS — 8 GNU-flag-on-BSD failures, every fix verified tokens to reach the same answers — 98% cut
man cmd
26,316 tokens  — ~3,290 per page, and 2 of the 8 it cannot answer at any price
the ladder
438
↓ escalate cheapest-first · stop at the first hit
1 · re-read the error you have — free, solves 3/8 2 · cmd --help — ~58 tok 3 · man | grep -m3 -B2 -A3 'concept' — ~150 tok 4 · web only if 3 is empty — 8/8 for 3,166 hook DENIES unfiltered man
v0.7.0 · commands run only to CHECK something — tests, builds, git, archives · every answer kept tokens to get the verdict — 97.1% cut
loud default
31,031 tokens  — pytest, compiler spew, git diff, unzip, tar -v
quiet form
893
↓ ask for the verdict, not the log · saves tokens, not time
pytest -q … && echo ok || tail -5 log 2>&1 | grep -m5 'error:' git log --oneline · diff --name-only tar -xf · unzip -q
10-task validation Darwin arm64 · deterministic synthetic data
CORRECTNESS GATE
10 / 10
same task answer · counts, IDs, sums, JSON, previews, stored records, and unique sets verified
ANSWER / PREVIEW / SPILL TASKS
99.16%
combined output reduction · excludes the task that genuinely required the complete JSON value
⚠ guardrails — smaller must equal same
wc -l counts newlines cat glues file boundaries sort before uniq ties ≠ bug compare data, not format shorter ≠ faster awk CSV only when simple head/tail can cut the error
self-benchmarking plugin · v0.7.0 · re-runs weekly, tests its own advice 10 tasks + 8 recovery + 10 verification scenarios · all answers preserved · cl100k proxy, not a universal billing claim