Skip to content
tokensafe 4.5.1

tokensafe 4.5.1

Pypi •[email protected] • November 25, 2026

Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.

pip install tokensafe==4.5.1

Your AI agent is smart enough to code all day. Now it actually can. Stop letting bloated file reads, noisy test dumps, and broken prompt caches drain your limits by lunch. TokenSafe runs locally, filtering context down to what the model actually touches while keeping secrets out of git. Works with Cursor, Claude Code, Codex, Windsurf, Google Antigravity, Kimi Code, and ChatGPT .

Install • Quickstart • What's New in v4.0 • Why TokenSafe • Benchmarks • Pricing • FAQ • Reference • Website & Docs

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 & ( scoped_search , tokensafe ) : Native SQLite full-text with trigram tokenization and BM25 relevance ranking ( 1024px) via Pillow or macOS sips , 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.

Connect TokenSafe to the AI coding agents on your workstation in one command:

The 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.

Claude Desktop / Cursor MCP config:

Cloud features (team metrics, managed distillation, shared team cache, billing) run on the remote endpoint with Authorization: Bearer . 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 .

The full command reference (24 commands) is in Reference .

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 .cursorrules wear off mid-session. Agents hardcode fallback credentials, disable TLS checks, or stage .env files with git 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.

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.

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.

When an operation is blocked, the agent sees an explicit, constructive message:

10 Core Engine Capabilities

Why TokenSafe agents ship working code on the first pass without burning quotas or leaking keys:

Deeper mechanics (language matrix, AST syntax trees, cache tiers, governor) live in docs/ARCHITECTURE.md .

Agent Usability Benchmarks (AUB) — Full-Stack Agent Velocity

Beyond file slicing, TokenSafe's agent-native ecosystem eliminates architectural friction, state pollution, and compiler loops for autonomous coding agents across frontend and backend:

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,368 optimized tokens) while baselines ( 169,761 ), turn counts, and output estimates ( 6,805 tokens) are modeled constants. See METRICS.md and BENCHMARK_REPORT.md .

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,368 optimized tokens) while baselines ( 169,761 ), turn counts, and output estimates ( 6,805 tokens) are modeled constants. See METRICS.md and BENCHMARK_REPORT.md .

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% in SWE-07 ), Architecture Discovery maps repos in > ), 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 call tokensafe: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 .env files 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.

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.

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

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.

Endpoint: , auth Authorization: Bearer .

Proxy mode & agent coverage (v3.0.0)

One command wires everything it safely can:

The 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 yourself:

Proxy-only (A/B/D) : Tool Result Ledger (folds aged tool results in-flight, TOKENSAFE_TOOL_LEDGER=0 to 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, .js, FastAPI, Gin) and configures agent tooling dynamically.

Level 1 Static AST Fallback : When live dev-servers are offline, oumv_observe and oumv_understand gracefully fall back to zero-config static AST component trees and route maps with evidence tracking.

Consolidated Adapters : Frontend : @tokensafe-ui/oumv/react , @tokensafe-ui/oumv/vue , and @tokensafe-ui/vite with secure .tokensafe/runtime.json session authentication. Backend : Go ( gin , chi , stdhttp ) and Python ( fastapi , sqlalchemy ) in tokensafe-backend .

Frontend : @tokensafe-ui/oumv/react , @tokensafe-ui/oumv/vue , and @tokensafe-ui/vite with secure .tokensafe/runtime.json session authentication.

Backend : Go ( gin , chi , stdhttp ) and Python ( fastapi , sqlalchemy ) in tokensafe-backend .

Safe-by-Default Mutations : Mutation tools ( oumv_mutate ) require explicit permission in .tokensafe/oumv.json ( mutate: false by default) and enforce optimistic concurrency control to prevent agent code drifts.

Doctor & Integration CLI : Run tokensafe integrate to scaffold project configs or tokensafe oumv doctor to verify dev-server connectivity and capabilities.

More documentation: docs/AGENT_SETUP.md · docs/ARCHITECTURE.md · docs/API.md · METRICS.md · BENCHMARK_REPORT.md

Development and License

The client runs on Python 3.10+ with cryptography>=42.0 as its sole runtime dependency for Ed25519 license checks; all AST slicing, SQLite metrics, MCP tooling, and guardrails run on the standard library ( details ).

Contributing: CONTRIBUTING.md

Security policy and vulnerability reporting: SECURITY.md

Metrics and honesty contract: METRICS.md

MIT License. Commercial licenses are available for self-hosted B2B and enterprise VPC deployments. Questions: corp@tokensafe.dev · tokensafe.dev

Release files for tokensafe 4.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation .

Source distribution (sdist)

Built distribution (wheel)

Total release size: 1.1 MB

Release files / tokensafe-4.5.1.tar.gz

Release files / tokensafe-4.5.1-py3-none-any.whl

Security for tokensafe 4.5.1

Provenance describes where a file came from. On PyPI, provenance is shared via attestations , which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

Nov 25, 2026 2 release files No provenance

Nov 25, 2026 2 release files No provenance

Nov 25, 2026 2 release files No provenance

Nov 24, 2026 2 release files No provenance

Nov 24, 2026 2 release files No provenance

Nov 24, 2026 2 release files No provenance

Nov 23, 2026 2 release files No provenance

Nov 23, 2026 2 release files No provenance

Nov 23, 2026 2 release files No provenance

Nov 23, 2026 2 release files No provenance

Nov 22, 2026 2 release files No provenance

Nov 22, 2026 2 release files No provenance

Nov 22, 2026 2 release files No provenance

Nov 21, 2026 2 release files No provenance

Nov 21, 2026 2 release files No provenance

Nov 20, 2026 2 release files No provenance

Nov 20, 2026 2 release files No provenance

Nov 19, 2026 2 release files No provenance

Nov 19, 2026 2 release files No provenance

Nov 19, 2026 2 release files No provenance

Nov 18, 2026 2 release files No provenance

Nov 18, 2026 2 release files No provenance

Nov 18, 2026 2 release files No provenance

Nov 18, 2026 2 release files No provenance

Nov 18, 2026 2 release files No provenance

Nov 18, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 17, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 16, 2026 2 release files No provenance

Nov 15, 2026 2 release files No provenance

Nov 15, 2026 2 release files No provenance

Nov 15, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 14, 2026 2 release files No provenance

Nov 13, 2026 2 release files No provenance

Nov 13, 2026 2 release files No provenance

Nov 13, 2026 2 release files No provenance

Nov 13, 2026 2 release files No provenance

Nov 13, 2026 2 release files No provenance

Nov 13, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 12, 2026 2 release files No provenance

Nov 11, 2026 2 release files No provenance

Nov 11, 2026 2 release files No provenance

Nov 11, 2026 2 release files No provenance

Nov 11, 2026 2 release files No provenance

Nov 11, 2026 2 release files No provenance

Nov 11, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Yanked reason: Bump-only accidental release; never existed in git/npm history (1.8.0 → 2.0.0).

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 10, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 9, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Nov 8, 2026 2 release files No provenance

Extracted Entities