TokenJam — local-first OTel-native observability for Autonomous AI agents
Project description
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. It then shows it all in a local browser dashboard. Runs entirely on your machine.
No cloud · No signup · No vendor lock-in
Get started
TokenJam ingests telemetry data about your agents from a multitude of sources and provides you a quick and easy way to visualize and optimize cost so that you get the most out of the tokens you pay for.
One command sets up live capture, all six analyzers, Lens (the local dashboard), and the zero-token statusline:
npx tokenjam onboard # or: pipx install tokenjam && tj onboard
tj onboard asks how you use AI agents (Claude Code, Codex, or your own SDK/API agents) and wires the right path; under npx it first offers to make itself a permanent install. For Claude Code and Codex that means backfilling your recent history plus the statusline and hooks; restart and you're live. Then run:
tj optimize # cost-saving candidates from your actual usage
tj serve # open the dashboard at http://127.0.0.1:7391/
The statusline is zero-token; 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).
Run bare tj any time and it points you to the next best action (tj status, tj tokenmaxx, tj optimize, or tj serve).
Just looking? npx tokenjam prints a 15-second read-only report over the logs you already have: no install, nothing kept.
Building your own agent with the SDK: install in your project (pip install tokenjam + tj onboard); see the table below.
npx tokenjam and uvx tokenjam launch the Python CLI via uvx/pipx under the hood; see docs/installation.md for the runner requirements and the full install matrix.
Which path are you?
| You are | Run this | What you get |
|---|---|---|
| Claude Code user | pipx install tokenjam && tj onboard --claude-code |
Auto-backfills your last 30 days, wires a zero-token statusline, unlocks all six analyzers + Lens |
| Codex CLI user | pipx install tokenjam && tj onboard --codex |
Same onboarding flow, wired for Codex's session logs |
| Python SDK / API agent dev | pipx install tokenjam && tj onboard + @watch() in your code (Python SDK) |
Live capture from your own agent process, no CLI-specific backfill |
| Framework user (LangChain / CrewAI / AutoGen) | pip install tokenjam[langchain] (or [crewai] / [autogen]) + one patch_*() call |
Framework-level spans with no manual instrumentation |
| Already on Langfuse / Helicone | tj backfill langfuse --source-url <url> --api-key <key>(swap langfuse → helicone, same flags) |
One-time import of your existing traces into the local DB |
| Any OTel-emitting agent | Point your OTLP exporter at tj serve (http://127.0.0.1:7391/v1/traces) |
Zero-code ingestion: no SDK, no patch |
The --claude-code / --codex flags just pre-answer the wizard's first question; bare tj onboard asks.
LlamaIndex and the OpenAI Agents SDK ship their own native OTel support; point their exporter at tj serve rather than installing an extra. Full matrix: docs/framework-support.md.
A single page walks every path, each ending with a verify step: see docs/getting-started.md.
Six analyzers + Lens. One install.
TokenJam reads telemetry from the major agent runtimes, frameworks, providers, and observability tools and surfaces savings across six areas. It then brings them together in a local browser dashboard.
tj optimize (no args) runs every analyzer: the six above, plus budget-projection (projects your monthly run-rate against a configured [budget.<provider>] ceiling; powers Lens's Budget screen) and cache-recommend (the Cache card's breakpoint-suggestion half, above). Run a subset with tj optimize downsize cache reuse. Lens brings it all together: see the dashboard below.
Lens: the local dashboard
tj serve runs Lens at http://127.0.0.1:7391/: a Dashboard that lands you on recoverable waste and current health, 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 six 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
- Context & quota audits:
tj context(re-read vs. net-new split) andtj quota-audit(retroactive Opus usage check) over your Claude Code sessions - Close the loop:
tj loopannotates a run with a verdict, promotes a bad run into a stored expectation, and tracks whether later runs pass or regress against it - Prompt summarization (advisory):
tj summarizefinds prompt files worth condensing and estimates the per-call saving - Enforcement-plane proxy (suggest mode):
tj proxysurfaces routing suggestions locally, without rewriting requests - 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, since an in-loop MCP would be 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. 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 →
Documentation
| Topic | Where |
|---|---|
| Getting started: every entry path, by persona | docs/getting-started.md |
| The first hour: what to do once data flows | docs/first-hour.md |
| Full CLI reference, every command and flag | docs/cli-reference.md |
| 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 |
| Claude Code vs. Codex vs. SDK vs. OTLP: capability matrix | docs/agent-capability-matrix.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.), including the full OTel provider/framework matrix | docs/framework-support.md |
| Alert channels & rule reference | docs/alerts.md |
| Backfill from Langfuse / Helicone / OTLP | docs/backfill/ |
| Enforcement-plane proxy (suggest mode) | docs/proxy/overview.md |
| Policy rules | docs/policy/overview.md |
| 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: Downsize · Cache · Script · Trim · Reuse · Subagent right-sizing · Claude Code + Codex onboarding · MCP server · Lens web UI · Backfill adapters (Langfuse, Helicone, OTLP) · Period comparison · Routing-config export · Read-only policy preview · Context & quota audits · Close-the-loop annotations/expectations · Prompt summarization (advisory) · Enforcement-plane proxy (suggest mode)
Up next (roughly):
- Continued Lens polish + per-product visual branding
-
tj policy add | edit | apply: unified rule surface (today:tj policy list/tj policy decisions) -
tj replay: replay captured sessions against new model versions - TypeScript framework patches (LangChain JS, OpenAI Agents SDK)
- Vercel AI SDK & Mastra integrations
- Published Docker image
- GitHub Actions for CI drift/cost checks
Full version-by-version history: GitHub Releases.
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.
- Bugs: notice something off? File a bug.
- Documentation: struggled with something while getting started? Help the next person by writing or updating documentation.
- 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. - Coding Agents are first-class citizens: TokenJam is built by Humans AND 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
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.6.tar.gz.
File metadata
- Download URL: tokenjam-0.5.6.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
780457c92be716799a29721da2ee440c756195bb02858a7d85d08ee9f1c75985
|
|
| MD5 |
f67911c13d8384c45d73ac22887b75d2
|
|
| BLAKE2b-256 |
784dd4f62ec2a980956dacc709e48e437e330d5790353dcf8c9de6f9d6a76a43
|
Provenance
The following attestation bundles were made for tokenjam-0.5.6.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.6.tar.gz -
Subject digest:
780457c92be716799a29721da2ee440c756195bb02858a7d85d08ee9f1c75985 - Sigstore transparency entry: 2146405697
- Sigstore integration time:
-
Permalink:
Metabuilder-Labs/tokenjam@9497917ff0c90fccae695aeafa58e2c1204a7d6c -
Branch / Tag:
refs/tags/v0.5.6 - Owner: https://github.com/Metabuilder-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9497917ff0c90fccae695aeafa58e2c1204a7d6c -
Trigger Event:
release
-
Statement type:
File details
Details for the file tokenjam-0.5.6-py3-none-any.whl.
File metadata
- Download URL: tokenjam-0.5.6-py3-none-any.whl
- Upload date:
- Size: 837.0 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 |
38fc90eb8ba7f560e0038a8a2583bc09fe7f9a8b900e7a117d5240887b534763
|
|
| MD5 |
dfdda4a5f106cf76bf9328c1ad73b8a8
|
|
| BLAKE2b-256 |
87826a9b4331a9e7c6ed918149efb8617e968055a97498c030a56d3e7bd1c2d2
|
Provenance
The following attestation bundles were made for tokenjam-0.5.6-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.6-py3-none-any.whl -
Subject digest:
38fc90eb8ba7f560e0038a8a2583bc09fe7f9a8b900e7a117d5240887b534763 - Sigstore transparency entry: 2146405709
- Sigstore integration time:
-
Permalink:
Metabuilder-Labs/tokenjam@9497917ff0c90fccae695aeafa58e2c1204a7d6c -
Branch / Tag:
refs/tags/v0.5.6 - Owner: https://github.com/Metabuilder-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9497917ff0c90fccae695aeafa58e2c1204a7d6c -
Trigger Event:
release
-
Statement type: