Structural codebase MCP server with persistent memory: navigate by symbol, recall across sessions.
io.github.Mibayy/token-savior-recall โ Model Context Protocol (MCP) Server
The io.github.Mibayy/token-savior-recall MCP server is described as a structural codebase server with persistent memory. It supports navigating by symbol and recalling information across sessions, intended for working with code structure and retained context.
๐ ๏ธ Key Features
Structural codebase MCP server
Persistent memory
Navigate by symbol
Recall across sessions
๐ Use Cases
Navigating a codebase using symbols
Remembering and recalling prior context across multiple sessions
โก Developer Benefits
Symbol-based navigation for code structure exploration
Cross-session recall enabled by persistent memory
โ ๏ธ Limitations
Available documentation data does not specify tool count, configuration options, supported languages, or any additional capabilities beyond structural navigation and recall
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.
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:
bash
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.json
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.
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.
python
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, JSON
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.
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 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
optimized
15
~1.5 KT
Recommended default -- Pareto win on tsbench
auto
adaptive
~1-2 KT
Per-client telemetry-based (experimental)
tiny
6
~0.6 KT
Minimal hot loop
lean
51
~4 KT
Legacy -- broader surface
compact-only
1
~0.3 KT
Bash compaction only -- you already run symbol nav elsewhere
full
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.
Run TS as compact-only if serena is your navigator
codebase-memory
Persistent code graph
With the memory engine
TS_MEMORY_DISABLE=1
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.
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/:
bash
python3 scripts/bench_compactors_real.py # match rate + mean savings
python3 scripts/bench_compactors_unmatched.py # top unmatched commands
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.
To reproduce the tsbench score:
bash
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 B
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:
bash
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 agents
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
Var
Default
Purpose
WORKSPACE_ROOTS
current dir
Comma-separated project roots to index
PROJECT_ROOT
โ
Single-root alternative to WORKSPACE_ROOTS
TOKEN_SAVIOR_PROFILE
full
Tool profile. optimized โ the value the quickstart config and ts init recommend โ ships the Pareto manifest, implies thin schemas, and omits the capture tools from the manifest
TS_THIN_SCHEMAS=1
off (on in optimized)
Strip verbose tool schemas from the manifest
TS_AUTO_HOT_K
10
Hot-tool count exposed by the telemetry-driven auto profile
TOKEN_SAVIOR_CHAIN_NUDGE
on
0/false/off disables chained-tool nudges
TS_MEMORY_DISABLE=1
off
Disable the memory engine (clean-context workloads)
TS_CAPTURE_DISABLED=1
off
Skip read-side capture sandboxing and drop the capture tools from the manifest (no profile flips this; optimized only hides the capture tools)
TS_CODE_MODE_DISABLE=1
off
Disable code-mode tools
TS_CODE_MODE_NODE
node
Node binary used by the code-mode sandbox
TS_RESOURCES_DISABLED
off (bool)
Don't expose observations as ts://obs/{id} MCP resources
TS_WARM_START
off (bool)
Pre-build project slots at startup
TOKEN_SAVIOR_NO_WARMUP
off (bool)
Skip the ts_search embedding warm-up
TS_SEARCH_COLD_DELEGATE
off (bool, on ok)
Delegate the cold ts_search call to a running ts daemon
TS_SOCK
/tmp/ts.sock
Unix socket of the ts daemon (CLI + cold delegate)
TOKEN_SAVIOR_CLIENT
auto-detected
Client label (claude-code, โฆ) for telemetry/client detection
TOKEN_SAVIOR_SESSION_LABEL
โ
Free-form label attached to session telemetry
Indexing
Var
Default
Purpose
INCLUDE_PATTERNS
built-in list
Colon-separated globs; replaces the default include list
EXCLUDE_PATTERNS
built-in list
Colon-separated globs; replaces the default exclude list
EXCLUDE_EXTRA
โ
Colon-separated globs appended to the default excludes
TOKEN_SAVIOR_EXCLUDE_PATTERNS
โ
Colon-separated globs appended at the indexer level
TOKEN_SAVIOR_MAX_FILE_SIZE
500000
Max file size (bytes) to index
TOKEN_SAVIOR_MAX_FILES
10000
Max files per project
TOKEN_SAVIOR_WATCHER
auto
File watcher: auto / on / off
TS_WATCHER_FORCE_POLLING
off
Force the polling watcher backend
Claude Code hooks
Var
Default
Purpose
TS_CAPTURE_THRESHOLD_BYTES
4096
Minimum tool-output size to sandbox
TS_CAPTURE_REPLACE=1
off
Strong-replace: tell the agent to ignore the inline output and capture_get the URI
TS_BASH_COMPACT=1
off
Enable PostToolUse Bash output compactors
TS_COMPACT_INLINE_THRESHOLD
4096
Hybrid mode: compact-result size above which the full original is also sandboxed
TS_COMPACT_TINY_THRESHOLD
256
Hybrid mode: compact-result size below which the sandbox is always skipped
TS_BASH_REWRITE=1
off
Enable the PreToolUse Bash command rewriter
TS_BASH_REWRITE_LOG
โ
JSONL audit log of every rewrite
TS_HOOK_MINIMAL=1
off
SessionStart memory hook emits only the Memory Index block
Memory extras
Var
Default
Purpose
TS_VIEWER_PORT
off
Port for the observation web viewer (unset = disabled)
TS_AUTO_EXTRACT=1 + TS_API_KEY
off
LLM auto-extraction of memory observations (Anthropic API key required)
TS_MODEL
claude-sonnet-4-6
Auto-extraction model override
TOKEN_SAVIOR_MEMORY_AUTO_SAVE=1
off
Auto-save memory observations
TELEGRAM_BOT_TOKEN + TELEGRAM_CHAT_ID
โ
Critical-observation feed
Storage, dashboard, debugging
Var
Default
Purpose
TOKEN_SAVIOR_STATS_DIR
~/.local/share/token-savior
Telemetry + stats directory
TOKEN_SAVIOR_DASHBOARD_HOST
127.0.0.1
Dashboard bind host
TOKEN_SAVIOR_DASHBOARD_PORT
8921
Dashboard port
TOKEN_SAVIOR_INCLUDE_TMP_PROJECTS
off (bool)
Dashboard also lists projects under temp dirs
TOKEN_SAVIOR_DEBUG=1
off
Debug logging
TOKEN_SAVIOR_TRACE
off (bool)
MCP request lifecycle tracing
Not knobs: CLAUDECODE, CLAUDE_CODE_ENTRYPOINT, CLAUDE_PROJECT_ROOT,
CLAUDE_CONTEXT_REMAINING_PCT, CODEX_* and HERMES_* are read for host/client
detection โ the environment sets them, you don't.
Naming trap: TS_PROFILE in the benchmark snippets is tsbench's variable;
the server reads TOKEN_SAVIOR_PROFILE.
License
MIT
Install
Configuration
Environment variables
WORKSPACE_ROOTSrequired
Comma-separated list of absolute paths to project roots to index.
TOKEN_SAVIOR_CLIENT
Optional client identifier (e.g. 'claude-code', 'cursor', 'hermes') for usage attribution.
TOKEN_SAVIOR_PROFILE
Manifest size. 'optimized' (recommended) advertises the Pareto-optimal 15-tool set; 'auto' sizes it from your own usage; 'full' advertises every tool; 'compact-only' if you already run symbol navigation elsewhere.