SuperAPI AI Directory

token-savior

Structural code intelligence: navigate and edit code by symbol, with dependency graphs, call chains, dead code detection and structural diffs.

Open website

About this tool

Token Savior is an MCP server positioned as a "structured code intelligence" layer for AI coding agents, primarily solving two problems: agents such as Claude Code reading entire files just to answer questions about a few lines of code, and forgetting all context after a session ends. On top of this, it adds a third dimension: constraining Bash output that can inflate the turn budget by rewriting commands before execution.

Main capabilities

  1. Structured code navigation: indexes the codebase by symbol (functions, classes, imports, call graph), enabling the model to navigate by pointers rather than reading with cat. It is officially claimed that across more than 170 real sessions, a 97% reduction in injected characters was measured.
  2. Persistent memory engine: every decision, bugfix, convention, guardrail, and session summary is stored in SQLite WAL + FTS5 with vector embeddings, ranked by Bayesian effectiveness and ROI, and reinjected as a compact delta at the start of the next session.
  3. Bash compression and rewriting: since v4.1 it provides Bash compressors (34) and a PreToolUse rewriter. Compressors are pure functions, with no I/O and no globals, returning token-efficient renderings; the dispatcher returns None when no matcher hits, preserving the original sandbox path. Compound commands (such as cd ... && cmd) fall through to the last meaningful segment.
  4. Audit tools: including detect_breaking_changes, find_dead_code, analyze_config, and others.
  5. ts_discover: a new MCP tool that scans Claude Code session records to find patterns where TS tools could have been used but were not, such as Read->Grep->Read chains, sequential find_symbol, edits that did not use get_edit_context, memory_search without first memory_index, using native shell on code files, and so on. Parameters are trimmed to key keys (PII-safe), streamed out as JSONL with fast skipping by mtime.

How to use Just add the server to your MCP configuration (such as Claude Code). It is officially emphasized that in Claude Code 2.1.28x and later versions, "alwaysLoad": true is important: without it, every tool of the server is located in ToolSearAfter ch, the model switches to using the loaded Read and Grep. Officially, it is stated that before the option existed, only 1 out of 143 sessions measured called the Token Savior tool; after enabling, the manifest consumes a few thousand cached tokens per session.

The environment variable TOKEN_SAVIER_PROFILE=optimized provides the Pareto-optimal configuration that won tsbench, bundling: tiny_plus (a manifest of 15 hot tools), thin inputSchema (44% smaller manifest), disabled capture sandbox, and memory hooks gated for cross-project safety.

Bash compression and rewriting are optionally enabled and require two environment variables and one CLI call. ts init is idempotent: it detects existing hook entries, deduplicates by (matcher, command), prints a unified diff, and backs up settings.json as .bak-YYYYMMDD-HHMMSS (UTC) before writing. Supported agents: claude, cursor, gemini, codex, openclaw. Use --dry-run to preview, or --global to write user-level configuration.

Installation methods include pip (MCP server), uvx (no venv, no clone), and a one-line command for Claude Code.

Important distinction: the PreToolUse rewriter modifies the command before it runs, so it produces smaller output, and the output entering the model is also smaller, which is a real reduction for the current turn; the PostToolUse compressor runs after the tool returns and can only add context, the original output has already been sent, and the compact rendering is appended rather than replaced. What the compressor really provides is persistence: the full output is saved in the capture sandbox, can survive across context compression, and can later be queried without rerunning. If the goal is to shrink the current turn, use TS_BASH_REWRITE=1; if the goal is to avoid command output being lost during compression, use TS_BASH_COMPACT=1.

Applicable scenarios Suitable for AI coding agents that use MCP clients (such as Claude Code), as well as agents without MCP (Cursor, Aider, Continue, scripts, CI), the latter of which can use some tools in a shell-like way via the ts command. Officially, it is stated that in Claude On Code, prefer using the MCP server; measured on Opus 4.7 it is cheaper than the CLI; use the CLI for portability scenarios.

Limitations and caveats The official documentation explicitly states: the headline benchmark data (97.9%, -80% tokens, -83% wall-clock time) is self-reported by the project and has not been independently verified, and the test framework repository that produced these numbers is currently not public. A retest published on 2026-08-09 was retracted on 2026-08-10 because that retest did not actually measure this server: of 143 benchmark sessions, only 1 called the Token Savior tool; the client had MCP deferred tool loading enabled, all 18 tools were behind a ToolSearch query, the model never saw them, and instead used Grep and Read (66 greps, 30 reads, 1 MCP call). The official statement says this assertion has now been added to the test framework.

The 2026-10-07 retest (where the tools were actually called) used a frozen copy of the same repository (commit 9d15a1e, no CLAUDE.md), Claude Haiku 4.5, plain Claude Code versus the auto configuration with alwaysLoad; all 48 sessions across 8 tasks succeeded; v4.22.0 measured a 14% saving, and 5 of the 8 sessions used the tools. In the 2026-10-08 edit test on the same repository (3 tasks, files 1900 to 3700 lines, scored by running the code and module tests, 4 passes), both groups succeeded in every session, and the cost noise was too large to call it a gain (from -54% to +16% per pass). Native Edit only needs a partial Read, so there is little room to cut there. Wall-clock time is worse because each benchmark session starts a new server and indexes the repository first; long-lived sessions pay for this only once. The changes from v4.22.0 to v4.23.0 are mainly wording: search_codebase now points out the function each hit is in, and the tool descriptions explicitly state which native call they replace.

Test suite size: main branch 1898 passed, 2 skipped; CI is green on Python 3.11 / 3.12 / 3.13.

Other notes The project also mentions the starscope tool (for seeing who starred or forked your repository and ranking them by influenceorder), and release notes are in CHANGELOG.md, Releases, and PyPI. All environment variables are optional; those marked =1 accept only the exact value 1, and those marked bool accept 1 / true / yes (some accept on). Naming pitfall: TS_PROFILE in the benchmark snippets is a tsbench variable, while the server reads TOKEN_SAVIOR_PROFILE. CLAUDECODE, CLAUDE_CODE_ENTRYPOINT, CLAUDE_PROJECT_DIR, CLAUDE_CONTEXT_REMAINING_PCT, CODEX_* and HERMES_* are set by the host/client for detection and startup project hints, and are not user-adjustable.