I opened the bill. The number was climbing, but I couldn’t say what it was spent on.

The same files I’d fed the model last round got sent again this round, byte for byte. Tool logs, search results, duplicated README snippets… context leaks like a bucket with a hole. And whether any “optimization” actually worked — there was no receipt to check against.

d-token answers three questions:

  1. Where did these tokens actually go?
  2. Which provider really handled the request?
  3. Did compression actually happen — or does it just feel cheaper?
Local context control plane collage: token stream passing through compression gears and an explicit routing switch toward the provider
The full local control plane: the raw token stream passes through compression transforms first, then takes an explicit route to the provider — every step inside the machine boundary.
TL;DR d-token is a context control plane that runs on your own machine: requests from your AI coding agent pass through it first — duplicates get compressed, routing stays explicit — then go out to the model provider, with a receipt for every request. In one measured real request, it cut the physical payload by 33,705 tokens — not an estimate, but the difference between Local Tokens and Provider Tokens on the receipt. Three rules: secrets never leave your machine, routing never switches silently, and a broken config can be rolled back. Currently at 0.2.0-beta.1.

Problem

AI coding agents keep resending the same files, logs, and tool outputs. The token bill quietly grows, but:

Measured savings in one request
One real routed request on 2026-08-04: 33,705 fewer tokens sent (not an average).
  • Can’t tell which session burns the most
  • Can’t tell whether an “optimization” actually worked
  • Break a config, and there’s no way back

No prompt-engineering trick fixes this. What’s needed is infrastructure that is visible and roll-back-able.

The waste comes from three places. Resends: the same files fed last round go out again byte for byte — the fattest slice. Log bloat: tool outputs, search results, and build logs stuffed into context wholesale, when only a few lines matter. No ledger: whether an “optimization” worked is pure vibes, with no receipt to prove anything.

Local is the premise, not an option. Context carries source paths, secret boundaries, internal company structure. Put compression and routing in a third-party black box and you hand over visibility too.

d-token keeps settings, diagnostics, request metadata, and rollback history on your machine. Plain logs never store full prompts, full responses, source text, or API keys. Your chosen provider still receives the requests you send — but now there’s a door you control in between.

Four-stage pipeline
Agent → compression transforms → explicit routing → configured provider.

Approach

The README is blunt about what it is: a local context control plane for AI coding agents.

It sits between “the agent you’re using” and “the model provider you configured”. It compresses redundancy before context leaves your machine, keeps routing explicit, and makes config changes recoverable — not a pile of scripts and guesswork.

AI coding agent
     ↓
   d-token   connect · optimize · route · observe
     ↓
 your configured model provider

Three hard rules:

  • Local-first: secrets never end up in plain logs; the control plane runs on your machine.
  • Explicit routing: every request takes a stated path, never silently switches providers.
  • One receipt per request: source agent, route, transforms, Local / Provider Tokens, recovery status.

The compression pipeline runs in four stages, each more aggressive than the last. First, dedupe: content-hash matching finds repeated chunks — the same file sent twice counts once. That’s the bulk of the 33,705. Second, trim: fold tool logs, merge duplicated README fragments, keep only the hit lines from search results. Third, summarize: long-tail history gets compressed into summaries that keep the decisions and drop the meandering. Fourth, redact: keys, tokens, and internal paths get handled before anything crosses the machine boundary. Secrets stay home.

The routing table is explicit. Every request’s path — which route, which provider, which model — is written down, never silently switched. You think you’re on the cheap lane and at midnight it flips to the expensive one? That kind of bill ambush doesn’t exist here. Route changes leave a trail and go through the five-step config flow.

The receipt is the most honest part of the system. One per request: which agent it came from, which route it took, which transforms ran, how many Local Tokens, how many Provider Tokens, recovery status. Savings on paper, not a feeling. It’s the receipt that lets d-token claim “33,705 fewer tokens in one measured request” instead of “save 30% on average” — the former is reproducible, the latter can’t be audited.

The desktop app is Tauri 2 + Rust core. The Rust side handles connection state, routing decisions, the compression pipeline, and receipts; the frontend only does display and the safe-config flow. The heavy lifting lives in Rust; the UI is a good-looking front door — the right division of labor, since a compression pipeline wants determinism and speed, not animations.

Config changes aren’t “save and it applies”. They go: preview → redacted diff → backup → verify → roll back. When something breaks, you diagnose, fix, recover — the README calls it “the config doctor”. Editing configs barehanded flips over sooner or later; a rollback button is infrastructure dignity.

Status semantics are deliberately spelled apart:

  • detected ≠ configured ≠ connected ≠ verified
  • passing tests ≠ “passing real compression”

Don’t trust a “connected” badge on sight — run one real request and read the numbers on the receipt.

The deeper lesson: when you build middleware in the AI toolchain, honesty beats a feature list. How much was saved, what wasn’t, and why — all on the receipt. Marketing-style “save X% on average” convinces nobody; developers only believe numbers they can reproduce.

Results

The README records one number: 33,705 fewer tokens in a single real routed request (measured, 2026-08-04).

Token savings infographic: local tokens vs provider tokens, 33,705 measured savings
Measured savings: local tokens entering the control plane on the left, tokens actually sent to the provider on the right — the 33,705 difference is receipt-backed.

Not “save 30% on average” marketing — a reproducible measurement. The receipt shows Local Tokens vs. Provider Tokens side by side. How much you saved is on paper, not a feeling. But don’t misread it: this is one data point, not an average. What you save depends on how bad your resends are — heavy users with bloated logs gain the most; clean little requests save almost nothing.

The tradeoffs deserve daylight. Compression isn’t free: the local pipeline adds latency, summaries can lose detail, dedupe lives and dies by content-hash hit rates. Saving tokens must never cost correctness — which is where the roadmap’s phrase “trusted compression” comes from: if compression eats critical context, every saved cent turns into debug hours.

Currently at 0.2.0-beta.1, a public unsigned pre-release (macOS ARM64 / Windows x64). Unsigned builds may trigger OS security warnings — verify the repo and hashes; don’t bypass system protections.

On the roadmap:

  • v0.3: cross-agent Context Relay, Session Cache, cc-switch follow / lock / observe
  • v0.4: multi-agent adapters, low-risk auto-fix, stable signing

Deep compression, Headroom-style integrations, and full signed distribution are still on the way. Two experiments on the horizon are worth a mention: LeanCTX — cross-agent context reuse, so the second agent doesn’t get re-fed what the first one already saw; and optical compression — rendering context into images and compressing that. Sounds wild, but the bet is “models sometimes read images cheaper than long text”.

git clone https://github.com/37chengshan/d-token.git
cd d-token/code/apps/desktop
npm ci
npm run tauri:dev

Main repo: 37chengshan/d-token.

Try it now

Five steps, tonight:

  1. Clone.
    git clone https://github.com/37chengshan/d-token.git
    cd d-token/code/apps/desktop
    npm ci
    npm run tauri:dev
  2. Configure your provider. Walk the safe-config flow in the UI: provider, model, key. Remember the status semantics — detected ≠ configured ≠ connected ≠ verified. Verify step by step, don’t skip.
  3. Point your agent at it. Route your AI coding agent’s requests through d-token’s local endpoint; d-token forwards them along the explicit route.
  4. Run one real request and read the receipt. Don’t trust the “connected” badge — check the receipt: Local Tokens in, Provider Tokens out, the difference is what you saved. That’s your first reproducible number.
  5. Reconcile and tune. Which session burns the most? What’s the dedupe hit rate? Is log-folding too aggressive? Tune compression strength by the receipts — how much, and why, all accounted for.

FAQ

What exactly is d-token for?

It’s a local context control plane for AI coding agents, sitting between “the agent you use” and “the provider you configured”: it compresses redundancy before context leaves your machine, keeps routing explicit, and makes config changes recoverable.

Does it really save tokens? How many?

The README records one measurement: a single real routed request on 2026-08-04 sent 33,705 fewer tokens. Note this is a single data point, not an average; the receipt shows Local Tokens vs. Provider Tokens, so the savings are on paper, not a feeling.

Will it upload my code or secrets?

No. Local-first is a hard rule: settings, diagnostics, request metadata, and rollback records stay on your machine, and plain logs never store full prompts, full responses, source text, or API keys. Your chosen provider still receives the requests you send — but now there’s a door you control in between.

What if I break a config?

Changes aren’t “save and it applies” — they go through five steps: preview → redacted diff → backup → verify → roll back. When something breaks, you diagnose, fix, and recover; the author calls it “the config doctor”.

Is it for me?

It’s for heavy users who burn real tokens: multi-agent parallelism, long sessions, log-bloated tasks. Not for: the occasional two questions (barely any savings, plus one more latency hop). Measure your most expensive session first, then decide on full rollout.

Can I use it now?

It’s at 0.2.0-beta.1, a public unsigned pre-release (macOS ARM64 / Windows x64). Unsigned builds may trigger OS security warnings — after downloading, verify the repo and hashes; don’t bypass system protections.

The X-thread version

1/ I opened my AI coding bill. The number was climbing, but I couldn’t say what it was spent on. Same files fed last round got resent this round, byte for byte — context leaks like a bucket with a hole. d-token cut 33,705 tokens off one real request of mine, with a receipt to prove it. How? 🧵

2/ ① d-token runs on your machine, sitting between “your agent” and “the model provider”. Requests pass through it first: compress redundancy, take an explicit route, then go out. One receipt per request for reconciliation.

3/ ② 33,705 isn’t “save 30% on average” talk — it’s the Local-Tokens-minus-Provider-Tokens difference on the receipt. Savings on paper, not a feeling.

4/ ③ The pipeline runs four stages: content-hash dedupe, trimming logs and duplicate fragments, long-tail summaries, pre-exit redaction. Resends are the fattest slice — kill those first.

5/ ④ Routing must be explicit: every request’s path written down, never silently switched. Route changes leave a trail; silent switches are bill assassins.

6/ ⑤ Config changes go: preview → redacted diff → backup → verify → roll back. Give your AI toolchain a rollback button too — barehanded config edits flip over sooner or later.

7/ ⑥ Status semantics deliberately apart: detected ≠ configured ≠ connected ≠ verified. Don’t trust “connected” on sight — run one real request and read the receipt.

8/ ⑦ The biggest lesson of building middleware: honesty beats a feature list. How much was saved, what wasn’t, and why — all on the receipt.

9/ ⑨ Tradeoffs: compression isn’t free — local pipeline latency, summaries can lose detail. Measure your most expensive session first, then decide on full rollout.

10/ ⑨ Experiments ahead: cross-agent context reuse (LeanCTX), session caches, even optical compression — rendering context into images and compressing that.

11/ ⑪ Currently 0.2.0-beta.1, unsigned pre-release. Verify the repo and hashes; don’t bypass system protections — checking hashes before running a beta is basic hygiene.

12/ Three hard rules: secrets never leave the machine, routing never switches silently, broken configs roll back. Before context leaves your machine, let it pass through your own door. Full version 👇 https://citygenius-blog.pages.dev/article/project-d-token

打开账单,数字在涨,但说不清花在哪。

同一批文件,上一轮刚喂过模型,这一轮又原样重发。工具日志、搜索结果、重复的 README 片段……上下文像漏水的桶。所谓「优化」有没有用,没有回执可以对账。

d-token 要回答三个问题:

  1. 这些 token 花在了哪里?
  2. 哪个 Provider 真的处理了请求?
  3. 压缩是否真的发生了,而不是「感觉更省了」?
本地上下文控制面拼贴:token 流经压缩齿轮与显式路由道岔后发往服务商
本地控制面全景:原始 token 流先经过压缩变换,再走显式路由发往服务商,每一步都留在本机边界之内。
一句话总结 d-token 是跑在你本机上的上下文控制面:AI 编程 Agent 发出的请求,先经过它压缩掉重复内容、走显式路由,再发给模型服务商,每个请求留一张回执对账。一次真实请求的实测里,它让物理发送量减少了 33,705 token——不是估算,是回执上 Local Token 和 Provider Token 的差值。核心就三条:秘密不出本机、路由绝不静默切换、配置改坏了能回退。当前 0.2.0-beta.1。

问题

AI 编码 Agent 会一遍又一遍重发相同的文件、日志和工具输出。token 账单悄悄增长,但:

单次实测节省
2026-08-04 单次真实路由请求:少发送 33,705 token(非平均值)。
  • 说不清哪个会话最烧钱
  • 说不清「优化」是否生效
  • 配置改坏了,回不去

这不是再写一个 prompt 工程技巧能解决的。需要一层看得见、可回退的基础设施。

浪费主要来自三处。重复发送:同一批文件上轮喂过,这轮原样再发一遍,这是最肥的一块。日志膨胀:工具输出、搜索结果、构建日志全量塞进上下文,真正有用的就几行。无对账:「优化」有没有生效全靠感觉,没有一张回执能证明。

本地是前提,不是可选项。 上下文里有源码路径、密钥边界、公司内部结构。压缩和路由如果放在第三方黑盒里,你就把「可见性」也交出去了。

d-token 把设置、诊断、请求元数据、回退记录都留在本机。普通日志不会主动保存完整 prompt、完整 response、源代码正文、API key。你选的服务商仍会收到你主动发出的请求——但中间多了一层你自己掌控的门。

四段路径
Agent → 压缩变换 → 显式路由 → 已配置的服务商。

做法

README 的定位很干脆:面向 AI 编码 Agent 的本地上下文控制面。

