Are you TokenMaxxing hard enough? Find out in less than a minute β†’
Open source Β· runs locally Β· no signup

Token Efficiency For AI Agents

TokenJam reads your Claude Code, Codex, and other agent logs and estimates where you can cut tokens: cheaper models, cacheable prefixes, leaner prompts, deterministic scripts.

Open-source. Runs locally. Full observability stack included.

tokenjam β€” first run
$ pipx install tokenjaminstalled tokenjam Β· CLI available as `tj` $ tj onboard --claude-codewired Claude Code telemetry Β· backfilled 247 sessions $ tj optimizeAnalyzing 247 sessions, 9.8K spans, 4.0M tokens (30d)…  downsize  116 sessions look Haiku-eligible (structural)  cache     2.4K-token prefix repeats across 94% of calls  trim      ~770 low-significance tokens in your CLAUDE.md  Estimated recoverable: ~$1,632/mo β€” review before acting $ tj tokenmaxx  Efficiency tier: LeanOperator Β· 38% overhead this cycle

Illustrative output. Every figure is an estimate you review before acting.

How it works

Telemetry from your agents flows into the TokenJam core, through the analyzers, and out to TokenJam Lens and TokenJam Bench.

From your agents

  • Claude
  • OpenAI
  • Anthropic
  • Google
  • AWS
  • Microsoft
  • NVIDIA
  • LiteLLM
  • OTLP
TOKENJAM
Available via CLI Β· MCP Β· Exported config

Reads telemetry from every major agent runtime, framework, provider, and observability tool.

Seven analyzers + Lens. One install.

Each analyzer reads the same captured telemetry and surfaces a different shape of waste. Lens brings them together in a local dashboard you can open in your browser.

Downsize

Find tasks where a cheaper model would suffice.

tj optimize β€” downsize
$ tj optimizeΒ Analyzing 247 sessions, 9.8K spans, 4.0M tokens (last 30d)…   β‘  Model downgrade: 47% of sessions look Haiku-eligible     β€’ 116 of 247 sessions match structural heuristics     β€’ Currently: claude-opus-4-7, claude-sonnet-4-7     β€’ Suggested target: claude-haiku-4-5     β€’ At current usage: $1,886 β†’ $254 (-86% on flagged sessions)     β€’ Estimated monthly savings: $1,632 (-38% total)
See how it works

Trim

Identify token waste in your system prompts.

tj optimize β€” trim
Prompt bloat detected in claude-code-myproj:  β€’ Your CLAUDE.md is 4,213 tokens (up 38% in 30 days)  β€’ Section "Coding conventions > Error handling" appears identically    in 91 of 247 sessions (1,108 tokens Γ— 91 = ~100K repeated tokens)  β€’ Significance analysis suggests ~340 of those 1,108 tokens carry    the signal; the rest could be trimmed  β€’ Estimated cost: ~$8.50/mo at current usage on Sonnet
See how it works

Cache

Detect cacheable prompt prefixes. Save 30–60% with provider-native caching.

tj optimize β€” cache
Cache opportunities in last 30d:  β€’ Identical 2,400-token prefix detected across 94% of your calls    (your CLAUDE.md + tools + system prompt)  β†’ You're already using prompt caching for 11% of cacheable opportunities.  β†’ Increasing cache_control breakpoints could save ~$42/mo (90% reduction     on the 89% of calls currently paying full price).Β   β€’ Semantic similarity β‰₯0.95 detected on 47 instances of "format SQL query"    style requests in last 30d.  β†’ Estimated savings: $8/mo at TTL β‰₯ 1 day.
See how it works

Script

Surface recurring agent sessions that should have been simple (deterministic) scripts.

tj optimize β€” script
Deterministic workflow candidates (high confidence only):  β€’ 23 sessions in last 30d executed identical 5-step sequence:    git pull β†’ npm install β†’ cat .env.staging β†’ npm run build β†’ pm2 restartΒ     Zero argument variation. Zero observed branching.    Estimated current cost: ~$87/mo (23 sessions Γ— ~$3.80 average)Β   β†’ This looks like a deployment script, not an agent task.    Suggested: replace with `scripts/deploy-staging.sh`.    Estimated savings: $87/mo, plus ~30s latency per execution.
See how it works

Reuse

Find planning your agent keeps redoing and pays for every time.

tj optimize β€” reuse
Repeated planning detected (last 30d):  β€’ Cluster "patch-release": 31 sessions share one plan skeleton    (read changelog β†’ bump version β†’ run tests β†’ tag β†’ push)  β€’ Planning portion: ~2,100 tokens/session on claude-opus-4-7  β€’ The skeleton is identical across all 31 runs; only the version    string and date change.  β€’ You paid to generate this plan 31 times.  β€’ Estimated recoverable: ~$54/mo if served from a plan cache    (or ~$61/mo if converted to a slash command)
See how it works

