token-diet

token-diet

An MCP server that reduces token usage by injecting graph-ranked repo maps, decision logs, and diff-only output into AI coding tool requests.

Category
Visit Server

README

ctx — token-saving context engine

Local middleware between your AI coding tool (Claude Code, Cowork, Codex, any MCP host) and the model. It shapes every request to be minimal but intelligent: a graph-ranked repo map instead of whole files, an append-only decision log instead of replayed history, a stable cached prefix, and diff-only output. Saving tokens and keeping the model sharp are the same goal — see ARCHITECTURE.md.

Install

pipx install token-diet            # core (runs with graceful fallbacks)
pipx install 'token-diet[all]'     # full: MCP + proxy + tree-sitter + tiktoken + docs

Not on PyPI yet? Install straight from GitHub:

pipx install 'git+https://github.com/aryxnsdfs/token-diet'

From source:

pip install -e '.[all,dev]'

The core works with zero heavy deps via fallbacks (regex parser, char-based token estimate, heuristic distillation). Install extras to upgrade each piece; ctx doctor shows what's active.

Quick start

cd your-project
ctx init        # build index, register with host, write command files
ctx doctor      # verify wiring + see which optional deps are active

In Claude Code, press / and pick a command. First run /init (or /ctx start) to warm the chat — injects the repo map, enables diff mode.

Commands

Command Does
/init Build index, inject map, enable diff-only output
/map [path] Inject the graph-ranked repo map
/focus <file|symbol> Pin full detail of a file or symbol
/explain <symbol> Pull just one symbol's body
/diff Force diff-only (SEARCH/REPLACE) output
/compress Distill old history into the decision log
/cost Token + cache telemetry
/route <tier> Force a model tier (frontier|cheap_cloud|local)

Two front-ends, one engine

  • Mode A — MCP server. ctx serve exposes every command as an MCP prompt (you type /name) and tool (the model calls it). The native path for MCP-aware hosts.
  • Mode B — local proxy. ctx proxy runs a localhost:8000 server you point a client at; it optimizes every request and parses /text for non-MCP tools.

Layout

ctx/
  cli.py        init · index · serve · doctor · proxy
  registry.py   single source of truth for commands
  server.py     FastMCP: prompts + tools + resources
  proxy.py      Mode B FastAPI proxy
  init/         per-host registration adapters
  engine/       index · repomap · assembler · budget · memory · docs · patch · router · telemetry
tests/          unit + eval harness (the guardrail)

The guardrail

tests/evals/ holds representative tasks with automatic checks. Token reduction only counts as saving intelligence if task success holds. Run pytest on every engine change.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured