TokenSafe
TokenSafe is a local MCP server that cuts token usage for AI coding agents by replacing raw file reads, greps, and log dumps with AST-sliced, searchable, guarded, runtime-aware context.
smart_read_file— Read only what matters: a single symbol, a repo route (endpoint="POST /api/x"→ handler body, path, lines, version) in one call, or 2–8 targets batched; folds uncalled code into typed signatures (dep_mode), with line ranges and force-full fallback for.d.tspackages.scoped_search— Grep/find replacement with scope and mode control (text, regex, glob, fuzzy, git), plus batched multi-query runs (up to 20) to avoid repeated tool calls.apply_edits— Multi-hunk edits across up to 50 files, with create/overwrite,dry_run, auto-scoping from read windows, and inlineverify(includingauto= the project's declared test command) so the edit and its verdict return together.repo_map— Structural overview without crawling: dependency/God-Node graph, exported API surface, or directory tree, with depth control and multi-repoproject_path.session_context— Context hygiene: budget scoring (S–F), transcript compaction into a state ledger, pruning superseded reads, a dead-ends/mistakes ledger, and savings metrics.oumv— Live runtime protocol:status, progressiveobserve(L0–L4),understandcausality/routes,verify, OCC-guardedmutate,graph, repo-wideindexsymbol search,previewdry-run diffs,build/test runs, and cooperativecancel.run_helper— Utility belt: command output sanitizing, pre-flight securityguard, diff slicing, dependency/lockfile summaries, web page → compact Markdown, hash-anchorexpandfor reversible stashes, image downscaling, and prompt compression.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@TokenSafe skeletonize src/auth.ts and distill my prompt to cut token usage"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
What's New in v4.0
TokenSafe 4.0 is a major architecture release designed for Zero Mid-Day Lockouts, 3-Second Turn Latency, Exact Code Context (Zero Loss), and Developer Flow:
⚡ SQLite FTS5 BM25 Code Indexer & Search (
scoped_search,tokensafe search): Native SQLite full-text search with trigram tokenization and BM25 relevance ranking (<1ms) across the repository. Replaces raw terminal grep entirely with zero-token-waste search.🔗 SQLite Graph Cache & Cross-Boundary Route Linking: Persistent SQLite caching (
.tokensafe/cache/graph.db) with bidirectional semantic linking between frontend client endpoints (fetch,axios,apiClient) and backend HTTP routes (FastAPI,Express,Flask,Next.js).🖼️ Vision Image Downscaler (
optimize_image,tokensafe optimize-image): Automatically scales down oversized screenshots, architecture diagrams, and mockups (>1024px) via Pillow or macOSsips, saving 50–75% vision tokens while keeping original files intact.🧠 Anti-Stuck Dead-Ends Ledger (
get_mistakes,tokensafe mistakes): Persistent project memory tracking failed hypotheses, loop guard trips, and git reverts to prevent agents from cycling through already-failed solutions.🧹 Transcript Superseded Output Pruning (
prune_superseded,tokensafe prune-superseded): Prunes obsolete intermediate tool reads that were superseded by subsequent edits or re-reads in long agent transcripts (-30-40% context).🧼 ANSI Escape Sequence Stripper: Cleans all ANSI/VT100 escape codes from tool outputs, test runners, and proxy streams before they enter model context.
👻 Ghost Tokens Auditor (
tokensafe doctor): Detects and cleans redundant multi-IDE configuration files (.cursorrules,CLAUDE.md,.windsurfrules,.clinerules) and oversized rule files, saving 2,000–5,000 wasted ghost tokens on every turn.🛡️ Exact Code Context & Reversible Stash (
expand_ref): 100% byte-exact target symbol preservation with reversible 8-char hash anchors (#a1b2c3d4) to instantly recover any folded block.🌲 C# Tree-sitter Support: Native AST slicing and God Nodes detection for C# (
tree-sitter-c-sharp) alongside TypeScript, JavaScript, Python, Go, Rust, Java, Kotlin, and PHP.
Related MCP server: ContextPrism
Install & Agents
Connect TokenSafe to the AI coding agents on your workstation in one command:
# Option 1: Zero-Install via npx (recommended)
npx tokensafe
# Option 2: Python / PyPI
pip install tokensafe && tokensafe
# Option 3: Direct shell script (macOS / Linux)
curl -fsSL https://tokensafe.dev/install.sh | bashThe installer detects which agents live on your machine, registers the TokenSafe MCP server, injects project rules, and wires lifecycle hooks where the agent supports them.
Runtime requirements
CPython 3.10+ (3.11+ recommended). If no suitable interpreter is found, the npm launcher provisions a pinned, SHA-256-verified CPython 3.12 build into
~/.tokensafe/runtimeand installs the dependencies there, so TokenSafe works on a machine without Python. One-time download: 25 MB on macOS, 47 MB on Windows, 53-68 MB on Linux. Opt out withTOKENSAFE_NO_DOWNLOAD=1, force a specific interpreter withTOKENSAFE_PYTHON=/path/to/python3, relocate the whole tree withTOKENSAFE_HOME.cryptography>=42.0is the only required Python dependency (Ed25519 license checks, under 1 ms per validation).Optional accelerators, installed by default but not required:
tree-sitterplus grammar wheels for AST-accurate slicing across 10 languages (without them the slicer falls back to stdlib heuristics; disable withTOKENSAFE_TREESITTER=off), andPillowfor cross-platform image downscaling (macOS falls back tosips).The managed runtime is pinned in
bin/python-runtime.json: CPython 3.12.16 fromastral-sh/python-build-standalone, five platform builds, every archive verified against a hardcoded SHA-256 before extraction.
Agent | Integration |
Google Antigravity | Plugin symlink + hooks + skills + MCP (loaded automatically on startup) |
Claude Code CLI | MCP + |
Cursor | MCP + |
Claude Desktop | MCP registration ( |
Windsurf | MCP registration + global rules |
OpenAI Codex | MCP in |
Cline / Roo Code | MCP registration (VS Code) |
GitHub Copilot | MCP registration |
Z.ai Code | MCP registration |
Kimi Code | Native Plugin ( |
ChatGPT | Cloud connector, nothing to install |
Claude Desktop / Cursor MCP config:
{
"mcpServers": {
"tokensafe": { "command": "npx", "args": ["-y", "tokensafe", "mcp"] }
}
}Cloud features (team metrics, managed distillation, shared team cache, billing) run on the remote endpoint https://api.tokensafe.dev/mcp with Authorization: Bearer <TS2. license key>. Four public tools work without a key, so ChatGPT connects with authentication set to None.
Full per-agent configuration, hook details, and the Codex/ChatGPT setup live in docs/AGENT_SETUP.md.
CLI Quickstart
# View live savings dashboard in your terminal
tokensafe stats⚡ TOKENSAFE CONTEXT OPTIMIZER DASHBOARD
Total Tokens Saved: 4,524,156 tokens
Efficiency Gain: [████████████████████████░░] 92.5%
Context Traffic: 4,889,255 raw → 370,574 optimized (2,132 events)
• Command Sanitizer (CLI) : 727,300 tokens saved (263 events)
• Architecture Graph : 758,256 tokens saved (13 events)
• Multi-turn History Fold : 2,897,897 tokens saved (471 events)
• Prompt Compactor (local+cache) : 43,502 tokens saved (1,255 events)# Audit your environment: MCP tool overhead, skills tax, risky settings
tokensafe doctor
# Recursive security & hygiene audit of a repository
tokensafe guard audit
# Preview prompt compaction on custom input
tokensafe test "fix the validate_token method in src/auth.py to check jwt expiration"
# Map architectural hotspots before multi-file changes
tokensafe graph
# Disable a heavy MCP server without editing JSON
tokensafe mcp disable <server>
# Compile and preview the Friday team ROI digest
tokensafe digest
# Scaffold a new token-optimized project for AI agents
tokensafe create my-app --template fullstack # tokensafe-ui + tokensafe-python
tokensafe create my-service --template go # tokensafe-backend (Go)
# Retrofit existing apps for AI agents (out-of-the-box stack detection)
tokensafe integrate # Generates .tokensafe/oumv.json with safe defaults
tokensafe adapters # Catalog of frontend & backend OUMV adapters
tokensafe oumv doctor # Verify live dev-server & static AST capabilities
# Activate a Team or Solo license key
tokensafe activate TS2.eyJlbWFpbCI6...The full command reference (24 commands) is in Reference.
Why TokenSafe
Giving coding agents raw access to entire repositories creates three daily costs:
Senior hours burned on AI PRs: reading 2,000-line modules for a 10-line fix makes models forget imports, invent methods, and regress adjacent code.
Secret leaks and unsafe shortcuts: static prompt rules in
.cursorruleswear off mid-session. Agents hardcode fallback credentials, disable TLS checks, or stage.envfiles withgit add ..Mid-sprint quota stops and blind spend: bloated diffs, lockfiles, and verbose MCP schemas burn 5-hour limits while engineering leads lack per-seat ROI visibility.
Outcome | What changes for your team | How it is enforced |
Clean code on the first pass | Agents read only target functions, design tokens, and 1-hop dependencies instead of 2,000 lines of noise. | Sub-30ms local AST skeletonizer, architecture graph, predictive signature prefetch, lockfile-stripping diff slicer, loop guard. |
Zero leaked secrets in git | Hardcoded password fallbacks, TLS bypasses, raw SQL interpolation, and | Deterministic TokenSafe Guard on every tool call, output guard on large writes, local PII/key redaction. |
Predictable sprint velocity & ROI | Teammates get warm cache hits, and CTOs receive a Friday ROI digest separating | Shared team cache, live context budget HUD, per-seat dashboard. |
A $29 seat pays for itself by saving one hour of senior code review or preventing one leaked key. Typical payback: 1 to 3 days of team usage.
Before and After
One contrast: an agent asked to change one helper in a 1,420-line file receives 94 lines of target logic and type contracts instead of the whole module. The same principle applies to terminal output, diffs, and session history.
What breaks coding agents | How TokenSafe fixes it | The outcome |
"Lost in the Middle" context fade: an agent reads a 2,000-line file to change one 10-line helper, forgets imports, and invents methods. | AST skeletonizer folds inert bodies into typed signatures while keeping the target symbol and 1-hop callees intact. | Focused signal: the model keeps full type contracts without drowning in unrelated logic. |
Terminal log flooding: | Command sanitizer strips lockfile noise and trims output to the failing assertion and stack frame. | Root-cause fixes instead of unrelated rewrites. |
Infinite wait on background tests: | Test-runner guard forces run-once mode ( | The test run terminates with an exit code and the agent moves on. |
5-attempt retry loops: an agent repeats the same broken edit until the context budget runs dry. | Loop guard detects repeated identical tool calls and halts the cycle. | Stuck loops stop before damaging working modules. |
Unsafe edits & secret leaks: fallback keys, | TokenSafe Guard audits writes and shell commands locally before execution. | Credentials, SQLi patterns, and destructive commands are blocked locally. |
When an operation is blocked, the agent sees an explicit, constructive message:
🛡️ TokenSafe Guard: Blocked a hardcoded secret fallback in config.py.
Leave the default empty or read from os.environ at runtime.10 Core Engine Capabilities
Why TokenSafe agents ship working code on the first pass without burning quotas or leaking keys:
Capability | What it solves | How it works | Impact |
1. Architecture Graph | Agents open an unfamiliar repo and burn 45k tokens blindly crawling files. | Analyzes dependency centrality, import hubs, and critical call paths in memory. | < 250 tokens to map God Nodes (vs ~45k blind crawl) |
2. Smart Code Slicing | Feeding 3,000 lines into context causes models to hallucinate fake methods. | Preserves target method logic while folding uncalled helpers into typed contracts. | -95.0% tokens (192 vs 3,840) across 11 languages |
3. Pre-Git Security Guard | Autonomous agents read | Sub-millisecond pre-flight interception blocks secrets, TLS bypasses, and dangerous commands. | 0 leaked keys in LLM logs or git history |
4. Lockfile & Noise Shield | Reading | Intercepts lockfiles and massive schemas, returning a queryable dependency summary. | -99.8% tokens (855 vs 367,410 tokens) |
5. Monorepo API Surface Map | Agents guess interfaces or crawl dozens of modules to find exported types. | Extracts all exported types, interfaces, and contracts across the repo in one pass. | 1 tool call vs 50 separate file reads |
6. Subagent Pointer Cache | Multi-turn chats and swarms pay full price to re-read the same shared utilities. | In-memory content hashes return 1-line pointer hits for unchanged files. | 0 tokens wasted on repeat file reads |
7. Shared Team Cache | 10 to 50 engineers repeatedly parse the same core libraries from scratch. | L3 monorepo pool shares stripped signatures and package contracts across teammates. | 72% team hits with 0ms turnaround |
8. KV-Cache Prefix Locking | Shifting timestamps and reordered tools break provider prompt cache hits. | Locks prefix order, sorts schemas, and injects breakpoints for Anthropic, DeepSeek, and OpenAI. | 92% cache hit rate at 0.10x provider rates |
9. Compact Test Runner | Test suites spew 1,000 lines of passing dots that crowd out instructions. | Forces run-once mode ( | 1 line vs 1,200 lines (traces kept on failure) |
10. Context Governor & Ledger | Models suffer needle-in-a-haystack amnesia after 70% context saturation. | Monitors context thresholds and compacts chat sprawl into an actionable State Ledger. | 50+ turns without regression or amnesia |
Deeper mechanics (language matrix, AST syntax trees, cache tiers, governor) live in docs/ARCHITECTURE.md.
Context survival, recall, and host coverage
Compaction is the most expensive event in a long session: the host rewrites the prompt, re-bills it uncached, and drops turns the task still depends on. TokenSafe now survives it explicitly.
Feature | Surface | What it does |
Post-compaction recovery | Claude Code | Reinjects a small digest: goal, last state, next focus, and up to five ranked pointers to the turns the compaction dropped. Each pointer expands with |
Transcript recall | CLI | BM25F search over prior Claude/Codex/Kimi/ZCode/Cursor/Antigravity transcripts. No index copy; snippets are secret-redacted and output is budget-capped. |
Zero-token statusline | Claude Code |
|
Claude Code plugin |
| Marketplace manifest, nine lifecycle hooks (including compact events), and an MCP entry. The plugin fails open if the Python engine is absent. |
Host capability matrix |
| States exactly which host supports hooks, compact events, context injection, statusline, and transcript parsing, so partial coverage is never sold as full. |
Only hosts with a context-injection surface receive hook-injected digests (Claude Code, ZCode, Kimi Code, Antigravity). Cursor, Codex, Claude Desktop, Windsurf, Cline/Roo, and Copilot get the MCP tools, rules, transcript recall, and the fallback compaction detector; their host contracts expose no equivalent injection point today.
What happens on the first prompt
You install TokenSafe, open a project in your agent, and the first turn does the wiring:
Detect the stack (React/Vue/Solid/Angular + Vite, FastAPI, Flask, Django, Go/Gin|Chi, Node/Express|Fastify, Next.js, Elysia on Bun, ASP.NET Core, Spring, Laravel/Symfony, or nothing supported) — every supported app in a monorepo, not just the first.
Activate the adapters:
frontend —
tokensafe devserves OUMV from an inline Vite config; no file in the repository changes;FastAPI — a global
~/.tokensafe/pyhooks/sitecustomize.pymountsmount_tokensafe(app)when the server runs throughtokensafe run-backend uvicorn ...;Go — one
AutoMount()line betweentokensafe:oumvmarkers, byte-exact backup in~/.tokensafe/inject/,go buildvalidated;--revertrestores the entrypoint andgo.mod/go.sumwhen they were not edited after inject (net/http gets a printed manual recipe instead, and Echo is reported as planned);Node (Express/Fastify) — one
mountTokensafe(app)/registerTokensafe(app)line, same markers and byte-exact revert; ASP.NET Core — oneAddTokensafe()/UseTokensafe()pair;Next.js (App Router) — three generated files:
app/api/tokensafe/route.ts(createNextRouteHandlers, bridge on),app/api/tokensafe/bridge/route.ts(the browser bridge) andinstrumentation-client.ts(installNextBridge, Next ≥ 15.3); older Next gets the two route files plus a manual snippet.--revertdeletes exactly the files it created and restores a pre-existing v1 route it upgraded;Elysia (Bun) — one
app.use(oumv())line beforeapp.listen()(tokensafe-backend-node/elysia), same markers and byte-exact revert;Flask / Django — certified WSGI adapters mounted explicitly:
mount_tokensafe(app)in the app factory (wrapsapp.wsgi_app) ormount_tokensafe(application)inwsgi.py;tokensafe inject --statusprints the recipe and writes nothing, because the WSGI application is yours to wrap.
Brief the agent — a short routing block (hook context and MCP
instructions) says which stack is worked through OUMV and which through the TokenSafe tools. Nothing is written into the repository by the brief.
Without a live runtime oumv stays useful and says what it did: observe/understand/index
answer from the static graph, verify answers a labelled static subset (OFFLINE_STATIC_VERIFY:
file exists, syntax, OCC version, symbol/route presence) instead of failing, and observe on a
file at L1+ returns the same skeleton a read would and seeds the read cache — a later
smart_read_file on that file returns a pointer instead of the body again.
tokensafe inject --status # what would be wired, and where
tokensafe inject --dry-run # same, but explicit
tokensafe inject # apply every detected app (config + Python autoload + adapter lines)
tokensafe inject --revert # undo every patch: Go entrypoint/modules, .NET csproj, Next files, Python hook, config
tokensafe create shop --template react-fastapi # greenfield with everything pre-wired
tokensafe oumv doctor # readiness: adapter installed? runtime live? blocking reasonsFull matrix and details: docs/OUMV.md.
Benchmarks
Measured agent matrix v7 (Go + React, DeepSeek — 3 tasks × 5 runs × 3 arms)
Real 12-assertion oracle re-run after every step; tokens and cost from the provider's usage
payload. baseline = file/search/command tools, tokensafe = this product's MCP server
(smart_read_file(endpoint="POST /api/…") in one call → apply_edits with the hunk and inline
verify="auto"), oumv = the OUMV runtime measured in November 2026 (observe L3 returns the handler, its
version and the same-package callees; applyEdit mode=patch carries an inline verify probe and
an actionable -32009). The Go sandbox is the benchmark module plus 200 generated service
files; the React sandbox is a TaskManager store + component whose declared npm test is the
oracle.
Arm | Solved | Mean steps | Mean input | Mean output | Cost/run |
| 15/15 | 5.9 | 32,231 | 1,712 | $0.0051 |
| 15/15 | 3.1 | 8,240 | 401 | $0.0012 |
| 15/15 | 2.7 | 6,712 | 433 | $0.0011 |
| 15/15 | 4.9 | 18,396 | 1,591 | $0.0033 |
| 15/15 | 4.3 | 11,971 | 507 | $0.0017 |
| 15/15 | 4.2 | 9,814 | 642 | $0.0016 |
vs baseline — Go: oumv -79.2% input, -77.8% cost,
-55.1% steps; tokensafe -74.4%,
-76.4%, -48.3%. React: oumv
-46.7% input, -52.7% cost, -14.9%
steps; tokensafe -34.9%, -50.4%,
-12.2%. Every session in both matrices solved — the v6 max-steps
flounder on product-validation is gone. On Go the protocol arm creates the fix in 2.0 calls
against the product arm's 3.2 and ties it on the other two tasks; on React a component has no
endpoint for a route slice, so the protocol arm's getSource → patch path wins there as well.
Full method, per-task tables, both targets, the min–max spread and the limits (one model, alias
drift between dates, cache-hit share):
OUMV_AGENT_MATRIX_V7.md
in the backend repo, generated from the run JSON by go/benchmark/render_agent_matrix.py. The
previous measured run is
OUMV_AGENT_MATRIX_V5.md.
--- | :--- | :--- | :---: | :---: | :---: | :---: |
| Frontend (UI) | tokensafe-ui | React 18/19 vs. TokenSafe UI | 21.0x | -95% (1.5k vs 32.5k) | 1 vs 6 turns | Zero reactive stale closures |
| Backend (Python) | tokensafe-python | Vanilla FastAPI vs. TokenSafe UARP | 23.5x | -96% (1.4k vs 33.3k) | 1 vs 6 turns | 0 DB pollution (automatic rollback) |
| Backend (Go) | tokensafe-backend | Vanilla Gin vs. TokenSafe Backend | 24.6x | -96% (1.3k vs 33.9k) | 1 vs 6 turns | 0 DB pollution + in-memory compiler guard |
Core SWE Benchmarks
Reference run across 10 production engineering scenarios (169,761 baseline tokens down to 8,173 tokens, -95.2% net context reduction, -99.4% peak single-scenario reduction, +30.6% turn latency speedup with 100% accuracy retention):
Prompt compaction, graph topology (
SWE-06),dep_mode="signature"slicing (SWE-07), repeat-read pointer dedup (SWE-09), and parametric slot cache hits (SWE-10) are measured live (1,368optimized tokens) while baselines (169,761), turn counts, and output estimates (6,805tokens) are modeled constants. See METRICS.md and BENCHMARK_REPORT.md.
Benchmark Scenario | Task Complexity | Baseline Tokens | TokenSafe Tokens | Reduction | Turn Speedup | Accuracy |
SWE-06: Zero-Token Architecture Discovery | God Node indexing vs. crawl | 49,716 | 312 | -99.4% | 6 → 1 turns (+83%) | 100% Pass |
SWE-09: Repeat-Read Pointer Dedup |
| 17,388 | 208 | -98.8% | 2 → 1 turns (+50%) | 100% Pass |
SWE-03: Monorepo Lockfile Git Diff | Monorepo branch diff | 18,911 | 761 | -96.0% | 2 turns | 100% Pass |
SWE-07: Graph-Guided AST Symbol Slicing |
| 26,023 | 1,194 | -95.4% | 4 → 2 turns (+50%) | 100% Pass |
SWE-10: Parametric Distillation Slot Cache | Slot template hit ( | 2,814 | 133 | -95.3% | 2 → 1 turns (+50%) | 100% Pass |
SWE-08: Monorepo Lockfile Grep Leak |
| 10,111 | 491 | -95.1% | 2 turns | 100% Pass |
SWE-01: Race Condition / Distributed Lock | AST query & Redis redlock | 5,046 | 414 | -91.8% | 4 → 3 turns (+25%) | 100% Pass |
SWE-05: Multi-Turn History Compaction | 8-turn session history fold | 31,010 | 3,130 | -89.9% | 8 turns | 100% Pass |
SWE-02: OAuth JWT Expiration Triage | Controller bug investigation | 3,733 | 403 | -89.2% | 3 → 2 turns (+33%) | 100% Pass |
SWE-04: CI Test Failure Extraction | Full test log & stack trace | 5,009 | 1,127 | -77.5% | 3 turns | 100% Pass |
Why "Up to 99%" (Multiplicative Math & Honest Boundaries)
TokenSafe combines two multiplicative savings layers rather than relying on AST compression alone:
Context Token Reduction (-85% to -99.4%): Graph-guided
dep_mode="signature"keeps only the edited symbol body intact while collapsing imports and 1-hop dependency implementations into signatures (-95.4%inSWE-07), Architecture Discovery maps repos in< 350tokens vs. full crawls (-99.4%inSWE-06), and repeat reads resolve to ~75-token integrity pointers (-98.8%inSWE-09, or-99.56%on raw file re-reads).KV-Cache Prefix Locking (
90.8%hit rate at0.10xcached-read rate): The Append-Only Epoch Governor (ContextGovernor) freezes history prefixes monotonically up to 80% of the model context window whilePromptCacheNormalizerstrips volatile metadata, sorts tool schemas, and injects providercache_controlbreakpoints /prompt_cache_key. In a live 20-turn replay oversrc/*.py(BENCHMARK_REPORT.md):
Multi-Turn 20-Turn Replay Metric | Value | Comparison |
Byte-Identical KV-Cache Prefix Hit Rate |
|
|
20-Turn Context Input Tokens |
|
|
Claude Sonnet 4.5 Input Bill (vs. Uncached) |
| Cached input reads @ |
Claude Sonnet 4.5 Total Bill (vs. Uncached) |
|
|
Claude Sonnet 4.5 Total Bill (vs. Naive Mid-Trim Cache) |
|
|
DeepSeek V3 Total Bill (vs. Uncached) |
| Cached reads |
Honest bounds: When ~85–95% fewer context tokens combine with a 90%+ KV-cache hit rate billed at 0.10x, cached input spend approaches 1–2% of uncached cost (up to ~99% savings) on graph-first, repeat-read, and cache-warm workflows. Total session invoices typically fall 80–97% because newly generated output tokens and first-turn cache writes are never discounted by KV-caching.
How to read these numbers: this benchmark is a simulated harness. Compression ratios and 20-turn KV-prefix byte matches are computed live from real files, while baselines and turn speedups are modeled. Production events in TokenSafe are explicitly labeled
measuredorestimated(see METRICS.md).
Real-Repository Benchmark (measured on live clones)
No modeling: fifteen popular repositories across 10 languages (Python, TypeScript, JavaScript, Go, Rust, Java, Ruby, PHP, C#, Swift, C) cloned at HEAD, scenarios pre-registered before measurement (src/bench_scenarios.json), every token counted on real bytes, and deterministic zero-loss gates that disqualify any scenario they fail. Curated rows (all rows in docs/BENCHMARK_REAL.md):
Repo (language) | Scenario | Baseline tok | TokenSafe tok | Reduction | Gates |
lodash (JS) | Symbol read (AST skeleton) | 515,843 | 855 | -99.8% | PASS |
lodash (JS) | Multi-turn + repeat reads | 1,640,674 | 4,233 | -99.7% | PASS |
lodash (JS) | Architecture discovery | 802,825 | 178 | -99.98% | PASS |
lodash (JS) | Junk-read guard | 87,475 | 1,745 | -98.0% | PASS |
lodash (JS) | KV-cache 10-turn bill | 7,390,347 | 1,567,062 | -78.8% | PASS |
fastapi (Py) | Junk-read guard (uv.lock cap) | 367,129 | 855 | -99.8% | PASS |
flask (Py) | Architecture discovery | 53,237 | 176 | -99.7% | PASS |
sinatra (Ruby) | Architecture discovery | 28,165 | 199 | -99.3% | PASS |
composer (PHP) | Junk-read guard (composer.lock) | 33,103 | 1,645 | -95.0% | PASS |
flask (Py) | Write egress (output axis, $15/M) | 7,106 | 44 | -99.4% | PASS |
flask (Py) | Multi-turn + repeat reads | 45,336 | 5,304 | -88.3% | PASS |
curl (C) | Symbol read (AST skeleton) | 125,168 | 31,174 | -75.1% | PASS |
rich (Py) | Multi-turn + repeat reads | 80,036 | 12,329 | -84.6% | PASS |
requests (Py) | Multi-turn + repeat reads | 59,380 | 9,561 | -83.9% | PASS |
flask (Py) | Symbol read (AST skeleton) | 18,864 | 3,784 | -79.9% | PASS |
rich (Py) | Symbol read (AST skeleton) | 28,675 | 7,710 | -73.1% | PASS |
requests (Py) | Symbol read (AST skeleton) | 9,743 | 2,849 | -70.8% | PASS |
sinatra (Ruby) | KV-cache 10-turn bill | 303,850 | 63,393 | -79.1% | PASS |
retrofit (Java) | KV-cache 10-turn bill | 3,312,375 | 673,361 | -79.7% | PASS |
gin (Go) | KV-cache 10-turn bill | 317,638 | 65,036 | -79.5% | PASS |
zod (TS) | KV-cache 10-turn bill | 1,905,787 | 431,857 | -77.3% | PASS |
serde (Rust) | KV-cache 10-turn bill | 1,307,460 | 300,472 | -77.0% | PASS |
curl (C) | KV-cache 10-turn bill | 1,586,875 | 423,360 | -73.3% | PASS |
newtonsoft (C#) | Symbol read (AST skeleton) | 56,076 | 17,871 | -68.1% | PASS |
alamofire (Swift) | Symbol read (AST skeleton) | 13,909 | 8,100 | -41.8% | PASS |
serde (Rust) | Symbol read (AST skeleton) | 69,610 | 42,671 | -38.7% | PASS |
gin (Go) | Symbol read (AST skeleton) | 23,567 | 14,938 | -36.6% | PASS |
flask (Py) | Secret guard (cat .env -> deny, 0 leak) | 153 | 82 | -46.4% | PASS |
flask (Py) | Tree-sitter AST (13 langs) | 18,864 | 2,410 | -87.2% | PASS |
fastapi (Py) | Reversible Hash Stashing (#hash) | 7,605 | 37 | -99.5% | PASS |
rich (Py) | Context Tax & Ghost Token Audit | 13,425 | 699 | -94.8% | PASS |
rich (Py) | Verbose test output (noise strip) | 746 | 385 | -48.4% | PASS |
composer (PHP) | Prompt compaction (TOCP) | 138 | 46 | -66.7% | FAIL |
flask (Py) | Full-suite pytest output | 6,402 | 6,191 | -3.3% | PASS |
fastapi (Py) | Git diff churn -> slice | 416 | 393 | -5.5% | PASS |
Aggregate: ~25.7M measured tokens saved per traced pass over all 15 repositories in 10 languages (186 gated-OK rows; input at $3/M, output axis at $15/M, KV-cache hits billed at $0.30/M). Clean pytest suites honestly score ~0-3% — savings are never invented. 17 gate-FAILs and 21 skips are published with reasons on the live page (e.g. fastapi's test-output: strict warning filters escalate a pytest-asyncio deprecation into a pytest INTERNALERROR; whole-repo API surfaces bigger than hub crawls for fastapi/httpie; httpie's core.py refuses skeletonization — one function is most of the file). Full table + raw JSON: docs/BENCHMARK_REAL.md · live page: https://tokensafe.dev/bench · methodology post: https://tokensafe.dev/blog/real-repo-benchmark-5-repos. Reproduce:
tokensafe bench --real # all 15 pre-registered repos
tokensafe bench --real --repo=pallets/flask # one repo
tokensafe bench --real --here # your current repositoryHead-to-Head Competitor Benchmark (Measured on Real Repositories)
We cloned 8 popular open-source repositories across Python, Go, C, and Java, and tested JayPokale/Chisle, alexgreensh/token-optimizer, and TokenSafe (v4.1.2) on the exact same hub files and target functions. Every token was counted with a calibrated BPE tokenizer on real bytes.
Deterministic zero-loss gates disqualify any output where the code fails to compile/parse, or where the targeted function is missing. Savings without code correctness are just destructive truncation.
Repository & Target File | Baseline Tokens | JayPokale / Chisle | alexgreensh / token-optimizer | TokenSafe (v4.1.2) | Zero-Loss Gate Result |
flask ( | 18,864 | 18,864 (0.0%) | 317 (-98.3%)❌ GATE FAIL: SyntaxError / Symbol Dropped | 3,784 (-79.9%) | TokenSafe PASSValid AST, target 100% intact |
requests ( | 9,743 | 9,743 (0.0%) | 651 (-93.3%)✅ Heuristic match | 2,849 (-70.8%) | TokenSafe PASSValid AST, target 100% intact |
fastapi ( | 73,721 | 73,721 (0.0%) | 139 (-99.8%)❌ GATE FAIL: SyntaxError / Symbol Dropped | 39,529 (-46.4%) | TokenSafe PASSValid AST, target 100% intact |
rich ( | 28,675 | 28,675 (0.0%) | 585 (-98.0%)❌ GATE FAIL: SyntaxError / Symbol Dropped | 7,710 (-73.1%) | TokenSafe PASSValid AST, target 100% intact |
httpie ( | 2,933 | 2,933 (0.0%) | 266 (-90.9%)✅ Heuristic match | 689 (-76.5%) | TokenSafe PASSValid AST, target 100% intact |
gin ( | 15,032 | 15,032 (0.0%) | 115 (-99.2%)❌ GATE FAIL: Unsupported Lang / Truncated | 9,904 (-34.1%) | TokenSafe PASSNative Tree-sitter Go grammar |
curl ( | 23,246 | 23,246 (0.0%) | 204 (-99.1%)❌ GATE FAIL: Unsupported Lang / Truncated | 5,343 (-77.0%) | TokenSafe PASSNative Tree-sitter C grammar |
retrofit ( | 8,189 | 8,189 (0.0%) | 127 (-98.4%)❌ GATE FAIL: Unsupported Lang / Truncated | 4,617 (-43.6%) | TokenSafe PASSNative Tree-sitter Java grammar |
Key empirical takeaways:
Chisle scores 0.0% reduction on code reads: its lifecycle hook hardcodes
const NEVER_COMPRESS = ['read', 'edit', 'write']to avoid breaking diffs without an AST parser.token-optimizer failed 6 out of 8 zero-loss gates: on Python files, its
structure_map.pyemits invalid pseudo-YAML text outlines and caps methods at 4 (MAX_SKELETON_METHODS_PER_CLASS = 4), discarding up to 56 methods including the target function. On Go, C, and Java, it performs blind regex truncation.TokenSafe achieves 34.1% to 79.9% real token reduction with a 100% Gate PASS rate: using native Tree-sitter AST polyglot grammars, TokenSafe keeps 100% of the target function's executable body intact byte-for-byte, produces valid syntax, and enables 0ms bit-exact restoration via
#hashandexpand_ref.
Architectural Comparison: TokenSafe vs. Competitors
Capability | JayPokale / Chisle | alexgreensh / token-optimizer | TokenSafe (v4.1.3) |
Parsing & AST Engine | None (Markdown rulesets only) | Regex & heuristic bracket lexers | Native Tree-sitter AST (13 languages) with zero-loss fallback |
Context Reversibility | Irreversible (bash pipe cut) | Disk archiving with shell expand command | Reversible Hash Stashing ( |
Integration Surface | System prompt instructions | Claude Code & Codex hooks wrapper | 18-tool MCP Server + universal proxy (Cursor, Claude, Antigravity, Windsurf, Codex, Gemini) |
Pre-Git Security Guard | None | None | Sub-30ms interception: blocks |
KV-Cache Prefix Locking | None | Session cache hints | Monotonic Append-Only Epoch Governor (90.8% hit rate at 0.10x cached rate) |
Environment Context Tax | None | Claude Code audit command |
|
Polyglot Language Scope | Prompt-only | Python, TS/JS heuristics | 13 polyglot languages: Python, TS, JS, Go, Rust, Java, C#, C, C++, PHP, Kotlin, Swift, Ruby |
Team FinOps & Telemetry | None | Local SQLite database | Local SQLite + Cloud Team Dashboard ( |
Why token-optimizer Reports Smaller Token Numbers (and Why It Fails Zero-Loss Gates)
When running benchmarks on large repositories, developers often ask: Why does token-optimizer show 317 tokens on Flask while TokenSafe shows 3,784 tokens?
The answer lies in what each tool actually passes to the model:
Pseudo-YAML vs. Executable Code:
token-optimizerreplaces Python source code with a plain text outline (lines: 1687\nimports (50):\nclasses (1): ...). This is not valid Python syntax; runningast.parse()on it raises an immediateSyntaxError.Arbitrary Method Dropping: In
structure_map.py, token-optimizer enforcesMAX_SKELETON_METHODS_PER_CLASS = 4. Flask'sAppclass defines over 60 methods. token-optimizer took the first 4 methods and discarded the other 56 methods, including the exact target functionfull_dispatch_requestthe agent was supposed to inspect and edit!The Book Analogy: Tearing out 98% of the pages in a novel and handing someone only a 4-line table of contents reduces token count by 98%, but completely destroys the chapter. If an agent cannot see the function body, it cannot fix bugs or generate valid diffs; it is forced to hallucinate code.
TokenSafe's Zero-Loss Guarantee: TokenSafe reduces Flask from 18,864 down to 3,784 tokens (-79.9%) using native Tree-sitter AST parsing. It preserves 100% of the target function's executable body byte-for-byte, keeps 1-hop typed caller contracts, produces 100% valid Python syntax, and allows any folded block to be recovered via
#hashandexpand_ref.Why Chisle Shows 0% on File Reads: JayPokale/Chisle lacks an AST parser. To prevent models from hallucinating edits against missing code, its lifecycle hook hardcodes
const NEVER_COMPRESS = ['read', 'edit', 'write']. As a result, reading code files (the largest source of context consumption) passes 100% uncompressed into context.
Why Alternative Approaches Fall Short
Prompt Engineering Alone (Chisle) Cannot Enforce Contracts: Prompt rulesets like Chisle ("be concise", "caveman prose", "YAGNI code") rely entirely on the LLM's willingness to follow negative instructions. As context grows past 10–15 messages, models suffer Lost in the Middle amnesia, ignore prompt rules, and revert to dumping 2,000 lines of boilerplate. Furthermore, truncating bash command outputs via shell pipes permanently destroys tracebacks and compiler errors, causing agents to enter infinite repair loops.
Heuristic Regex Slicing (token-optimizer) Breaks on Real Codebases: Regex-based AST slicing fails when parsing modern polyglot codebases with nested generics (
<T extends Map<K, V>>), decorators, async generators, and multi-line macros. TokenSafe uses native C Tree-sitter grammars across 13 languages with exact start/end byte offsets, eliminating bracket miscounts while preserving 1-hop caller contracts.The Zero-Loss Invariant (
#hash&expand_ref): Unlike tools that irreversibly discard folded content, TokenSafe hashes every compressed artifact into an 8-character anchor ([TokenSafe folded: #a1b2c3d4 ...]). Any agent can calltokensafe:expand_ref('a1b2c3d4')to retrieve 100% bit-exact original bytes in 0ms without re-running commands.Pre-Git Security vs. Blind Agents: Autonomous coding agents frequently run
git add .containing.envfiles or introduce hardcoded API keys as fallback parameters in environment lookups. TokenSafe is the only tool with an inline security guard that blocks both credential fallbacks and secret file reads locally before anything reaches LLM transcripts or git commits.
Metrics Honesty
TokenSafe labels every savings event as one of:
measured: the model literally received fewer bytes than the tool produced (sliced file reads, filtered command output, AST skeletons).estimated: the model received a compact artifact and saved tokens are counted against a reasonable baseline (architecture graph vs. a full repo crawl; folded history digest injected while raw history stays in context).
Totals always display the split (X metered · Y est.). When a live metric is missing, the UI shows — rather than a placeholder number. USD figures are derived approximations (tokens × $1.5 / 1M), not provider invoices. Full contract: METRICS.md.
Pricing and 7-Day Team Trial
TokenSafe follows an open-core model: verify local context savings and guardrails on your own repo first, then roll out team caching, org policies, and per-seat ROI.
Plan | Price | Monthly Allowance | Included Capabilities |
Developer Sandbox | $0 forever | 500,000 tokens / mo | 9-language local regex compactor, local AST slicer CLI, local secret & |
Engineering Team (Recommended) | $29 / seat / mo (~$24 / seat / mo billed $290/yr) | Unlimited | 7-Day Free Trial, shared team cache (L3 monorepo hits), org-wide guard & git leak shield, Friday per-seat ROI digest, centralized seat provisioning & revoke, managed cloud distillation (zero keys needed) |
Enterprise & VPC | Custom | Unlimited | Org audit log (guard forensics: who / what / when, CSV & SIEM export), central guard policies, self-hosted VPC proxy (private BYOK), zero-telemetry / air-gapped mode, SAML / OIDC SSO, dedicated onboarding & SLA |
Working solo? Individual Solo plans start at $9 / mo ($89 / yr).
7-Day Free Trial · Offline Ed25519 Seat Keys (TS2.*) · Zero Source Code Transmitted · Cancel anytime
Start a 7-Day Team Trial Run Free Locally
FAQ
Does my source code leave my machine?
No. Slicing, guarding, compaction, and metrics run locally. The cloud receives only counters (token totals and event types), never file contents or prompts. Set TOKENSAFE_TELEMETRY_DISABLED=1 to disable all telemetry sync; local features keep working.
How does offline license verification work?
License keys are TS2.* tokens signed with Ed25519. Your client verifies the signature offline against an embedded public key and caches the result for up to an hour. Enforcement never requires a network round trip.
What do measured and estimated mean?
measured means the model literally received fewer bytes than the tool produced. estimated means savings are counted against a reasonable modeled baseline. The dashboard always shows the split and never invents numbers for missing data.
What exactly does the $29/seat plan include? Unlimited compaction and managed cloud distillation (zero API keys for developers), the shared L3 monorepo cache, org-wide guard policies, the Friday per-seat ROI digest, and centralized seat provisioning and revocation. Billed annually it is $290/seat/year (~$24/seat/mo).
Can we self-host? The Enterprise & VPC plan covers a private VPC Docker proxy with BYOK provider keys, zero-telemetry / air-gapped mode, and SAML/OIDC SSO, deployed together with the TokenSafe engineering team: corp@tokensafe.dev.
What happens if a hook fails? All hook adapters fail open: an internal error never stalls your agent. Failures are logged locally so they can be reported and fixed, not silently swallowed.
Reference
Tool | What it does |
| Architectural hotspots, dependency topology, and God Nodes detection before multi-file reading (persisted in SQLite cache) |
| Compact markdown map of all exported interfaces, classes, and types |
| AST-skeletonized file read preserving a target symbol and 1-hop dependencies; |
| 3–8 related symbols across files in one call: merged skeletons, deduplicated shared imports, unified 1-hop signatures |
| Sub-millisecond keyword and symbol search powered by native SQLite FTS5 trigram index with BM25 relevance ranking (<1ms) |
| Reversible stash expansion: recovers original un-truncated content by its 8-char hex hash anchor ( |
| Web reader & HTML-to-Markdown compactor: strips scripts, styles, navbars, and cookie banners (-80% to -95% tokens) |
| Downscales oversized visual assets (>1024px) via Pillow or macOS |
| Prunes obsolete intermediate tool reads that were superseded by subsequent edits or re-reads in long agent transcripts (-30-40% context) |
| Anti-stuck persistent ledger: retrieves past dead-ends, loop guard trips, and git reverts to prevent repeating failed paths |
| Clean directory tree without permissions, timestamps, or lockfiles |
| Unified diff slicing omitting lockfiles and minimizing context lines |
| Per-stage shell command rewrites ( |
| Pre-flight security and hygiene audit for commands or code snippets |
| Context window usage estimate with thresholds and recommendations |
| Compiles a verbose developer prompt into a compact S-expression |
| Folds a long agent transcript into a compact state ledger |
| Cumulative token and cost savings analytics |
| Status, capabilities, and connection health of frontend/backend OUMV runtimes with hybrid fallback mode |
| Progressive runtime observation (L0 pulse, L1 surface, L2 detail) with out-of-the-box static AST fallback. |
| Query runtime causality, state dependencies, and backend route mappings |
| OCC-guarded source edits ( |
| Transactional verification and state invariant assertions |
Observation is free on every plan. The write tools (oumv_mutate, oumv_preview, oumv_verify, oumv_build) need Solo or higher: guest and free run OUMV's read-only profile, where those methods are absent and answer -32601.
Endpoint: https://api.tokensafe.dev/mcp, auth Authorization: Bearer <TS1./TS2. key>.
Tool | Access | What it does |
| Public | Aggregate product statistics |
| Public | Latest published version and update banner |
| Public | Copy-paste MCP snippets per agent |
| Public | Search public documentation |
| Licensed | Active tier, seat, and trial state |
| Licensed | Team savings metrics with |
| Licensed | Managed cloud prompt distillation (zero API keys) |
| Licensed | Shared L3 team cache lookup |
| Licensed | Shared L3 team cache store |
| Licensed | Billing history |
| Licensed | Provision a signed |
| Licensed | Revoke an active seat key |
| Licensed | Preview the Friday team ROI digest |
tokensafe stats / markdown / html Savings analytics (terminal / .md report / dashboard)
tokensafe search <query> [--path <p>] Fast SQLite FTS5 BM25 code search (<1ms)
tokensafe index [dir] [--clear] Index repository into SQLite FTS5 trigram database
tokensafe expand-ref <hash8> Restore folded tool/command/file result by its 8-char hash
tokensafe optimize-image <path> Downscale image >1024px via Pillow or macOS sips
tokensafe prune-superseded <path> Prune obsolete intermediate tool reads from transcript
tokensafe mistakes [list|record|clear] Anti-stuck dead-ends ledger & prompt guard
tokensafe web <url> Fetch web page/docs and print clean compact Markdown
tokensafe wrap <command> Run command with compact output folding & ANSI stripping
tokensafe doctor [--cleanup] Audit MCP tool overhead, ghost tokens & conflicts
tokensafe benchmark Zero-context-loss benchmark suite (simulated harness)
tokensafe bench --real Measured benchmark on real repos (zero-loss gates)
tokensafe graph / map / skeleton Architecture graph / API surface / AST skeleton of a file
tokensafe test "<prompt>" Preview prompt compaction on custom input
tokensafe guard "<command>" Pre-flight safety check for a shell command
tokensafe guard audit [path] Recursive source audit for secrets & vulnerabilities
tokensafe digest [--send] Compile (and optionally dispatch) the weekly team digest
tokensafe integrate [--dry-run] Detect project stack and scaffold OUMV Retrofit config
tokensafe adapters Show catalog of frontend/backend OUMV adapters
tokensafe oumv doctor Audit OUMV runtime connectivity and capabilities
tokensafe mcp list|disable|enable Manage configured MCP servers
tokensafe proxy [port] Local transparent AI proxy (127.0.0.1:8765/v1)
tokensafe proxy on/off/status Daemon + agent wiring with one-command rollback
tokensafe install / setup [--all] Configure detected agent environments
tokensafe update / check-update Self-update / check for a newer version
tokensafe activate <KEY> Activate a Team or Solo license key
tokensafe login / logout Authorize or unlink this device via browser
tokensafe license Show active tier and trial state
tokensafe providers List distillation providers and active mode
tokensafe sync Sync local telemetry with the cloud dashboard
tokensafe prune [--days N] Compact metrics database (roll old events)
tokensafe vacuum Reclaim SQLite disk space
tokensafe tests [pytest] Run the unit test suite (compact failure report)
tokensafe reset Reset all local token metrics
tokensafe --version Print version and exitProxy mode & agent coverage (v3.0.0)
One command wires everything it safely can:
tokensafe proxy on # installs a keep-alive daemon (launchd/systemd), wires Claude Code, prints manual steps for the rest
tokensafe proxy status # health, wiring state, last traffic
tokensafe proxy off # rollback: unwires agents (previous base URL restored) and removes the daemonThe daemon keeps the proxy alive on 127.0.0.1:8765, on rewires agents only after a verified /health answer (a dead proxy never bricks an agent), and every wiring is backed up for off. tokensafe install and tokensafe update ask interactively whether to enable the proxy (skipped in non-TTY/scripted runs); prefer manual? Run tokensafe proxy in a terminal and point your agent's base URL at http://127.0.0.1:8765 yourself:
Agent | Route through proxy? | How |
Claude Code | ✅ auto ( |
|
Cline / Roo Code | ✅ manual | API Provider → OpenAI-compatible → Base URL |
Aider | ✅ manual |
|
Cursor (custom models) | ✅ manual | Add an OpenAI-compatible model with override base URL |
Cursor (built-in models) | ❌ | Routed via Cursor's own backend — hooks only |
Antigravity / ZCode | ❌ | Hooks only (lifecycle adapters) |
Codex CLI | ❌ | stdio MCP + AGENTS.md (no proxy transport) |
What runs where:
Proxy-only (A/B/D): Tool Result Ledger (folds aged tool results in-flight,
TOKENSAFE_TOOL_LEDGER=0to disable), session-stable cold-tool pruning (opt-in:TOKENSAFE_TOOL_PRUNING=1,TOKENSAFE_TOOL_PRUNE_KEEP,TOKENSAFE_TOOL_PRUNE_ALLOWLIST), managed-cloud history distillation (paid, opt-in:TOKENSAFE_HISTORY_DISTILL=1).Hooks (all agents): PostToolUse stdout compaction, PreToolUse shell/secret guards, Output Guard steering full-file writes to surgical edits, prompt compaction, history folding.
Folded originals are archived under
~/.tokensafe/data/tool_ledger/and every fold carries a deterministic re-hydration anchor — nothing is destroyed, and already-folded results are never re-processed (KV-cache stable).
OUMV Retrofit: Universal Agent Runtime & Progressive Adoption
TokenSafe integrates with the OUMV Protocol (Observe, Understand, Mutate, Verify), providing AI coding agents with a structured, machine-readable interface to existing web and backend applications without requiring framework migrations.
Out-of-the-Box Stack Detection: TokenSafe automatically detects your application stack (
package.json,go.mod,pyproject.toml, Vite, Next.js, FastAPI, Gin) and configures agent tooling dynamically.Level 1 Static AST Fallback: When live dev-servers are offline,
oumv_observeandoumv_understandgracefully fall back to zero-config static AST component trees and route maps with evidence tracking.Consolidated Adapters:
Frontend:
tokensafe-ui/react,tokensafe-ui/vue, and the zero-footprint Vite bridge (tokensafe-ui/vite) that also serves Solid (--framework solid) and Angular (--framework angular, Vite/Analog dev server), with a session token stored in the per-workspace descriptor (~/.tokensafe/runtimes/<hash>.json, mode 0600).Backend: Go (
gin,chi,stdhttp), Node (express,fastify,next,elysia), Python (fastapi,starlette,flask,django), ASP.NET Core and the JDK/PHP sidecars intokensafe-backend— eighteen manifests in the OUMV adapter matrix, every claim backed by a committed certificate.
Guarded Mutations, Enabled by Default:
oumv_mutateworks out of the box on Solo and above and guards every write — mandatory OCCexpectedVersion, workspace path jail, syntax pre-flight, backup of previous bytes. Opt out withpermissions.mutate: falsein.tokensafe/oumv.json.Automatic Wiring CLI:
tokensafe injectactivates every detected app (Vite wrapper, Python autoload, marker-delimited Go/.NET lines),tokensafe inject --revertundoes every patch and restores pre-existing files, andtokensafe oumv doctorreports readiness with blocking reasons.Greenfield Recipes:
tokensafe create <name> --template react-fastapi|react-go|vue-gin|fastapi|gingenerates a normal project in your stack with OUMV already wired.
More documentation: docs/OUMV.md · docs/AGENT_SETUP.md · docs/ARCHITECTURE.md · docs/API.md · METRICS.md
Development and License
The client runs on CPython 3.10+ with cryptography>=42.0 as its only required runtime dependency for Ed25519 license checks and fail-closed RS256 session verification. tree-sitter grammars and Pillow are optional accelerators with stdlib fallbacks, so the engine still slices, guards, and records metrics when they are absent. If no Python 3.10+ exists, the npm launcher downloads a pinned, SHA-256-verified CPython into ~/.tokensafe/runtime; all AST slicing, SQLite metrics, MCP tooling, and guardrails run on the standard library (details).
# Run the unit test suite (compact failure report; full: --traceback / -v)
tokensafe testsContributing: CONTRIBUTING.md
Security policy and vulnerability reporting: SECURITY.md
Metrics and honesty contract: METRICS.md
Trademark policy and certification mark rules: TRADEMARK.md
Apache-2.0 for versions 4.7.0 and newer. Versions up to and including 4.6.4 were released under MIT and remain MIT forever — that grant cannot be withdrawn, and those tags stay forkable.
Commercial licenses are available for self-hosted B2B and enterprise VPC deployments, support and indemnity. Questions: corp@tokensafe.dev · tokensafe.dev
"TokenSafe" and "OUMV Certified" are trademarks of Oleg Savelev. Apache-2.0 section 6 excludes trademark rights: the code is open, the names are not.
Available Tools
7 toolsapply_editsAInspect
Multi-hunk editor (up to 50 files) with optional inline verify: the edit and its verdict come back in one call. Shape: edits=[{path, hunks:[{target, replacement}]}]; a top-level path fills edits that omit one (single-file shorthand). target/replacement take a string or an array of lines; in a single string escape every newline as \n and every double quote as " so the arguments stay valid JSON.
Inputs: edits (required), cwd, path, root, +3 more.
oumvAInspect
Call this FIRST on an OUMV-supported stack: status/brief/observe before grep or full-file reads. OUMV runtime: 'status'|'observe' L0-L4 (a file target at L1+ returns the same skeleton a read would and seeds the read cache: a later smart_read_file returns a pointer)|'brief' (skeleton + call sites + props + module state in one call)|'understand'|'verify'|'mutate' (OCC edit)|'graph'|'index' (repo-wide symbol search: query, kinds?, limit?)|'preview' (dry-run diff, no write)|'build' (run the runtime's build/test command, §14.3)|'cancel' (cooperative, by requestId). Offline the static graph answers observe/understand/index and a labelled verify subset (exists/syntax/OCC/symbol/route presence). Observation is free on every plan; the write actions (verify, mutate, preview, build) need Solo or higher and are refused with a read-only notice on guest/free.
Inputs: path, batch, kinds, level, +12 more.
repo_mapCRead-onlyInspect
Structure without crawling: view='graph' (God Nodes), 'api' (exports) or 'tree' (directories).
Inputs: path, root, view, depth, +1 more.
run_helperDInspect
Utilities: 'sanitize','guard','diff','deps','web','expand','image','compress','dict','bundle-probe' (live entry + hashed chunks + expect/reject table).
Inputs: url, code, diff, hash, +12 more.
scoped_searchBRead-onlyInspect
Search replacing grep/find: query+scope, or queries=[{query|pattern,type,path,glob}] batch (max 20).
Inputs: cwd, mode, path, root, +5 more.
session_contextCInspect
Context hygiene: 'budget' (score S-F), 'compact' (fold transcript), 'prune' (drop superseded reads), 'mistakes', 'metrics', 'remember' (store a decision/note/preference), 'recall' (read project memory), 'forget' (remove one entry by id), 'recall_transcript' (BM25 search over prior session transcripts).
Inputs: id, kind, text, files, +9 more.
smart_read_fileARead-onlyInspect
AST-skeleton reader. endpoint="POST /api/x" resolves route→handler body + path + lines + version in one call; path+symbol for one file; targets=[{path,symbol}] for 2-8 at once; package_name+symbol for .d.ts.
Inputs: path, root, symbol, targets, +8 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
The oumv mega-tool directly overlaps with four other tools: its 'graph' duplicates repo_map, 'index' duplicates scoped_search, 'observe'/'brief' duplicate smart_read_file, and 'mutate'/'preview' duplicate apply_edits. run_helper's 'diff' also overlaps oumv 'preview', so an agent cannot reliably tell which tool to call for a given action.
Most names are lowercase snake_case, but conventions are mixed: verb_noun (scoped_search, smart_read_file, apply_edits, run_helper) versus noun phrases (repo_map, session_context) and an opaque acronym (oumv). It is readable but not a predictable verb_noun pattern throughout.
Seven top-level tools is a reasonable count for a code-context server and each has a plausible role. However, oumv (12 actions), session_context (9 actions) and run_helper (11 actions) are mega-routers that hide dozens of operations behind single tools, making the effective surface heavier than the count suggests.
The surface covers the core code-agent lifecycle: search (scoped_search), read/skeleton (smart_read_file), structure (repo_map), edit with verify (apply_edits), runtime inspect/verify/build (oumv), and session memory (session_context). Minor gaps exist around creating/deleting files and explicit VCS operations, but agents can largely work around them.
Maintenance
Related MCP Connectors
AST context pruner, token budget planner, fuzzy patcher, and code solvers.
Cuts coding agent token burn up to 72% continuously via contradiction-free memory & verification.
Codebase intelligence for agents: 152 structured artifacts across 21 programs, one call.
Compress coding-agent context ~64%. Hosted Neural Keep MCP for Cursor/Claude/Codex.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceReduces token consumption for AI coding agents by 50-70% through intelligent code context filtering, Git delta tracking, and local SQLite/Tree-sitter indexing.167 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables AI coding agents to efficiently analyze codebases by extracting AST skeletons, reducing token usage while preserving type contracts and interfaces.2 npm1MIT
- AlicenseAqualityCmaintenanceEnables AI coding agents to reduce token usage by condensing source code into AST skeletons, extracting specific symbols, compressing logs, and estimating token budgets.4MIT
- AlicenseAqualityBmaintenanceEnables coding agents to reduce prompt token usage by extracting code skeletons and symbols, compressing test and command output, generating compact diffs, and tracking session token health to avoid rate-limit lockouts.61MIT