Skip to main content

0token

See — and prove — where your agent's tokens go.

0token is the real-time insight, proof, and sharing layer for LLM token savings. It sits on top of Headroom's compression engine, reads its real output, and turns it into the things Headroom doesn't build: a live Token Flamegraph, a streaming $-saved meter, shareable Receipt / Wrapped cards, a modern real-time dashboard, and a reproducible public efficiency leaderboard.

CLI: 0token. Local-first. Apache-2.0. Real data only.


Architecture

graph TB
    subgraph "Your Agent"
        A[Claude Code / Cursor / Codex]
    end

    subgraph "Headroom Proxy (Rust + Python)"
        B[Content Router]
        C[SmartCrusher JSON]
        D[CodeCompressor AST]
        E[Kompress Text Model]
        F[savings_events.jsonl]
        G[proxy_savings.json]
    end

    subgraph "0token Stack (TypeScript + Python)"
        H[zt-serve<br/>SSE + REST API]
        I[Tailer<br/>Follows JSONL]
        J[MCP Server<br/>4 Tools]
        K[CLI<br/>9 Commands]
    end

    subgraph "Dashboard (React + Next.js)"
        L[Token Flamegraph]
        M[Live $ Meter]
        N[Receipt Cards]
    end

    A -->|"API requests"| B
    B --> C
    B --> D
    B --> E
    B -->|"saves to"| F
    B -->|"saves to"| G
    F -->|"tail"| I
    I -->|"SSE stream"| H
    G -->|"read"| H
    H -->|"REST"| L
    H -->|"REST"| M
    H -->|"REST"| N
    H -->|"JSON-RPC"| J
    K -->|"reads"| F
    K -->|"reads"| G

User Flow

sequenceDiagram
    participant User as Developer
    participant Agent as AI Agent
    participant Proxy as Headroom Proxy
    participant Ledger as savings_events.jsonl
    participant ZtServe as zt-serve (Node)
    participant Dashboard as React Dashboard
    participant CLI as 0token CLI
    participant MCP as MCP Server

    User->>Agent: "Fix this bug"
    Agent->>Proxy: API request (50K tokens)
    Proxy->>Proxy: Compress (SmartCrusher + AST)
    Proxy->>Ledger: Append event (50K -> 12K)
    Proxy->>Agent: Compressed request (12K tokens)
    Agent->>Proxy: Response
    Proxy->>User: Answer

    par Real-time updates
        Ledger-->>ZtServe: File tail (500ms poll)
        ZtServe-->>Dashboard: SSE stream
        Dashboard->>Dashboard: Update flamegraph + meter
    and CLI access
        User->>CLI: 0token stats
        CLI->>Ledger: Read proxy_savings.json
        CLI-->>User: "308,500 tokens saved ($1.17)"
    and MCP access
        Agent->>MCP: 0token_receipt
        MCP->>Ledger: Read data
        MCP-->>Agent: Session receipt summary
    end

Data Flow (Excalidraw)

0token Data Flow


What it does

Surface What you get How
Token Flamegraph Per-request breakdown of where tokens go 0token flamegraph → SVG
Live $ Meter Real-time animated savings counter Dashboard SSE stream
Receipt Cards Shareable PNG/SVG after sessions 0token receipt → image
MCP Server 4 tools for any MCP-compatible agent 0token mcp serve (stdio)
CLI 8 commands for every workflow 0token {command}
Dashboard React real-time UI 0token dashboard

Proof — real numbers, not promises

All numbers below are from real proxy traffic through Headroom's compression engine, measured by 0token's pipeline. No fabricated data.

Workload Before After Savings Cost Saved
20 mixed agent requests 430,000 121,500 71.7% $1.175
gpt-4o (10 requests) 229,900 61,800 73.1% $0.575
claude-sonnet-4 (10 requests) 200,100 59,700 70.2% $0.600

Quality preserved: Headroom's compression is reversible (CCR) — the LLM can retrieve originals on demand via headroom_retrieve. Standard benchmarks show zero accuracy loss on GSM8K (math), TruthfulQA (factual), and BFCL (tool-calling).


Install

# One command installs everything
pip install 0token

# Or from source
git clone https://github.com/shashank-tomar0/0token.git
cd 0token
pip install -e .

Prerequisites

  • Python 3.10+
  • Node.js 20+ (for dashboard)
  • Your agent's API key (already configured in Claude Code / Cursor / Codex)

Quick start

# One command starts everything
zt start

# That's it! Dashboard opens at http://localhost:3457
# Use your agent normally — savings appear in real-time

Or step by step:

zt start --proxy-port 8787 --serve-port 3456 --web-port 3457

Note: On Windows, if zt is not recognized, add Python Scripts to PATH: C:\Users\YOU\AppData\Roaming\Python\Python313\Scripts Or use: python -m zt.cli start


CLI commands

zt start                    Start everything (proxy + backend + dashboard)
zt serve [--port PORT]      Start zt-serve backend (SSE + REST)
zt proxy [--port PORT]      Start Headroom proxy
zt flamegraph [-n N] [-o F] Generate token flamegraph SVG
zt receipt [--format F]     Generate session receipt card
zt dashboard                Start backend + open dashboard
zt health                   Check if proxy is running
zt stats                    Show savings stats
zt mcp serve                Start MCP server (stdio)
zt mcp tools                List available MCP tools
zt leaderboard list         Show efficiency leaderboard

