
Token Optimizer
io.github.omkar9854Published by GitHub account omkar9854v0.1.0Updated Oct 24, 2026
Reversible context compression for AI agents: cut token usage up to 94%, originals retrievable
Overview
A local MCP server that compresses agent context (tool output, logs, JSON, code, prose) before it reaches the LLM, with byte-exact originals retrievable.
- What you can do
- Compress context before it reaches the model, routing JSON, logs, code and prose to different lossless or reversible transforms to cut token usage. Retrieve the byte-exact original of any compressed content by its reference marker. Keep errors and warnings verbatim and leave the system prompt and recent messages untouched. Store originals in memory, SQLite, or a bring-your-own cipher store.
- When to use it
- Useful when an agent reads large tool outputs, logs, JSON dumps or source files and token cost or context limits are a problem, especially in air-gapped or client-site deployments where no network egress is acceptable.
- Requirements
- Runs as a local process via uvx from the PyPI package slimctx (Python, standard library only). The README's MCP example starts it with a SQLite store path. No accounts, API keys, environment variables or headers are declared.
Installation
In SourceWeft
- Open Token Optimizer in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
slimctx — the token optimizer for AI agents
[CI] [PyPI] [MCP Registry] [License: Apache 2.0] [Python 3.9+] [Dependencies: zero]
Zero-dependency, fully-reversible context compression for AI agents.
slimctx compresses what your agent reads — tool outputs, logs, JSON, source files, prose — before it reaches the LLM. Same answers, fraction of the tokens. Pure Python stdlib: no ML models, no downloads, no network calls, ever. Auditable end to end in ~1,600 lines.
[slimctx demo: 61,700 tokens compressed to 298 in 29ms, FATAL lines preserved, byte-exact retrieval]
Live output of python3 benchmarks/demo.py — run it yourself, nothing is staged.
Results (synthetic workloads modeled on real agent traffic)
Every run also verifies that each planted "needle" (the FIXME, the OOMKill,
the outlier) survives compression, and that every lossy transform is
byte-exact reversible. Reproduce with python3 benchmarks/bench.py.
How it works
The four guarantees
- Universal reversibility. Before any lossy transform, the original
goes into a content-addressed store (memory / SQLite / bring-your-own
cipher) and the output carries a
[slimctx-ref <hash> ...]marker. The model — or you — can always get the byte-exact original back. - Errors are never dropped. Every compressor pins error/warning content: log errors pass verbatim, salient JSON rows are kept, salient sentences outrank filler.
- Deterministic output. Same input → byte-identical output, across runs and processes. Compressed prefixes stay stable, so provider prompt-caches (Anthropic/OpenAI) keep hitting.
- Net gain or no-op. If a transform doesn't save enough tokens to pay for its marker, the original is kept untouched. The live zone (system prompt + last N messages) is never modified at all.
Why not just use Headroom?
Headroom is the established project in this space and is more featureful today (provider proxy with SSE streaming, agent wrappers, cross-agent memory, an ML compression model). slimctx makes a different set of trade-offs, aimed at locked-down / client-site deployments:
If you need the proxy/wrap ecosystem, use Headroom. If you need something you can read in an afternoon, run air-gapped, and certify for a client environment, use slimctx.
Install / test
Integration sketches
As a library (any framework): call pipe.compress(messages) right
before your provider SDK call; expose pipe.retrieve as a tool named
retrieve so the model can pull originals.
As an MCP server (GitHub Copilot, Claude Code, Cursor, ...): ships built in, stdlib-only:
See USAGE.md for the GitHub Copilot (.vscode/mcp.json) setup
and a security deployment checklist.
Encrypted store:
License
Apache-2.0. Original implementation — no code derived from Headroom.
Source: README.md at commit f2cc938
Tools
0Version history
1- v0.1.0LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts