tokdiet is a local streaming reverse proxy designed to measure and govern the context sent by AI coding agents. The distinction between its parts matters: the proxy applies savings rules, while the plugin alone provides metering.
The project documentation describes a local endpoint placed between an Anthropic-compatible client and its upstream API. Its quick start uses npx tokdiet start and points ANTHROPIC_BASE_URL to http://localhost:7787. Verify current commands before use.
Interpret the benchmark carefully
The maintainers report a 66-task A/B benchmark in which input fell from 5.07 million to 1.46 million tokens, while completed tasks changed from 64 of 66 to 63 of 66. This is a maintainer-published result, not an independent guarantee. Repositories, prompts, models and tool loops vary.
Select representative tasks, record completion quality and retries, then compare input, output, latency and cost. A lower token count is not a saving if missing context causes extra turns or a faulty change.
A safe trial
- Use a disposable project and restricted API key.
- Capture a baseline without governance.
- Enable metering before transformations.
- Run the same small task set through both paths.
- Review diffs and tool results, not only token totals.
Because the proxy sees prompts, code and credentials in transit, inspect its source, bind it locally and confirm logs do not retain secrets. Cost estimates may also differ from provider invoices.
tokdiet best fits teams with high, observable usage and repeatable tasks. For protocol-level problems rather than context volume, use the mcpsnoop guide.
Primary source: tokdiet repository and benchmark.
Metrics worth retaining
Measure tokens per completed task, not per request. Record retries, tool failures, human corrections and elapsed time beside provider-reported usage. Separate prompt caching from context removal so two savings mechanisms are not credited twice. Keep a holdout task set and rerun it after each rule change. If quality falls on security, migration or debugging work, exempt those workflows instead of optimizing every request identically.