TokenJam — local-first OTel-native observability for Autonomous AI agents
Project description
Token Efficiency For AI Agents
TokenJam reads your agent's telemetry and tells you when to downsize, when to trim prompts, what to cache, what to script, and what plans you've already paid to figure out — then shows it all in a local browser dashboard. Runs entirely on your machine.
pipx install tokenjam && tj onboard
The full local tool: captures your agent telemetry, runs the five analyzers, and serves the Lens dashboard + MCP server for Claude Code. Runs entirely on your machine. (pipx recommended — sidesteps PEP 668; pip install tokenjam works in a clean venv.) Just want a 15-second peek with no install? uvx --from tokenjam tj or npx tokenjam reads your existing Claude Code sessions and shows where your quota goes.
No cloud · No signup · No vendor lock-in
⭐ If TokenJam saves you tokens, star it · 👁 Watch for releases — we ship often
15-second peek — no install
Not ready to install? Get the headline in one command:
uvx --from tokenjam tj # or: npx tokenjam
TokenJam ingests your existing Claude Code sessions from
~/.claude/projects/*.jsonl into a throwaway in-memory database and prints:
- Quota composition — what share of your tokens went to re-reading context (history, CLAUDE.md, accumulated tool output) versus net-new work.
- A session timeline — your most recent sessions, token spend, and re-read share.
Nothing is written to disk, no daemon runs, no config is created. For live capture, the Lens dashboard, and the MCP server, use the full install above (pipx install tokenjam && tj onboard).
uvx --from tokenjam tj and npx tokenjam launch the Python CLI via uvx/pipx — see docs/installation.md for the runner requirements and the full install matrix.
Five Analyzers + Lens. One Install.
TokenJam reads telemetry from every major agent runtime, framework, provider, and observability tool and surfaces savings across five areas — then brings them together in a local browser dashboard.
Run all five analyzers with tj optimize. Run several with tj optimize downsize cache reuse.
30-second quickstart
For Claude Code users — zero code, auto-backfills your last 30 days:
pipx install tokenjam
tj onboard --claude-code
tj optimize # cost-saving candidates from your actual usage
tj serve # open the dashboard at http://127.0.0.1:7391/
Onboarding also wires a zero-token statusline into Claude Code — tj statusline runs out-of-band each turn (no model quota) and shows this session's re-read share with a /compact nudge: ◆ Opus 4.8 2.4M tok 🕳️ re-read 95% → /compact to reclaim quota. It does not add an in-loop MCP server (that's an SDK / API surface — an MCP would tax every turn).
That's it. Run tj any time and it points you to the next best action:
_____ _ _
|_ _|__| |_____ _ _ | |__ _ _ __
| |/ _ \ / / -_) ' \ | / _` | ' \
|_|\___/_\_\___|_||_|_/ \__,_|_|_|_|
|__/
TokenJam · cost-optimization for AI agents · local-first, OTel-native · no signup
You're set up. Next best actions:
tj status agent overview — what's running, recent cost
tj tokenmaxx your shareable spend tier
tj optimize cost-saving candidates from your usage
tj serve open Lens (web UI) at http://127.0.0.1:7391/
To upgrade later: pipx upgrade tokenjam (then tj stop && tj serve & to reload the daemon, and tj --version to verify). See docs/installation.md.
For any Python agent:
from tokenjam.sdk import watch
from tokenjam.sdk.integrations.anthropic import patch_anthropic
patch_anthropic()
@watch(agent_id="my-agent")
def run(task: str) -> str:
...
→ Python SDK · TypeScript SDK · Codex · OTel-compatible agents
Lens — the local dashboard
tj serve runs Lens at http://127.0.0.1:7391/: a Dashboard that lands you on recoverable waste and health at a glance, with an embedded explorer to slice your usage any way (metric × dimension × chart); plus Status, Traces, Cost, Analytics, Alerts, Drift, Optimize, and Budget screens. Plan-tier-aware, fully offline, no signup.
→ tokenjam.dev/products/lens for the visual walkthrough.
Beyond optimization
TokenJam is also a full observability stack. The five analyzers and Lens ride on top.
- Real-time cost tracking — every LLM call priced as it happens
- Safety alerts — 13 alert types, 6 channels (ntfy, Discord, Telegram, webhook, file, stdout)
- Behavioral drift detection — Z-score baselines, no LLM required
- Schema validation — declare or infer JSON Schema for tool outputs
- OTel-native — point any OTLP exporter at
tj serveand you're done - Statusline — a zero-token Claude Code status line (
tj statusline, wired bytj onboard --claude-code) showing this session's re-read share + a/compactnudge - MCP server — in-request-path tools for SDK / API users (not Claude Code / Codex subscription users — an in-loop MCP is a per-turn quota burden there; they get the out-of-band statusline instead)
Prove a swap holds — TokenJam Bench
tj optimize downsize flags candidates: cheaper models worth a look. It never claims the cheaper model would have produced the same answer. TokenJam Bench is the companion that checks. It runs your original and candidate models against real task suites and reports the pass-rate difference with statistics (Wilson CI + McNemar), so you get a hedged verdict ("holds" or "regressed") instead of a guess.
pip install tokenjam-bench
tjb run --original anthropic:claude-opus-4-7 --candidate anthropic:claude-haiku-4-5
Bench reports measured pass-rate on a suite, never "certified" or "quality preserved." Open source and local, like TokenJam. Learn more →
CLI
tj optimize # all five cost-optimization analyzers
tj optimize downsize # one analyzer (positional args)
tj tokenmaxx # shareable spend-tier callout
tj status # current cost, tokens, active alerts
tj cost --since 7d # spend by agent / model / day / tool
tj alerts # everything that fired while you were away
tj drift # behavioral drift Z-scores
tj report --reuse # HTML + Markdown skeleton export for the Reuse analyzer
tj backfill claude-code # ingest historical ~/.claude/projects/ sessions
tj serve # start Lens + REST API
Documentation
| Topic | Where |
|---|---|
| 🪶 Downsize / Cache / Script / Trim deep-dives | docs/optimize/ |
| 🔁 Reuse analyzer deep-dive | docs/optimize/reuse.md |
| 🧪 Prove a downsize candidate holds (TokenJam Bench) | tokenjam-bench |
| Claude Code & Codex integration | docs/claude-code-integration.md |
| Harness run grouping (governors / fan-out launchers) | docs/harness-integration.md |
| Python SDK reference | docs/python-sdk.md |
| TypeScript SDK reference | docs/typescript-sdk.md |
| Framework support (LangChain / CrewAI / etc.) | docs/framework-support.md |
| Alert channels & rule reference | docs/alerts.md |
| Backfill from Langfuse / Helicone / OTLP | docs/backfill/ |
| Configuration | docs/configuration.md |
| Architecture deep-dive | docs/architecture.md |
| Installation extras (Trim, framework patches) | docs/installation.md |
| Export to Grafana / Datadog / NDJSON | docs/export.md |
| NemoClaw sandbox observer | docs/nemoclaw-integration.md |
| Release notes | GitHub Releases |
Roadmap
Shipped in 0.3.x: Downsize · Cache · Script · Trim · Claude Code + Codex onboarding · MCP server · Web UI · Backfill adapters (Langfuse, Helicone, OTLP) · Period comparison · Routing-config export · Read-only policy preview
Shipped in 0.4.x:
- TokenJam Lens — local dashboard rebrand: Overview triage front-door, Optimize detail tab, real spend-over-time charts, cross-screen drill-through
- Reuse analyzer — fifth analyzer: detects clusters of sessions with repeated planning, exports reviewable skeleton templates you can convert into slash commands or scripts
- Daemon DB concurrency — per-thread DuckDB cursors so the Overview's fan-out doesn't block on a single shared connection (v0.4.1)
- Cache cost transparency —
cache_read+cache_writetoken columns surfaced in CLI + UI + API (the previously-hidden ~91% cost driver on cache-heavy workloads)
Shipped in 0.5.x:
- Lens Visualizations — an Analytics pivot explorer (metric × dimension × chart, presets, CSV), stacked cost-by-model, a cache-savings chart, KPI sparklines, a cost-annotated trace waterfall, and consistent series coloring
- Merged Dashboard — the explorer and the triage front-door unified into one default screen, with in-place drill-through from recoverable-waste tiles
- First-run polish — backfill fidelity (session-level traces, cache read/write split, honest session counts), plan-tier-aware framing throughout (subscription users see token-share, never raw spend), an onboarding welcome banner + next-steps guidance, and a contribution funnel
Up next (roughly):
- Continued Lens polish + per-product visual branding
-
tj policy add | edit | apply— unified rule surface -
tj replay— replay captured sessions against new model versions - TypeScript framework patches (LangChain JS, OpenAI Agents SDK)
- Vercel AI SDK & Mastra integrations
- Docker image
- GitHub Actions for CI drift/cost checks
Contributing
TokenJam is MIT, and contributions are welcome — from a one-line pricing fix to a whole new framework integration. A few easy on-ramps:
- 🟢 Good first issues → — scoped, newcomer-friendly tasks, ready to pick up.
- 💸 Model pricing —
tokenjam/pricing/models.tomlis community-maintained. Fix a rate or add a model in a single PR — no issue needed. - 🔌 Framework integrations — provider/framework patches follow one clear pattern (
tokenjam/sdk/integrations/anthropic.pyis the reference). Open an issue first to align on approach. - 🤖 Built with coding agents — TokenJam is built by AI coding agents, and contributing with one is first-class. Claude Code: read CLAUDE.md and run
/initto bring your agent up to speed. Codex / other agents: AGENTS.md has the critical rules.
Setup and the full dev workflow are in CONTRIBUTING.md.
If TokenJam saves you tokens, ⭐ star it and 👁 watch for releases — we ship often.
tokenjam.dev · PyPI · npm · TokenJam Bench · Issues
MIT License · Built by Metabuilder Labs
TokenJam was created by Anil Murty — reach him at anil@metabldr.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokenjam-0.5.3.tar.gz.
File metadata
- Download URL: tokenjam-0.5.3.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ad8dd24635ee76ff54a56bc5ab6e5fb0241c3decc93e8ad30059055acbf5887
|
|
| MD5 |
187c61cc8d0c9cb1efeef8424173a640
|
|
| BLAKE2b-256 |
971861183dfc798c7d50c0f956d9f7451662ec10d5a169f0d72502d212881c24
|
Provenance
The following attestation bundles were made for tokenjam-0.5.3.tar.gz:
Publisher:
publish-pypi.yml on Metabuilder-Labs/tokenjam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokenjam-0.5.3.tar.gz -
Subject digest:
6ad8dd24635ee76ff54a56bc5ab6e5fb0241c3decc93e8ad30059055acbf5887 - Sigstore transparency entry: 2063092596
- Sigstore integration time:
-
Permalink:
Metabuilder-Labs/tokenjam@b76b01277b08273f82b2b9d6fb4119a43b0938ba -
Branch / Tag:
refs/tags/v0.5.3 - Owner: https://github.com/Metabuilder-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@b76b01277b08273f82b2b9d6fb4119a43b0938ba -
Trigger Event:
release
-
Statement type:
File details
Details for the file tokenjam-0.5.3-py3-none-any.whl.
File metadata
- Download URL: tokenjam-0.5.3-py3-none-any.whl
- Upload date:
- Size: 710.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3e53d4c1f790203cff5a9476b8079175be07d814ad4222f52662f16e4f6f6d8
|
|
| MD5 |
276f915e151c53296f4edc2b25592e50
|
|
| BLAKE2b-256 |
bdcd4db36881cf2320ca5017b8e0b6de93a596d1c325afd498b7e1e682915948
|
Provenance
The following attestation bundles were made for tokenjam-0.5.3-py3-none-any.whl:
Publisher:
publish-pypi.yml on Metabuilder-Labs/tokenjam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokenjam-0.5.3-py3-none-any.whl -
Subject digest:
b3e53d4c1f790203cff5a9476b8079175be07d814ad4222f52662f16e4f6f6d8 - Sigstore transparency entry: 2063092678
- Sigstore integration time:
-
Permalink:
Metabuilder-Labs/tokenjam@b76b01277b08273f82b2b9d6fb4119a43b0938ba -
Branch / Tag:
refs/tags/v0.5.3 - Owner: https://github.com/Metabuilder-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@b76b01277b08273f82b2b9d6fb4119a43b0938ba -
Trigger Event:
release
-
Statement type: