Skip to main content

TokenJam: a local-first, OTel-native cost-saving utility for AI agents

Project description

TokenJam: token efficiency for AI agents. Reads your agent's telemetry, finds the waste, runs 100% local.

Reduce token use by up to 40%. TokenJam reads your agent's telemetry, finds overspending, and suggests fixes. Works with Claude Code, Codex, and your own SDK or API agents. Shows it all in a local browser dashboard. Runs entirely on your machine.

CI PyPI Downloads Python npm License: MIT OTel

No cloud · No signup · No vendor lock-in


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.

TokenJam Lens dashboard: past overspend by category, spend and token totals, and sessions by model over the last 30 days.

Get started

One command sets up live capture:

npx tokenjam onboard   # or: pipx install tokenjam && tj onboard

tj onboard asks how you use AI agents and wires that path: live capture, the analyzers your setup can act on, and Lens. Coding-agent users (Claude Code, Codex) also get their recent history backfilled and a zero-token status line wired in; restart the agent and you're live. SDK and API users add @watch() to their own code, or point an OTLP exporter at tj serve.

Then open the dashboard:

tj serve   # Lens, at http://127.0.0.1:7391/

It opens on your spend so far: which models, which sessions, where it went and proposed fixes. Prefer the terminal?

tj optimize          # what your usage is costing, and where it is recoverable
tj rules list        # the fixes that came out of it, and the files they'd land in

tj rules list reads the last analysis, so run it after tj optimize or after the daemon's first cycle. Not sure what to do next? Bare tj always points at the next useful command.

Just looking? npx tokenjam prints a read-only report over the logs you already have. No install, nothing kept.

Same output, fewer tokens: measured spend from Claude Code, Codex, Google (Gemini, ADK), AWS (Bedrock, Strands), the Python and TypeScript SDKs, LangChain/CrewAI, and OTLP/Langfuse flows into tokenjam, which analyzes it and shows how much you are overspending: today's spend against the same work with tokenjam applied, 34% fewer tokens per month, from 14 checks each with a concrete fix

Which path are you?

tj onboard is the entry point for everyone; the table is what it wires for each answer. Your answer also picks your analyzer set, since a coding agent and your own SDK code can change different things. Most analyzers run for both: the full split is below.

You are Run this What you get
Claude Code user tj onboard Backfills your recent history, wires a zero-token status line, unlocks the coding-agent analyzers and Lens
Codex CLI user tj onboard Same flow, wired for Codex's session logs
Python SDK / API dev tj onboard, then @watch() in your code (docs) Live capture from your own process; no CLI backfill
Framework user (LangChain / CrewAI / AutoGen) pip install tokenjam[langchain] and one patch_*() call Framework-level spans, no manual instrumentation
Already on Langfuse / Helicone tj backfill langfuse --source-url <url> --api-key <key> (or helicone) One-time import of your existing traces
Any OTel-emitting agent Point your OTLP exporter at http://127.0.0.1:7391/v1/traces Zero-code ingestion: no SDK, no patch

--claude-code and --codex pre-answer the wizard's first question for scripts and CI; they are shortcuts, not separate setups. Run tj onboard once inside each project you work in, since sessions and proposals group per project in Lens, or tj onboard --add-project to register another repo against a setup you already have.

LlamaIndex and the OpenAI Agents SDK ship native OTel support; point their exporter at tj serve instead of installing an extra. Full matrix: docs/framework-support.md. Every path, each ending with a verify step: docs/getting-started.md.


The analyzers

TokenJam reads telemetry from the major agent runtimes, frameworks, providers, and observability tools, then runs a suite of analyzers over it. They are persona-scoped: Coding agent (Claude Code, Codex), and SDK/API code. tj optimize runs everything your persona can act on; name a subset with tj optimize downsize resend relearn.

Where your tokens go: Expensive model (using Opus for a Haiku-level task) → downsize; Uncached repeats (sending the same base prompt 100s of times) → cache; Bloated prompts (re-sending the same long context every call) → trim; Verbose output (getting 500-word answers to yes/no questions) → verbosity; Repeated planning (re-planning the same task every day) → reuse; Don't need an LLM (paying a model to do what code could) → script.
Analyzer CC SDK Description
relearn Blockers your agent keeps re-hitting across sessions, and what the repeated recovery costs
resend How much of each turn's prompt is context you already sent, whether or not caching is on
summarize Instruction files large enough to tax every session, scanned from disk
downsize Sessions where a cheaper same-family model is a candidate. Never claims quality equivalence
subagent Per-subagent cost hidden inside the parent session's total, and which dispatches ran over-powered
deadweight MCP servers whose schemas load into every session and are never called
cache Your caching ratio per (provider, model), and where it is worst
cache-recommend Where to place prompt-cache breakpoints, from the prefixes you actually repeat
trim Prompt regions the model gives little weight to
verbosity Sessions whose output runs long against a per-(tool, task-shape) baseline
script Deterministic tool sequences a plain script could replace
reuse Sessions where your agent re-plans work it has already planned

They find where your agents are overspending. They also tell you where they are not, so you don't spend a week optimizing something that was never costing you anything.

That balance is why some checks stay dark for you: when the lever that would recover a category of spend belongs to your harness rather than to you, quoting the figure only makes you feel worse. It is also why a quiet result is an answer rather than a failed scan. Optimizing has a price of its own, paid in your attention and sometimes in the agent's output, and a bill lowered by making your agent terser or dumber was never a saving.


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

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.toml is 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.py is 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 /init to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokenjam-0.6.6.tar.gz (7.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokenjam-0.6.6-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file tokenjam-0.6.6.tar.gz.

File metadata

  • Download URL: tokenjam-0.6.6.tar.gz
  • Upload date:
  • Size: 7.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tokenjam-0.6.6.tar.gz
Algorithm Hash digest
SHA256 0f783c2005ad034cd573ef75aa102f28a04974f1725211a1b49e4df11d107c93
MD5 06b23e57361a744cba41ba031b3acf01
BLAKE2b-256 30dd98a8994a614eb8492c7258980b16745a0ad3474bb5d17770471759a290c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenjam-0.6.6.tar.gz:

Publisher: publish-pypi.yml on Metabuilder-Labs/tokenjam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokenjam-0.6.6-py3-none-any.whl.

File metadata

  • Download URL: tokenjam-0.6.6-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tokenjam-0.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 00898793ab6bd196164b39d174a3c8e42c0377903656f5b392ec0acb990bddaa
MD5 ee73df1f1022bf78b25778694f80392a
BLAKE2b-256 42b3c4ea4d445f532acdb58aa9f2f372ff1e3c095d1ac09e7d21e723d52b6e03

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenjam-0.6.6-py3-none-any.whl:

Publisher: publish-pypi.yml on Metabuilder-Labs/tokenjam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page