Subagent

Right-size the subagents hiding your session spend.

tj optimize β€” subagent
Subagent right-sizing (last 30d, claude-code):Β   147 subagents across 12 sessions ran in this window.  Subagent spend: $284.10 (66% of window cost).  β€’ researcher-3   opus, 1.2K out, 3 tools    [over_powered]  β€’ summarizer-1   opus, 61K ctx in           [over_provisioned]  Flagged spend to review: $52.60 across 6 subagents.
See how it works

Verbosity

Flag sessions whose output runs long for the task.

tj optimize β€” verbosity
$ tj optimize verbosityΒ Examined 247 sessions across 18 task-shape cohorts (30d)… High-verbosity candidates (top 5 of 14):  β€’ Cohort "edit_file -> run_tests": median output 620 tok  β€’ 1 session ran 1,840 out -- 2.97x the cohort median  β€’ Suggested max_tokens cap: 620 (the baseline, advisory)  Estimated recoverable: ~$18/mo (soft upper bound)
See how it works

Lens

See your spend, your recoverable waste, and your alerts at a glance, in a local browser dashboard.

127.0.0.1:7391/#/overview
OverviewLast 7d
Spend Β· last 7d$284.71
At this pace, ~$1,219 by end of June
(linear run-rate, not a forecast)
Estimated savings
Downsize
$42 / mo
Cache
$31 / mo
Reuse
$54 / mo
3 unread alertsΒ·0 agents drifting
See how it works

All six are in the open-source CLI. Install once, analyze everything.

Benchmark & Evaluate Β· the Prove beat

TokenJam Bench

A downsize candidate is a hypothesis. Bench runs the cheaper model against the original on real task suites and reports, per suite, whether accuracy holds. Pass rate with Wilson confidence intervals and a McNemar p-value, a hedged verdict, never a blanket "safe".

tjb
$ tjb run --suite humaneval,gsm8k --baseline opus --candidate haiku
  running 200 paired tasks per suite…
  humaneval Β· 200/200   gsm8k Β· 200/200
  humaneval REGRESSED   gsm8k HOLDS
  verdict β†’ ./bench-report.json

TokenJam Bench Β· per-suite verdict

Pass rate Β· per suite
humaneval
71/89%regressed
gsm8k
94/95%holds
Run summary
200paired / suite
pβ‰ˆ0.000humaneval McNemar
1 / 2suites held
haiku vs opus Β· Wilson CI Β· measured, never "certified"

Open source. pip install tokenjam-bench.

Analyze. Optimize. Prove.

TokenJam Lens and TokenJam Bench bring all three β€” analyze, optimize, prove β€” into local dashboards you can explore.

Analyze

Capture the telemetry

TokenJam reads from wherever your agent telemetry already lives. On Claude Code or Codex, that's your local log files. If you run Langfuse, Helicone, LangSmith, or Phoenix for observability, it ingests from there. No observability tool? It captures OpenTelemetry directly, into a local store.

Optimize

Surface the savings

Seven analyzers, each grounded in published research and validated against your own data, surface cheaper-model and prompt-trimming candidates with explicit confidence levels. TokenJam never claims a smaller model would have produced an identical answer; it shows candidates with evidence and you act via tj optimize, MCP, or an exported routing config.

Evaluate Β· Prove

Prove a candidate holds

A candidate is a hypothesis, not a guarantee. TokenJam Bench runs the cheaper model against the original on real task suites and reports, per suite, whether accuracy holds: pass rate with Wilson confidence intervals and a McNemar p-value, a hedged verdict (holds or regressed). Measured, never "certified".

Also included

A full observability stack

Everything you'd expect from a tracing tool, running locally alongside the analyzers.

Real-time cost tracking

Every LLM call priced as it happens. Spend per agent, model, session, and tool, visible the moment it occurs.

Trace waterfalls

Full span tree per session. See exactly which tools ran, in what order, and how long each step took.

Sensitive-action alerts

13 alert types, 6 channels (ntfy, Discord, Telegram, webhook, file, stdout). Get pinged before damage is done.

Drift detection

Z-score baselines flag when your agent starts behaving differently. No LLM-on-LLM evaluation required.

Schema validation

Declare a JSON Schema for your tools or let TokenJam infer one. Violations are caught the instant they occur.

Local web UI & REST API

tj serve runs a dashboard at 127.0.0.1:7391. Prometheus metrics at /metrics. No cloud, no signup.

Install

Three commands. Local. No signup.

install
$ pipx install tokenjam$ tj onboard --claude-code$ tj optimize$ pip install tokenjam-bench
Star us on GitHub

Open source Β· MIT Β· runs 100% locally Β· no signup

Get TokenJam updates