← Back to directory
T

Token Optimizer MCP

Community
Compression that optimises your bill, not your byte count — and ships the benchmark so you can check it.
GitHub source repository ↗
★ 531 Stars Category · Dev Tools Very popular
64FMRS · C

Token Optimizer MCP is an unusually large scope project and a rare self-verifying one: it does not merely claim token savings, it ships the benchmark scripts, the losses, the excluded data and the unfinished studies alongside the wins. Its core value is twofold — compressing tool results and smart-reading files before they reach the model, and a local knowledge graph that fills itself in from real agent traffic. Against typical alternatives it is explicit about separating direct, materialized savings from causal graph evidence, and it renders an unmeasurable saving as unknown rather than zero.

What deserves caution: the many comparisons against the competitor HeadRoom are offline estimates using this repository's own reimplementation of their published design, not their shipped binary, and the author repeatedly states that superiority was not established and that several studies are incomplete. The graph's causal benefit remains Collecting. It also actively refuses tool calls and writes elided payloads to local spill files, both of which have real workflow and security implications. Best suited to developers willing to accept a more invasive integration and able to run the benchmarks themselves.

Reliability
12/20
Security and permissions
9/20
Maintenance
14/20
Documentation
16/20
Setup experience
13/20
Read the FMRS scoring method →

Token Optimizer MCP is a locally running MCP server that optimizes the context window of AI coding agents. Through caching, compression and smart file tools, it reduces token spend before tool results reach the model; the README claims a 60–90% cut.

It also maintains a cross-session local knowledge graph: nodes for files, symbols, tasks and findings, joined by edges such as derived_from, contains, supersedes, contradicts and related. Findings, decisions and dead ends accumulate as a side effect of working, then feed back the moment the agent touches a relevant file, so conclusions are not re-derived. Data stays local — no account, no telemetry, no hosted service.

The server speaks stdio and ships as the npm package @ooples/token-optimizer-mcp under the MIT license, which permits commercial use. The README documents 16 clients and separates an enforcing tier (10 clients with a pre-execution hook that can refuse a wasteful built-in call) from a rules tier (6 clients where optimized routing is mandatory via rules but cannot be vetoed). Benchmarks ship in the repository and can be regenerated, e.g. with node bench/compression/proof.mjs.

Tools

smart_read
Read a file and return compressed or diffed content, avoiding a repeat read of an unchanged file.
smart_grep
Run a search and return compressed matches, keeping rows that depart from the expected shape.
smart_glob
Find files by pattern and return the result in a reduced form.
smart_edit
Edit a file in an optimized way that cuts redundant context.
expand
Expand previously elided content from a content-addressed store; it never re-runs the original command.
wiki_write
Let the active model record a durable conclusion (finding, decision or dead end) into the project knowledge graph.
wiki_read
Read what the project or the files about to be touched already know.
wiki_query
Query the graph directly: one finding by key, a ranked BM25 search over claims, a node with its neighbours, or the graph's own audit.
token_audit
Return a ranked queue of what is costing the most per session, with how to fix each line.
waste_audit
Turn a detected waste into a durable, measured, reversible fix such as a skip rule.
fleet_audit
Rank every project on the machine by measured cost and transfer a proven fix across projects by content hash.

Setup

Claude Code: run /plugin marketplace add ooples/token-optimizer-mcp, then /plugin install token-optimizer@token-optimizer, then /reload-plugins.

MCP server only (any client): npx -y @ooples/token-optimizer-mcp@latest. Optionally set TOKEN_OPTIMIZER_CACHE_DIR to choose the cache directory; it defaults to ~/.token-optimizer-mcp.

Codex: codex plugin marketplace add ooples/token-optimizer-mcp, then codex plugin add token-optimizer@token-optimizer; or codex mcp add token-optimizer -- npx -y @ooples/token-optimizer-mcp@latest.

After installing, verify the hooks actually work with npx token-optimizer-doctor — it feeds a synthetic payload to the real hook binary and asserts a large read is refused and a small one is not. Ready-made config for all sixteen clients lives in the repository's integrations/ directory.

claude_desktop_config.json
{
  "mcpServers": {
    "token-optimizer": {
      "command": "npx",
      "args": ["-y", "@ooples/token-optimizer-mcp@latest"],
      "env": {
        "TOKEN_OPTIMIZER_CACHE_DIR": "/path/to/cache"
      }
    }
  }
}

Fit and risk

Best for

  • Long, multi-turn coding agent sessions
  • Developers using several CLI clients at once
  • Teams that need local-only operation, no telemetry, and a commercially usable license
  • Teams that want to verify compression claims with a reproducible benchmark rather than vendor assertions

Not for

  • Anyone who wants a bare MCP server without installing client hooks or plugins (the README states adding the server alone does not enforce anything)
  • Scenarios where no request content may ever be written to local disk (the proxy writes elided payloads to spill files in the OS temp directory)
  • Users who need a hosted service or cloud account
  • Environments that cannot run Node.js 22+

Required permissions

  • Read and write project files for smart reads, diffs and edits
  • Install and run client lifecycle hooks that intercept or re-route tool calls before execution
  • Write cache, knowledge graph, logs and elided-content spill files to local disk
  • Optionally start a compression proxy process bound to the local loopback address
  • Read native CLI usage receipts for token accounting and pricing

Risks and side effects

  • The server refuses or rewrites built-in tool calls (Read, Grep, Glob, Edit, Write, and shell cat/head/grep -r), which in enforce mode can interrupt existing workflows
  • Recoverable elided content is written with 0600 permissions under token-optimizer-spill/ in the OS temp directory and is not deleted while the proxy runs; a kill signal or power loss leaves the directory behind to be cleaned up by hand
  • The proxy does not inspect written content for secrets, so a secret in your conversation can reach a spill file like any other text
  • The local knowledge graph and cache hold project structure, content hashes and derived findings
  • Several comparisons in the README are development-stage or incomplete studies; the project itself states that superiority was not established and that aggregate intervals still span 1.0

Troubleshooting

  1. If nothing seems to be happening, the lifecycle bundle is probably not installed: an MCP server process cannot modify the host, and npm 11 gates lifecycle scripts behind allow-scripts, so install the plugin or hook bundle for your client
  2. Run npx token-optimizer-doctor; it feeds a synthetic payload to the real hook binary and asserts a large read is refused
  3. If the proxy fails to start after enabling it, check the port and loopback binding, and confirm Node.js is version 22 or newer
  4. A harvest state of off:no-key means no model credential is configured; point TOKEN_OPTIMIZER_HARVEST_ENDPOINT at a local model to run it offline — npx token-optimizer-doctor reports which mode is live
  5. To inspect hook health, run npm run diagnostics with optional --hours and --output; raw event rows are opt-in, capped at 1,000
  6. To disable enforcement temporarily set TOKEN_OPTIMIZER_MODE=off; to disable proxy routing set TOKEN_OPTIMIZER_PROXY=0

Use cases

Cut tokens spent re-reading unchanged files in a coding agent session
Compress tool results, search output, logs and build output before they reach the model
Carry findings, decisions and dead ends across agent sessions
Attribute token spend by client and action to find the most expensive project
Reuse a proven optimization fix across several local projects

Supported clients

Claude CodeFull support
CodexFull support
GitHub Copilot CLIFull support
Gemini CLIFull support
Qwen CodeFull support
CursorFull support
ClineFull support
OpenCodeFull support
KiloFull support
WindsurfFull support
Roo CodePartial support
ZedPartial support
AmpPartial support
ContinuePartial support
CrushPartial support
DroidPartial support