TokenForge
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
TokenForge
Full-stack LLM token optimization engine — the best in the world. The first tool that compresses ALL token sources — code, command output, conversation, JSON, and MCP schemas — with real AST parsing (tree-sitter grammars), semantic diff compression, a built-in MCP server, one-command auto-setup, and lossless reversibility.
Why TokenForge?
Every existing tool solves one slice of the token problem:
RTK — command output only
lean-ctx — lossy compression, no reversibility
claw-compactor — file content only
context-pilot — conversation pruning only
TokenForge is the first full-stack optimizer: a single Rust binary that handles every token source with content-aware compression, lossless storage, quality measurement, and — uniquely — works as a proper MCP server that Claude can call directly.
Related MCP server: token-lens-mcp
Benchmarks (v0.2.0, aggressive)
Engine Type Tokens → After Saved% Quality ns/token
──────────────────────────────────────────────────────────────────────────────────
code:rust (AST) code:rust 762 549 28.0% 88.0 3124
code:python (AST) code:python 643 521 19.0% 88.0 3333
command_output output 422 18 95.7% 75.0 3016
json_payload json 302 55 81.8% 88.0 3404
mcp_schema mcp_schema 390 149 61.8% 95.0 2686Real tree-sitter AST parsing — not regex heuristics.
Architecture
┌─────────────────────────────────────────────────────────┐
│ Claude Code Session │
│ │
│ Tool Call → PostToolUse Hook → TokenForge → Compressed │
│ │ │
│ ┌─────┴─────┐ │
│ │ Engine │ │
│ ├───────────┤ │
│ │ Detect │← Content type │
│ │ Compress │← AST-aware │
│ │ Store │← SQLite+zstd │
│ │ Score │← Quality 0-100│
│ └─────┬─────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ ▼ ▼ ▼ │
│ Code Compressor Output Compressor JSON │
│ (tree-sitter) (ANSI strip, (schema │
│ 12+ languages dedup, summarize) extract)│
│ │ │ │ │
│ ▼ ▼ ▼ │
│ Conversation MCP Schema Learning │
│ (turn scoring, (tiered: (cross- │
│ recency decay) active/deferred) session) │
└─────────────────────────────────────────────────────────┘Features
What's New in v0.2.0
Real tree-sitter AST grammars — Rust, Python, JavaScript, TypeScript. Surgical function body folding at exact CST node boundaries.
MCP server mode —
tokenforge serveruns as a proper JSON-RPC MCP server. Claude calls it directly viaclaude_desktop_config.json.One-command setup —
tokenforge setupauto-configures~/.claude/settings.jsonatomically.Semantic diff compression — Detects when new content is >60% similar to stored content; stores only the diff.
Built-in benchmarks —
tokenforge benchwith real metrics: tokens, savings %, quality score, ns/token.
5 Compression Engines
Engine | What it does | Typical savings |
Code | AST-aware folding — keeps signatures, types, imports; folds large function bodies | 40-70% |
Command Output | Strips ANSI, deduplicates similar lines, summarizes test/compiler output | 50-80% |
Conversation | Scores turns by recency + relevance, compresses low-value turns | 30-60% |
JSON | Schema extraction + array sampling, depth limiting | 60-90% |
MCP Schema | Tiered virtualization — active tools get full schemas, others get names only | 70-95% |
Intelligence
Cross-session learning — Builds project relevance profiles from git history and file access patterns
Pattern analysis — Identifies session types (debugging, code review, feature build) and adjusts compression
Quality scoring — Measures compression quality 0-100, auto-adjusts aggressiveness
Per-category budgets — Allocates token budget across conversation, tool output, code context, and MCP schemas
Lossless Reversibility
Every original is stored in SQLite with zstd compression. Use tokenforge expand <hash> to retrieve any original content — nothing is ever lost.
Installation
From source (recommended)
git clone https://github.com/Manavarya09/tokenforge.git
cd tokenforge
./scripts/build.sh
./scripts/install.shManual
cd core
cargo build --release
cp target/release/tokenforge ~/.cargo/bin/Quick Start
1. Compress tool output
# Compress a file
tokenforge compress src/main.rs --type code --level medium
# Compress command output from stdin
cargo test 2>&1 | tokenforge compress --type output --level aggressive
# Auto-detect content type
cat package.json | tokenforge compress2. Set up as Claude Code hook
Add to ~/.claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"command": "~/.tokenforge/compress-output.sh"
}
]
}
}Now every tool output is automatically compressed before entering the context window.
3. Monitor compression
# View session stats
tokenforge stats
# Analyze patterns
tokenforge analyze
# Check quality
tokenforge quality
# View as JSON
tokenforge stats --json4. Retrieve originals
# Expand compressed content by hash
tokenforge expand abc123def4567895. Configure budgets
# Set total token budget
tokenforge budget --set 80000
# View current allocation
tokenforge budget --show6. Build project profile
# Learn from current project
tokenforge learn --project .CLI Reference
tokenforge — Full-stack LLM token optimization engine
USAGE:
tokenforge [OPTIONS] <COMMAND>
COMMANDS:
compress Compress text/code/output for LLM consumption
hook PostToolUse hook mode (reads JSON from stdin)
stats Show compression statistics
analyze Analyze token usage patterns
budget View or set per-category token budgets
learn Build project relevance profile
quality Show compression quality score
expand Expand compressed content by hash
serve Run as MCP server over stdio (JSON-RPC 2.0)
setup Auto-install PostToolUse hook into ~/.claude/settings.json
bench Benchmark all compression engines with real metrics
OPTIONS:
--json Output as JSON
-v, --verbose Verbose logging
--db-path SQLite database path [default: ~/.tokenforge/tokenforge.db]
-h, --help Print help
-V, --version Print versionMCP Server Mode
Add TokenForge as an MCP server so Claude can compress on-demand:
claude_desktop_config.json:
{
"mcpServers": {
"tokenforge": {
"command": "tokenforge",
"args": ["serve"]
}
}
}Claude now has access to 4 new tools: tokenforge_compress, tokenforge_expand, tokenforge_stats, tokenforge_bench.
One-Command Setup
tokenforge setup # auto-configures ~/.claude/settings.json
tokenforge setup --dry-run # preview without writingCompression Levels
Level | Code | Output | JSON | Use when |
| Keep 100+ line functions | Max 200 lines | Depth 5 | Early in session, exploring |
| Fold 50+ line functions | Max 80 lines | Depth 3 | Normal development |
| Fold 20+ line functions | Max 30 lines | Depth 2 | Context pressure, debugging |
MCP Tools
TokenForge exposes 4 MCP tools for programmatic access:
tokenforge_stats— Compression statisticstokenforge_expand— Retrieve original content by hashtokenforge_budget— View/set token budgetstokenforge_expand_tool— Retrieve full MCP tool schema
Performance
< 5ms for small outputs (< 1KB)
< 50ms for large outputs (> 100KB)
< 15MB binary size (release, stripped, LTO)
Zero runtime dependencies — single static binary
Tech Stack
Rust — Zero-cost abstractions, no GC pauses in the hot path
tree-sitter — Industrial-grade AST parsing for 12+ languages
SQLite (rusqlite, bundled) — Full-fidelity state persistence
zstd — Fast compression for stored originals
tiktoken (cl100k_base) — Accurate OpenAI-compatible token counting
blake3 — Fast content hashing for deduplication
License
MIT
Built by @masyv as a Claude Code plugin.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
A hosted MCP suite providing workflow primitives: web search, content fetching, compression, deduplication, cost/budget management, and agent memory pipelines.
Multiple MCP tools, persistent graph memory, token-saving data pointers, and more.
Provenance and metadata tools for AI agents. Paid tools use x402 (USDC) at /mcp/<tool>.
A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides context compression via the tokenslim engine, enabling MCP hosts to reduce token usage while preserving key information. Offers compress, retrieve, and stats tools for managing compressed content.Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables analyzing and optimizing context window token usage by measuring, compressing, and eliminating waste from MCP tool definitions.59 npmMIT
- AlicenseNot gradedqualityDmaintenanceA local, zero-cloud MCP server for token and text compression. It provides tools to compress, auto-compress, measure, and decompress text using offline rules, lossless gzip packing, or a local Ollama semantic model.1MIT
- AlicenseNot gradedqualityDmaintenanceLossless context compression for LLMs, packing text into 2x-8x fewer tokens with byte-exact reconstruction. Provides MCP tools to compress files/text and expand exact slices, verified by sha256.8MIT