它运行在「你正在用的 Agent」和「你配置的模型服务商」之间。在上下文离开本机之前压缩冗余,保持路由显式,并让配置变更可恢复——而不是一堆脚本和猜测。

AI 编程 Agent
     ↓
   d-token   连接 · 优化 · 路由 · 观察
     ↓
 你配置的模型服务商

三条硬原则:

  • 本地优先:秘密不进普通日志;控制面跑在本机。
  • 显式路由:每个请求走明确路径,绝不静默切换服务商。
  • 每请求一张回执:来源 Agent、路由、变换、Local / Provider Token、恢复状态。

压缩管线分四段,一段比一段狠。 第一段去重:按内容哈希识别重复片段,同一文件发两遍只算一次——这是 33,705 里的大头。第二段修剪:工具日志折叠、重复的 README 片段合并、搜索结果只留命中行。第三段摘要:超长的历史上下文做压缩摘要,保留决策点,丢掉过程废话。第四段脱敏:密钥、token、内部路径在出境前先处理,秘密不出本机。

路由表是显式的。 每个请求走哪条路、哪个 provider、什么模型,写得清清楚楚,绝不静默切换。你以为走的是便宜线路,半夜被切到贵的——这种账单刺客在这里不存在。路由变更要留痕,要走配置五步。

回执是这套系统最诚实的部分。 每个请求一张:来源是哪个 Agent、走了哪条路由、做了哪些变换、Local Token 多少、Provider Token 多少、恢复状态如何。省了多少写在纸上,不靠感觉。也是因为回执,d-token 敢写「单次实测少送 33,705 token」而不是「平均省 30%」——前者可复现,后者没法对账。

桌面端是 Tauri 2 + Rust core。Rust 侧负责连接状态、路由决策、压缩管线、回执;前端只做展示与安全配置流程。重活全在 Rust,界面只是个好看的门面——这分工很对,压缩管线要的是确定性和速度,不是动画。

配置变更不是「保存即生效」,而是:预览 → 脱敏 Diff → 备份 → 验证 → 回退。出问题可以诊断、修复、恢复——README 管这叫「配置的医生」。裸改配置早晚翻车,回退键是基础设施的尊严。

状态语义也刻意分开写:

  • detected ≠ configured ≠ connected ≠ verified
  • 测试通过 ≠ 「真实压缩通过」

看到「已连接」先别信,跑一次真实请求、看回执上的数字再说。

更底层的教训是:在 AI 工具链里做中间层,诚实比功能表重要。省多少、没省、为什么没省,全写在回执里。营销式的「平均省 X%」反而没人信——开发者只信能复现的数字。

结果

README 记录的数字是:单次真实路由请求物理减少 33,705 token(实测,2026-08-04)。

token 节省量信息图:本地 token 与服务商 token 对比,实测节省 33705
实测节省量:左侧为进入控制面的本地 token,右侧为实际发往服务商的 token,差值 33,705 有回执为证。

这不是「平均省 30%」的营销话术,而是一次可复现的实测点。回执里能看到 Local Token 与 Provider Token 的对比——省了多少,写在纸上,不靠感觉。但也别误读:这是单次实测点,不是平均值。你的会话省多少,取决于重复发送有多严重——日志膨胀型的重度用户收益最大,干净的小请求省不了几个。

权衡要讲清楚。压缩不是免费的:本地管线有延迟开销,摘要可能丢细节,去重依赖内容哈希的命中率。省 token 不能以丢正确性为代价——这也是路线图上「可信压缩」这个词的由来:压缩要是把关键上下文压没了,省下的钱全会变成 debug 时间。

当前 0.2.0-beta.1,公开未签名预发布(macOS ARM64 / Windows x64)。未签名构建可能触发系统安全警告——请核对仓库与哈希,不要绕过系统保护。

路线图上还有:

  • v0.3:跨 Agent Context Relay、Session Cache、cc-switch 跟随 / 锁定 / 观察
  • v0.4:多 Agent 适配、低风险自动修复、稳定签名

深度压缩、Headroom 类集成、完整签名分发,都还在路上。实验方向里还有两个有意思的:LeanCTX——跨 agent 的上下文复用,一个 agent 看过的东西另一个不用重喂;光学压缩——把上下文渲染成图片再压的路子,听着离谱,但思路是「模型读图有时比读长文本更省」。

git clone https://github.com/37chengshan/d-token.git
cd d-token/code/apps/desktop
npm ci
npm run tauri:dev

主仓库:37chengshan/d-token。

现在就能动手