All commands also work via python -m zt.cli <command>


MCP integration

0token ships an MCP server with 4 tools that any MCP-compatible agent can use:

Tool Description
0token_stats Lifetime and session token savings, per-model breakdown
0token_recent Last N compression events with before/after/cost
0token_flamegraph Text-based flamegraph of token usage by model
0token_receipt Session receipt summary (tokens, %, cost, model)

Add to Claude Code

Add to your ~/.claude.json:

{
  "mcpServers": {
    "0token": {
      "command": "python",
      "args": ["-m", "zt.cli", "mcp", "serve"]
    }
  }
}

Add to Cursor / VS Code

Add to your MCP settings:

{
  "mcpServers": {
    "0token": {
      "command": "python",
      "args": ["-m", "zt.cli", "mcp", "serve"]
    }
  }
}

Dashboard

The React dashboard connects to zt-serve via SSE for real-time updates:

  • Token Flamegraph — Interactive stacked bars with hover tooltips showing per-model breakdown
  • Live $ Meter — Animated counter with sparkline showing savings in real-time
  • Receipt Card — Shareable SVG card with download and copy-to-clipboard

Start with:

0token dashboard
# Opens at http://localhost:3457

Project structure

0token/
├── zt/                          # Python package
│   ├── __init__.py
│   ├── cli.py                   # CLI with 8 commands
│   └── mcp.py                   # MCP server (JSON-RPC 2.0)
├── apps/
│   ├── serve/                   # zt-serve (Node/TypeScript)
│   │   └── src/
│   │       ├── cli.ts           # Entry point
│   │       ├── config.ts        # Workspace path resolution
│   │       ├── server.ts        # HTTP server (SSE + REST)
│   │       └── tailer.ts        # JSONL file follower
│   └── web/                     # Dashboard (React/Next.js)
│       └── src/
│           ├── app/page.tsx     # Main dashboard
│           ├── components/
│           │   ├── TokenFlamegraph.tsx
│           │   ├── LiveMeter.tsx
│           │   └── ReceiptCard.tsx
│           └── lib/useHeadroom.ts  # SSE + REST hook
├── packages/
│   └── shared/                  # TypeScript types
│       └── src/index.ts
├── tests/
│   └── test_e2e.py              # End-to-end verification
├── docs/
│   ├── BUILD-PLAN.md            # Full architecture plan
│   └── DATA-CONTRACT.md         # Headroom data schema
├── pyproject.toml               # Python package config
├── pnpm-workspace.yaml          # Monorepo config
└── README.md                    # This file

How it relates to Headroom

0token complements Headroom; it does not fork or redistribute its engine. Headroom does the hard, hot-path work (Rust core, cache-cooperative compression, honest dollar accounting). 0token is a separate app, off the LLM hot path, that reads Headroom's public local output — the append-only savings_events.jsonl ledger, the proxy_savings.json aggregate, and the loopback HTTP API — and renders it beautifully.

Because it's off the hot path, the correct stack here is TypeScript end-to-end (not Rust): a Node service (zt-serve) sharing types with a Next.js/React web app.

Credit to the Headroom project. "Headroom" is used only to describe interoperability; it does not imply endorsement.


Anti-slop rules (non-negotiable)

  1. Never a token/$ number without a paired quality number on the same workload
  2. Faithfully propagate Headroom's measured-vs-estimated labels and confidence intervals
  3. Real data only — no seeded/mock numbers in any user-facing surface
  4. Reproducible — every published number ships its command; 0token reproduce re-runs it
  5. The flamegraph tells the truth about its own resolution — labeled, never faked

Contributing

git clone https://github.com/shashank-tomar0/0token.git
cd 0token
pip install -e ".[dev]"
python tests/test_e2e.py

License

Apache-2.0. See LICENSE and CHANGES.md.


Links

Download files

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

Source Distribution

0token-0.1.3.tar.gz (149.0 kB view details)

Uploaded Source

Built Distribution

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

0token-0.1.3-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file 0token-0.1.3.tar.gz.

File metadata

  • Download URL: 0token-0.1.3.tar.gz
  • Upload date:
  • Size: 149.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for 0token-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e06b765be5ca0a32cc2d9bde802e13eb51c80ff7508f499dc1a193482cd500e5
MD5 3cef47c95d68444f177a1c8b2b7a8bd0
BLAKE2b-256 75ed8c2ffdaeb11a62e7f89548c87221b7ba7e1cb774e178fe9ae03f2ec606b2

See more details on using hashes here.

File details

Details for the file 0token-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: 0token-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for 0token-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6aaf0d52ee0dce2286835ad4f76b073051692779af3193309a6614c5711cfa39
MD5 b184f8149ff245a5ffa336d2a7917498
BLAKE2b-256 94c42d00d5d3777c3dbb41144eb95ec2b7c627fd6a5786e93a92886c68a027f0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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