
Token Savior
io.github.Mibayy由 GitHub 帳號 Mibayy 發布v4.13.0更新於 Oct 26, 2026
Structural codebase MCP server with persistent memory: navigate by symbol, recall across sessions.
概覽
本機 MCP 伺服器,依符號索引程式碼庫並保留持久記憶,讓 AI 程式助理以指標導覽程式碼,而非整檔讀取。
- 可以做什麼
- 依符號索引與導覽程式碼:尋找函式、類別、匯入與呼叫圖,取得原始碼、相依者與變更影響
- 搜尋程式碼庫並取得編輯脈絡,用於範圍受控的修改
- 在持久記憶引擎中跨工作階段保存與回想決策、修正與慣例
- 程式碼稽核:偵測破壞性變更、找出無用程式碼、分析設定
- 掃描代理工作階段紀錄,找出原本可更省 token 的呼叫方式
- 可選擇透過掛鉤壓縮或改寫 Bash 指令輸出
- 適用情境
- 適合在大型程式碼庫中工作的程式助理,避免整檔讀取浪費脈絡,也適合需要記住先前決策的工作階段。若希望 Bash 輸出在脈絡壓縮後仍可查詢,也可考慮。
- 執行需求
- 以 Python 套件(pip 或 uvx)透過 stdio 在本機執行,僅支援桌面端。必須以 WORKSPACE_ROOTS 列出要索引的專案絕對路徑。另有可選變數可調整工具設定、用戶端標籤、索引與掛鉤。在 Claude Code 中需啟用 alwaysLoad,否則工具會被 ToolSearch 隱藏。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Token Savior,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Token Savior
One MCP server. One profile. 97.9% on tsbench at -80% tokens. Structural code navigation, persistent memory, and Bash command rewriting for AI coding agents.
[PyPI] [Benchmark] [Python 3.11+] [MCP] [CI]
mibayy.github.io/token-savior -- project site + benchmark landing Benchmark source + fixtures: not currently published (see Reproducing the score below)
[Plain Claude Code against Claude Code + Token Savior: 92,609 vs 38,150 new tokens, cost -45%]v4.23 in 31 seconds, measured on 2026-10-07 · watch the full video (MP4, sound on)
Benchmark -- 96 real coding tasks (Claude Opus 4.7, May 2026)
Reproduces with the optimized profile (single env var). The harness that
produced these numbers is described below; its repository is not public at the
moment, so take the figures as reported rather than as independently verifiable.
A re-measurement was published here on 2026-08-09 and has been withdrawn on
2026-08-10. It reported new-token savings from a small replacement harness.
Those numbers did not measure this server at all: across 143 benchmark
sessions, exactly one called a Token Savior tool. The client running the
harness had MCP deferred-tool loading enabled, so all 18 tools sat behind a
ToolSearch lookup instead of appearing in the model's manifest. The model
never saw them and fell back to Grep and Read — 66 greps, 30 reads, one
MCP call. What varied between the "profiles" was the size of the cached
prefix, not what the agent did.
The lesson is worth more than the numbers were: a benchmark of an MCP server must assert that its tools were actually called. Ours did not, so it happily compared two identical agents. That assertion now exists in the harness.
The headline figures above therefore stand as reported and unverified, as stated in the previous paragraph.
Re-measured on 2026-10-07, with the tools actually called. Same 8 tasks
on a frozen copy of this repo (commit 9d15a1e, no CLAUDE.md), Claude
Haiku 4.5, plain Claude Code against the auto profile with alwaysLoad.
The harness checks that the Token Savior sessions really called the server.
All 48 sessions succeeded. v4.22.0, measured once, saved 14% and used the tools
in 5 sessions out of 8. Editing, measured on 2026-10-08 on the same repository (3 tasks in files of
1 900 to 3 700 lines, graded by running the code and the module's tests,
4 passes): every session of both arms succeeded, and cost is too noisy to call
a gain (from -54% to +16% per pass). Native Edit only needs a partial
Read, so there is little left to remove there.
Wall time is worse because each benchmark session starts a fresh server that
indexes the repo first; a long-lived session pays that once. What moved from
v4.22.0 to v4.23.0 is mostly wording: search_codebase now names the function
holding each hit, and the tool descriptions say plainly which native call they
replace.
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.
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
Add to your MCP config (e.g. Claude Code):
"alwaysLoad": true matters on Claude Code (2.1.28x and later): without
it, every tool of the server sits behind ToolSearch and the model reaches for
Read and Grep, which are already loaded. Measured on this project's
benchmark before the option existed: one session in 143 called a Token Savior
tool. With it, the manifest costs a few thousand cached tokens per session.
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:
ts 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:
Compactor catalog (34)
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.
These run in PostToolUse, so they do not shrink the current turn. The hook fires after the tool has returned; it can add context, not remove it. The compact rendering is appended below the raw output, which stays. What you gain is persistence: the full output goes to the capture sandbox and outlives a context compaction. For an actual reduction of what reaches the model, use the PreToolUse rewriter (
TS_BASH_REWRITE=1) — it edits the command before it runs.
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.
Findings: 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
Detects 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 bounds the noisy Bash output that bloats turn budgets between code reads — by rewriting the command before it runs.
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.
Which of those two actually shrinks a turn, and which does not. Measured 2026-08-09, and worth stating plainly because the distinction is not obvious:
- The PreToolUse rewriter changes the command before it runs, so a smaller output is produced and a smaller output reaches the model. This is a real reduction in the current turn.
- The PostToolUse compactors run after the tool has returned. A PostToolUse hook can only add context; by the time it fires, the raw output has already been sent. The compact rendering is appended, it does not replace anything. What the compactors genuinely buy you is different and still valuable: the full output is preserved in the capture sandbox and survives a context compaction, so it can be queried later instead of being re-run.
If your goal is a smaller turn, TS_BASH_REWRITE=1 is the switch that does
it. If your goal is to stop losing command output across compactions, that is
TS_BASH_COMPACT=1.
Profile comparison
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.
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. Of those two, the
rewriter is the one that reduces the current turn.
Token savings
Install
pip (MCP server)
uvx (no venv, no clone)
Claude Code one-liner
Development
Suite 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/:
The 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.
Reproducing the tsbench score
Honest status, checked 2026-08-09: the benchmark repository these instructions pointed at returns 404, and so did the BENCHMARK-SUMMARY link above. Rather than leave a recipe that cannot run, here is what the harness does, so the number can be judged on its method:
- A generated toy repo (deterministic seed) with four planted traps: a symbol
defined twice, a three-level call chain, an
a -> b -> c -> aimport cycle, and a dead function whose name contains a live one. - Eight read-only tasks, scored mechanically against an
expectedlist and aforbiddenlist. The forbidden list is the half that matters: an answer can contain the right target and the wrong one, and a grader that only looks for the right one would score it correct. - A
sans_tscontrol arm running plain Read/Grep/Glob, without which the bench compares Token Savior profiles to each other and can never conclude "useless" — and therefore never "useful" either.
One trap worth knowing about if you rebuild it: the harness spawns
claude -p, which inherits ~/.claude/settings.json. If any Token Savior
PreToolUse hook is enabled on the machine, it applies to the control arm too
and rigs the comparison. Neutralise them in both arms
(TS_GUARD_OFF=1 TS_READ_GUARD=0 TS_BASH_REWRITE=0).
Bonus: 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:
On 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
Indexing
Claude Code hooks
Memory extras
Storage, dashboard, debugging
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
來源:README.md,提交 770e055
工具
0版本歷史
1- v4.13.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分