token-savior
Token Savior is an MCP server providing structural code navigation, persistent memory, and token-efficient tooling for AI coding agents.
Project & Workspace Management
List, switch, and add workspace projects; trigger reindexing; get high-level project summaries.
Code Navigation & Symbol Lookup
Find symbol definitions, retrieve full source, list all functions/classes/imports, search via regex, get file/project structure summaries.
Dependency & Impact Analysis
Find dependencies and dependents; analyze full transitive change impact; trace call chains; detect cross-project dependencies.
All-in-One Context
Get edit context (source + dependencies + callers) in a single call; find all files related to a feature keyword.
Git & Diff Tools
Structured git status; symbol-oriented summaries of worktree changes or changes since a ref; detect breaking API changes; build compact commit/review summaries.
Safe Editing & Checkpoints
Replace symbol source or insert content before/after a symbol without file-wide patches. Create, list, restore, compare, and prune checkpoints for safe mutations.
Testing & Validation
Find impacted test files; run only impacted tests; replace a symbol and auto-validate with optional rollback on failure.
Code Quality & Framework Analysis
Find dead code; rank complexity hotspots; detect Next.js routes/API endpoints and React components; analyze config files for secrets/duplicates; inspect Dockerfiles; cross-reference environment variable usage.
Persistent Memory Engine
Store and retrieve observations, decisions, and conventions across sessions with hybrid search (BM25 + vector), progressive disclosure, Bayesian validity, contradiction detection, decay/TTL, ROI tracking, and MDL distillation.
Efficiency & Customization
Session token-saving stats; customizable tool profiles (full, code_mode, auto) to minimize manifest size; defer-loading via
ts_search.
Synchronizes the codebase index by monitoring git status and diffs, and provides symbol-level impact analysis since specific git references.
Indexes documentation files via heading detection to allow section-based navigation and querying.
Identifies and executes specific tests impacted by symbol changes, providing compact summaries instead of raw logs.
Provides structural indexing and surgical source code retrieval for Python projects, including functions, classes, and dependency mapping.
Indexes Rust projects to extract and query symbols such as functions, structs, traits, and impl blocks.
Enables structural analysis and symbol extraction for TypeScript and JavaScript, covering functions, interfaces, and type aliases.
Click on "Install 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., "@token-saviorWhat is the impact of changing the LLMClient class?"
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.
Token Savior
One MCP server. One profile. 97.9% on tsbench at -80% tokens. Structural code navigation, persistent memory, and Bash output compaction for AI coding agents.
mibayy.github.io/token-savior -- project site + benchmark landing github.com/Mibayy/tsbench -- benchmark source + fixtures
Benchmark -- 96 real coding tasks (Claude Opus 4.7, May 2026)
Plain Claude Code | With Token Savior | |
Score | 141 / 180 (78.3%) | 188 / 192 (97.9%) |
Active tokens / task | 17 221 | 3 395 (-80%) |
Wall time / task | 110.6 s | 18.9 s (-83%) |
Reproduces with the optimized profile (single env var). See BENCHMARK-SUMMARY.
Who starred this repo?
On June 30, 2026 GitHub restricted stargazer and watcher lists to repo admins and collaborators, which broke every "who starred my repo" tool at once. I rebuilt one that still works, precisely because it only reads repos you own or can push to: starscope ranks the people who starred or forked your repo by influence, and surfaces their social accounts when their GitHub profile declares them.
Numbers on this very repo, computed with it: 1,147 people, 27% with a public social account, and the most followed carries 18,922 followers. The named list is visible to the repo owner and to nobody else — the public page shows aggregates only.
Related MCP server: astllm-mcp
What's new
Release notes live where they can't drift out of sync with the code:
CHANGELOG.md for the full history
Releases for the tagged builds
PyPI for what
pipwill actually give you
Quick start
pip install "token-savior-recall[mcp]"Add to your MCP config (e.g. Claude Code):
{
"mcpServers": {
"token-savior-recall": {
"command": "/path/to/venv/bin/token-savior",
"env": {
"WORKSPACE_ROOTS": "/path/to/project1,/path/to/project2",
"TOKEN_SAVIOR_CLIENT": "claude-code",
"TOKEN_SAVIOR_PROFILE": "optimized"
}
}
}
}That's it. TOKEN_SAVIOR_PROFILE=optimized ships the Pareto-optimum
config that wins tsbench. It bundles:
tiny_plus(15 hot tools manifest)thin inputSchema (-44% manifest)
capture sandbox disabled
memory hooks gated for cross-project safety
No other tuning needed.
Activation (Bash compaction + rewriting)
Bash compaction and the PreToolUse rewriter are opt-in. Two env vars and one CLI call:
export TS_BASH_COMPACT=1 # PostToolUse output compactors (34 of them)
export TS_BASH_REWRITE=1 # PreToolUse command rewriter (10 rules)
ts init --agent claude --yes # auto-merge hooks into ~/.claude/settings.jsonts init is idempotent. It detects existing hook entries, dedups by
(matcher, command), prints a unified diff, and backs up settings.json
to .bak-YYYYMMDD-HHMMSS (UTC) before writing. Supported agents:
claude, cursor, gemini, codex, openclaw. Pass --dry-run to preview, or
--global to write the user-level config.
Optional audit log of every rewrite:
export TS_BASH_REWRITE_LOG=$HOME/.local/state/token-savior/rewrites.jsonlCompactor catalog (34)
Family | Compactors |
git |
|
gh |
|
test/lint |
|
cloud |
|
docker |
|
packaging |
|
shell catch-alls |
|
Each compactor is a pure function (no I/O, no globals) returning a
token-efficient rendering. The dispatcher returns None when no matcher
fires, leaving the existing sandbox path untouched. Compound commands
(cd ... && cmd) fall through to the last meaningful segment.
ts_discover -- find missed TS opportunities
New MCP tool that scans your Claude Code transcripts for patterns where TS tools would have been cheaper than what the agent actually did.
ts_discover() # active project, last 30 days
ts_discover(project=None) # ALL transcript projects
ts_discover(format="adoption") # TS vs native ratio per session
ts_discover(format="adoption_json") # same, JSONFindings: Read->Grep->Read chains, sequential find_symbol, edits
without get_edit_context, memory_search without memory_index,
native shell on code files. Args are pruned to load-bearing keys
(PII-safe). Streams JSONL with mtime fast-skip.
ts init CLI
ts init --agent claude [--global] [--dry-run] [--yes]
ts init --agent cursor
ts init --agent gemini
ts init --agent codex
ts init --agent openclawDetects the target agent's settings location, deep-merges the Token
Savior hook config (PostToolUse + PreToolUse), preserves existing
hooks, dedups, prints a unified diff. Backs up to
settings.json.bak-YYYYMMDD-HHMMSS (UTC). Re-running is a no-op.
What it does
Claude Code reads whole files to answer questions about three lines, and forgets everything the moment a session ends. Token Savior fixes both, plus a third axis: it now compacts the noisy Bash output that bloats turn budgets between code reads.
It indexes your codebase by symbol -- functions, classes, imports, call
graph -- so the model navigates by pointer instead of by cat. Measured
reduction: 97% fewer chars injected across 170+ real sessions.
On top of that sits a persistent memory engine. Every decision, bugfix, convention, guardrail and session rollup is stored in SQLite WAL + FTS5
vector embeddings, ranked by Bayesian validity and ROI, and re-injected as a compact delta at the start of the next session.
And on top of that, since v4.1, sit the Bash compactors and the PreToolUse rewriter. Bench numbers above.
Profile comparison
Profile | Tools exposed | Manifest tokens | When to use |
| 15 | ~1.5 KT | Recommended default -- Pareto win on tsbench |
| adaptive | ~1-2 KT | Per-client telemetry-based (experimental) |
| 6 | ~0.6 KT | Minimal hot loop |
| 51 | ~4 KT | Legacy -- broader surface |
| 1 | ~0.3 KT | Bash compaction only -- you already run symbol nav elsewhere |
| 68 | ~6 KT | Everything exposed |
You probably want optimized.
How it composes with adjacent tools
Token Savior spans several layers, and most neighbouring tools occupy exactly one of them. Overlap is opt-out per layer, so running both is usually fine once you disable the half you already have. Thanks to @chirag127 for mapping this out in #45.
Tool | Layer | Overlap | What to do |
PostToolUse Bash output compression | Direct, with the 34 compactors | Pick one. | |
Symbol-graph navigation | Direct, with | Run TS as | |
codebase-memory | Persistent code graph | With the memory engine |
|
Ponytail, Caveman | Output-side compression (code and prose) | Partial, output side only | Complementary, no knob needed |
The layers Token Savior owns that these do not: the PreToolUse Bash rewriter
(it shrinks the command before it runs, not the output after), structural
editing that keeps the index in sync, and the audit tools
(detect_breaking_changes, find_dead_code, analyze_config).
If you only want the Bash layer, TOKEN_SAVIOR_PROFILE=compact-only advertises
a single tool and leaves the compactors and rewriter running.
Token savings
Operation | Plain Claude | Token Savior | Reduction |
| 41M chars (full read) | 67 chars | -99.9% |
| grep + cat chain | 4.5K chars | direct |
| impossible | 16K chars | new capability |
96-task tsbench (Opus, plain vs ts) | 17 221 active/task | 3 395 active/task | -80% |
7-day Bash output bench (v4.3) | ~30 K tokens/week | ~9.6 K tokens/week | ~20.4 K/week |
Install
pip (MCP server)
pip install "token-savior-recall[mcp]"
# Optional hybrid vector search:
pip install "token-savior-recall[mcp,memory-vector]"uvx (no venv, no clone)
uvx token-savior-recallClaude Code one-liner
claude mcp add token-savior -- /path/to/venv/bin/token-saviorDevelopment
git clone https://github.com/Mibayy/token-savior
cd token-savior
python3 -m venv .venv
.venv/bin/pip install -e ".[mcp,dev]"
pytest tests/ -qSuite size: 1898 passed, 2 skipped on main. CI green on Python 3.11 / 3.12 / 3.13.
Bench it yourself
The compactor numbers above come from replaying real Claude Code
transcripts through the dispatcher. Two scripts live under scripts/:
python3 scripts/bench_compactors_real.py # match rate + mean savings
python3 scripts/bench_compactors_unmatched.py # top unmatched commandsThe first walks ~/.claude/projects/*/*.jsonl, replays every Bash
output through the registry, and reports per-family savings + overall
match rate. The second buckets the unmatched commands so the next
compactor target is obvious from the histogram.
To reproduce the tsbench score:
git clone https://github.com/Mibayy/tsbench && cd tsbench
python3 generate.py --seed 42
git tag v1
python3 breaking_changes.py
git tag v2
TS_PROFILE=tiny_plus TS_CAPTURE_DISABLED=1 python3 bench.py --tasks all --run BBonus: ts CLI for non-MCP agents
For agents without MCP (Cursor, Aider, Continue, scripts, CI), the ts
command exposes a subset of the tools via shell:
ts use /path/to/project
ts get my_function # JSON output
ts search 'pattern'
ts daemon start # ~145ms per call vs 1.5s cold fork
ts init --agent cursor # wire up Bash hooks for non-Claude agentsOn Claude Code, prefer the MCP server -- measured cheaper than CLI on Opus 4.7. The CLI is there for the portability case.
Environment variables
All optional. Values shown as =1 also accept nothing else — set exactly 1;
values shown as bool accept 1/true/yes (and on where noted).
Server & tool manifest
Var | Default | Purpose |
| current dir | Comma-separated project roots to index. Codex trap: Codex whitelist-filters the MCP server environment, so an exported shell variable never arrives — set it in |
| — | Single-root alternative to |
| — | Deliberate active-project override (Token Savior's own contract — no host sets it). Registered if valid, wins over every other boot signal |
| off (bool, | Freeze the active project: explicit |
|
| Tool profile. |
| off (on in | Strip verbose tool schemas from the manifest |
|
| Hot-tool count exposed by the telemetry-driven |
| on |
|
| off | Disable the memory engine (clean-context workloads) |
| off | Skip read-side capture sandboxing and drop the capture tools from the manifest (no profile flips this; |
| off | Disable code-mode tools |
|
| Node binary used by the code-mode sandbox |
| off (bool) | Don't expose observations as |
| off (bool) | Pre-build project slots at startup |
| off (bool) | Skip the |
| off (bool, | Delegate the cold |
|
| Unix socket of the |
| auto-detected | Client label ( |
| — | Free-form label attached to session telemetry |
Indexing
Var | Default | Purpose |
| built-in list | Colon-separated globs; replaces the default include list |
| built-in list | Colon-separated globs; replaces the default exclude list |
| — | Colon-separated globs appended to the default excludes |
| — | Colon-separated globs appended at the indexer level |
|
| Max file size (bytes) to index |
|
| Max files per project |
|
| File watcher: |
| off | Force the polling watcher backend |
Claude Code hooks
Var | Default | Purpose |
|
| Minimum tool-output size to sandbox |
| off | Strong-replace: tell the agent to ignore the inline output and |
|
| Captures older than this are purged on the next |
| off | Enable PostToolUse Bash output compactors |
|
| Hybrid mode: compact-result size above which the full original is also sandboxed |
|
| Hybrid mode: compact-result size below which the sandbox is always skipped |
| off | Enable the PreToolUse Bash command rewriter |
| — | JSONL audit log of every rewrite |
| off | SessionStart memory hook emits only the Memory Index block |
Memory extras
Var | Default | Purpose |
| off | Port for the observation web viewer (unset = disabled) |
| off | LLM auto-extraction of memory observations (Anthropic API key required) |
|
| Auto-extraction model override |
| off | Auto-save memory observations |
| — | Critical-observation feed |
Storage, dashboard, debugging
Var | Default | Purpose |
|
| Telemetry + stats directory |
|
| Dashboard bind host |
|
| Dashboard port |
| off (bool) | Dashboard also lists projects under temp dirs |
| off | Debug logging |
| off (bool) | MCP request lifecycle tracing |
Not knobs: CLAUDECODE, CLAUDE_CODE_ENTRYPOINT, CLAUDE_PROJECT_DIR,
CLAUDE_CONTEXT_REMAINING_PCT, CODEX_* and HERMES_* are read for host/client
detection and boot-time project hints — the environment sets them, you don't.
(CLAUDE_PROJECT_DIR is what Claude Code actually exports; it always names the
main checkout, never the worktree the session works in, so the launch directory
outranks it when that directory is a linked worktree. CLAUDE_PROJECT_ROOT
moved up into the knobs table: nothing sets it but you.)
Naming trap: TS_PROFILE in the benchmark snippets is tsbench's variable;
the server reads TOKEN_SAVIOR_PROFILE.
License
MIT
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityCmaintenanceA Model Context Protocol server that enables Large Language Models to interact with Git repositories through a robust API, supporting operations like repository initialization, cloning, file staging, committing, and branch management.Last updated284,730229Apache 2.0
- Flicense-qualityCmaintenanceAn MCP server for efficient code indexing and symbol retrieval using tree-sitter AST parsing to fetch specific functions or classes without loading entire files. It significantly reduces AI token costs by providing O(1) byte-offset access to code components across multiple programming languages.Last updated
- Alicense-qualityBmaintenanceAn MCP server that provides structure-aware code analysis (symbol trees, dependencies, docs) to reduce AI agent token consumption by up to 99%, along with Git commit intelligence.Last updatedMIT
- Alicense-qualityCmaintenanceAn MCP server that provides ultra-efficient code exploration through AST analysis, reducing LLM token usage by up to 95% while enabling instant call graph generation and dependency analysis for massive codebases.Last updatedMIT
Related MCP Connectors
An MCP server that gives your AI access to the source code and docs of all public github repos
User-owned memory for AI agents, Copilot, Claude, IDEs, CLIs, and chat apps over remote MCP.
A MCP server built for developers enabling Git based project management with project and personal…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mibayy/token-savior'
If you have feedback or need assistance with the MCP directory API, please join our Discord server