五步,今晚就能跑:

  1. 克隆。
    git clone https://github.com/37chengshan/d-token.git
    cd d-token/code/apps/desktop
    npm ci
    npm run tauri:dev
  2. 配好你的 provider。 在界面里走安全配置流程:填服务商、模型、key。记住状态语义——detected ≠ configured ≠ connected ≠ verified,一步一步验,别跳步。
  3. 把 agent 的请求指过来。 让你的 AI 编程 agent 走 d-token 的本地端点发请求,d-token 再按显式路由转发。
  4. 跑一次真实请求,看回执。 别信界面上的「已连接」,去看回执:Local Token 多少,Provider Token 多少,差值就是这次省下的。这就是你的第一个可复现数字。
  5. 对账,调策略。 哪个会话最烧钱?去重命中率如何?日志折叠是不是太狠?按回执调压缩强度——省多少、为什么,都有数。

常见问题

d-token 到底是干嘛的?

它是面向 AI 编码 Agent 的本地上下文控制面,跑在”你正在用的 Agent”和”你配置的模型服务商”之间:在上下文离开本机之前压缩冗余,保持路由显式,并让配置变更可恢复。

它真能省 token 吗?省多少?

README 记录了一次实测:2026-08-04 单次真实路由请求物理减少 33,705 token。注意这是单次实测点,不是平均值;回执里能看到 Local Token 与 Provider Token 的对比,省了多少写在纸上,不靠感觉。

我的代码和密钥会被它上传吗?

不会。本地优先是硬原则:设置、诊断、请求元数据、回退记录都留在本机,普通日志不会主动保存完整 prompt、完整 response、源代码正文、API key。你选的服务商仍会收到你主动发出的请求,但中间多了一层你自己掌控的门。

配置改坏了怎么办?

配置变更不是”保存即生效”,而是走五步:预览 → 脱敏 Diff → 备份 → 验证 → 回退。出问题可以诊断、修复、恢复,作者管这叫”配置的医生”。

它适合我吗?

适合 token 烧得多的重度用户:多 agent 并行、长会话、日志膨胀型任务。不适合:偶尔问两句的小用量(省不了几个 token,还多一层延迟)。先测你最烧钱的那个会话,再决定全不全量上。

现在能用吗?

当前是 0.2.0-beta.1,公开未签名预发布(macOS ARM64 / Windows x64)。未签名构建可能触发系统安全警告,下载后请核对仓库与哈希,不要绕过系统保护。

本篇的 X 速览版

1/ 打开 AI 编程的账单,数字在涨,但说不清花在哪。同一批文件上一轮刚喂过,这一轮又原样重发——上下文像漏水的桶。d-token 让我的一次真实请求少送了 33,705 个 token,而且有回执为证。

2/ ① d-token 跑在你本机上,卡在”你的 Agent”和”模型服务商”之间。请求先过它:压缩冗余、走显式路由,再发出去。每请求留一张回执对账。

3/ ② 33,705 不是”平均省 30%“那种话术,是回执上 Local Token 和 Provider Token 的差值。省了多少写在纸上,不靠感觉。

4/ ③ 压缩管线四段:内容哈希去重、修剪日志与重复片段、长尾摘要、出境前脱敏。重复发送是最肥的一块肉,先干掉它。

5/ ④ 路由必须显式:每个请求走哪条路写得清清楚楚,绝不静默切换。路由变更要留痕,静默切换是账单刺客。

6/ ⑤ 配置变更走五步:预览 → 脱敏 Diff → 备份 → 验证 → 回退。给你的 AI 工具链也加个回退键,裸改配置早晚翻车。

7/ ⑥ 状态语义故意拆开:detected ≠ configured ≠ connected ≠ verified。看到”已连接”先别信,跑一次真实请求看回执。

8/ ⑦ 做中间件最大的教训:诚实比功能表重要。省多少、没省、为什么没省,全写在回执里。

9/ ⑧ 权衡:压缩不是免费的——本地管线有延迟,摘要可能丢细节。先测你最烧钱的那个会话,再决定全不全量上。

10/ ⑨ 实验方向:跨 agent 上下文复用(LeanCTX)、会话缓存,甚至把上下文渲染成图片再压的光学压缩。

11/ ⑩ 当前 0.2.0-beta.1,未签名预发布。核对仓库和哈希,别绕过系统保护——跑 beta 版先验哈希是基本素养。

12/ 三条硬原则:秘密不出本机、路由绝不静默切换、配置改坏了能回退。上下文离开本机之前,先过一遍你自己的门。完整版 👇 https://citygenius-blog.pages.dev/article/project-d-token