@nzkbuild/toche 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,367 +1,421 @@
1
- <p align="center">
2
- <img src="assets/branding/toche-wordmark.png" alt="Toche" width="620">
3
- </p>
4
-
5
- <p align="center">
6
- <strong>Claude Code repeats less, carries less noise, and leaves you a receipt.</strong>
7
- </p>
8
-
9
- <p align="center">
10
- Toche is a local gateway between Claude Code and your Anthropic API endpoint.
11
- It removes avoidable work while keeping every optimization visible and reversible.
12
- </p>
13
-
14
- <p align="center">
15
- <img src="assets/branding/toche-status.svg" alt="Toche 1.0.9: 65 filters, duplicate requests coalesced from many to one, zero hosted accounts, 354 Rust tests" width="820">
16
- </p>
17
-
18
- <p align="center">
19
- <a href="#why-toche">Why Toche</a> ·
20
- <a href="#what-changes">What changes</a> ·
21
- <a href="#install">Install</a> ·
22
- <a href="#how-it-works">How it works</a> ·
23
- <a href="#command-reference">Commands</a> ·
24
- <a href="#safety-and-control">Safety</a> ·
25
- <a href="#documentation">Docs</a>
26
- </p>
27
-
28
- ## Why Toche
29
-
30
- Claude Code sessions often pay for the same kind of waste more than once: an
31
- identical request is already running, a safe response was just fetched, or a tool
32
- prints thousands of tokens when the useful result is a few lines. Toche handles
33
- those cases before they consume another upstream call or more conversation space.
34
-
35
- The useful part is not a universal marketing percentage. Toche measures your
36
- actual traffic and reports what happened with `toche stats`.
37
-
38
- ## What changes
39
-
40
- - **Three identical requests at the same time can become one upstream call.** The
41
- first request runs while the other two wait for and share its response.
42
- - **An eligible local replay becomes zero new upstream calls.** Toche only replays
43
- workspace-matched, text-only responses that pass its safety checks.
44
- - **Sixty-five command filters remove known noise.** Cargo, Git, Terraform, Helm,
45
- Ansible, linters, and other supported output can be shortened while the original
46
- remains recoverable with `toche expand`.
47
- - **Every routed request leaves a local record.** Token counts, estimated cost,
48
- latency, cache decisions, coalescing, and reduction are written to a local SQLite
49
- ledger instead of a Toche cloud account.
50
-
51
- Here is a deliberately simple example. If a supported tool prints an estimated
52
- 10,000 tokens and its useful reduced form is 3,000, the ledger records 7,000 tokens
53
- removed, or 70%. That explains the measurement. It does not promise that every
54
- command, repository, or session will save 70%.
55
-
56
- Toche is most useful during long coding sessions, repeated test and diff cycles,
57
- parallel agent work, and projects where you want to inspect the cost of the work.
58
- A short conversation with no repetition or noisy tools may show little difference.
59
-
60
- ## Install
61
-
62
- ### Before you start
63
-
64
- You need:
65
-
66
- 1. Claude Code installed and already working.
67
- 2. Node.js 18 or newer for the npm installer.
68
- 3. Windows x64, Linux x64, macOS Intel, or macOS Apple silicon.
69
-
70
- Rust is not required when installing from npm.
71
-
72
- ### One-time setup
73
-
74
- 1. Install Toche globally. This makes the `toche` command available anywhere.
75
-
76
- ```shell
77
- npm install -g @nzkbuild/toche
78
- ```
79
-
80
- 2. Import your existing Claude Code endpoint into a local Toche profile.
81
-
82
- ```shell
83
- toche setup
84
- ```
85
-
86
- 3. Start Toche and leave this terminal open while using Claude Code.
87
-
88
- ```shell
89
- toche
90
- ```
91
-
92
- 4. Open a second terminal, connect Claude Code, and verify the setup.
93
-
94
- ```shell
95
- toche connect
96
- toche doctor
97
- ```
98
-
99
- 5. Start Claude Code normally.
100
-
101
- ```shell
102
- claude
103
- ```
104
-
105
- `toche connect` creates a backup before changing Claude Code's local routing.
106
-
107
- ### Normal daily use
108
-
109
- After the one-time setup, the routine is only:
110
-
111
- 1. Run `toche` and leave it open.
112
- 2. Run `claude` in another terminal.
113
-
114
- You do not need to run `setup` again. You also do not need to run `connect` again
115
- unless you previously used `toche disconnect`.
116
-
117
- ### Use these only when needed
118
-
119
- | Command | When to use it |
120
- |---|---|
121
- | `toche stats` | You want to see requests, tokens, estimated cost, and measured savings |
122
- | `toche doctor` | Something is not connecting or you want a health check |
123
- | `toche disconnect` | You want Claude Code to bypass Toche and use its original endpoint |
124
- | `toche setup --force` | You intentionally want to replace the current Toche profile; a backup is created |
125
-
126
- To uninstall cleanly, restore Claude Code's original route first:
127
-
128
- ```shell
129
- toche disconnect
130
- npm uninstall -g @nzkbuild/toche
131
- ```
132
-
133
- <details>
134
- <summary><strong>Build from source instead of npm</strong></summary>
135
-
136
- You need Rust 1.86 or newer.
137
-
138
- ```shell
139
- git clone https://github.com/nzkbuild/toche.git
140
- cd toche
141
- cargo build --release
142
- ```
143
-
144
- The binary is `target/release/toche` on Linux and macOS or
145
- `target\release\toche.exe` on Windows. Run that binary with the same numbered setup
146
- steps above.
147
-
148
- </details>
149
-
150
- ## How it works
151
-
152
- ```mermaid
153
- flowchart LR
154
- A[Claude Code] --> B[Toche on 127.0.0.1:8743]
155
- B --> C{Local pipeline}
156
- C --> D[Shield and safe cache]
157
- C --> E[Output reduction]
158
- C --> F[Efficiency and prompt cache]
159
- D --> G[Configured Anthropic API endpoint]
160
- E --> G
161
- F --> G
162
- G --> B
163
- B --> H[Local ledger and content store]
164
- B --> A
165
- ```
166
-
167
- In plain language, Claude Code sends its normal Anthropic Messages API request to
168
- Toche on `127.0.0.1:8743`. Toche then:
169
-
170
- 1. Gives the request a stable fingerprint.
171
- 2. Shares an already-running identical request or checks for an eligible local replay.
172
- 3. Shortens supported tool output and keeps the original locally recoverable.
173
- 4. Applies the selected efficiency and provider prompt-cache policy.
174
- 5. Forwards any remaining work to your configured Anthropic API endpoint.
175
- 6. Records the outcome locally so `toche stats` can explain it.
176
-
177
- The exact internal order is:
178
-
179
- ```text
180
- fingerprint -> shield -> safe cache -> reduce -> efficiency -> cache -> forward -> ledger
181
- ```
182
-
183
- Toche fingerprints the canonical request, checks whether work can be safely shared
184
- or replayed, reduces known tool-output noise, applies the selected efficiency and
185
- prompt-cache policy, forwards the resulting request upstream, then records the
186
- outcome locally.
187
-
188
- For the module map, database schema, cache rules, and content-addressed storage
189
- layout, see [the architecture guide](docs/ARCHITECTURE.md).
190
-
191
- ## Safety and control
192
-
193
- - The gateway binds to `127.0.0.1:8743` by default.
194
- - Toche configuration, its ledger, cache metadata, checkpoints, and stored content live locally.
195
- - Requests that require upstream work still go to the Anthropic API endpoint configured in your profile.
196
- - Persistent replay is limited to eligible responses. Responses containing `tool_use` blocks are rejected.
197
- - `toche doctor` reports configuration and integration health.
198
- - Every optimization stage has an explicit bypass header.
199
- - `toche expand <hash>` restores original tool output after reduction.
200
- - Cache entries can be inspected, explained, and cleared.
201
- - `toche disconnect` restores direct Claude Code routing.
202
-
203
- These controls make Toche inspectable and reversible. They are not a promise that
204
- every request will be cheaper or that an optimization can never affect model behavior.
205
-
206
- ## Command reference
207
-
208
- <details>
209
- <summary><strong>Gateway, setup, and diagnostics</strong></summary>
210
-
211
- | Command | What it does |
212
- |---|---|
213
- | `toche` | Start the gateway on `127.0.0.1:8743` |
214
- | `toche setup` | Generate `profiles.toml` from Claude Code configuration |
215
- | `toche setup --force` | Regenerate the profile and back up the existing file |
216
- | `toche connect` | Route Claude Code through Toche |
217
- | `toche disconnect` | Restore direct upstream routing |
218
- | `toche doctor` | Show configuration and integration health |
219
- | `toche status` | Show gateway status |
220
-
221
- </details>
222
-
223
- <details>
224
- <summary><strong>Usage, reduction, and persistent cache</strong></summary>
225
-
226
- | Command | What it does |
227
- |---|---|
228
- | `toche stats` | Show a human-readable usage and cost breakdown |
229
- | `toche stats --json` | Print machine-readable statistics |
230
- | `toche stats --entries 100` | Include the last 100 ledger entries |
231
- | `toche expand <hash>` | Restore original tool output from a reduction hash |
232
- | `toche cache inspect` | List persistent safe-cache entries |
233
- | `toche cache clear` | Clear entries for the current project |
234
- | `toche cache clear --all` | Clear all persistent cache entries |
235
- | `toche cache why <fingerprint>` | Explain the cache decision for a fingerprint |
236
-
237
- </details>
238
-
239
- <details>
240
- <summary><strong>Continuity and project graph</strong></summary>
241
-
242
- | Command | What it does |
243
- |---|---|
244
- | `toche checkpoint save` | Save a session checkpoint |
245
- | `toche checkpoint list` | List saved checkpoints |
246
- | `toche checkpoint show` | Show the latest checkpoint |
247
- | `toche checkpoint delete <id>` | Delete a checkpoint |
248
- | `toche graph query <question>` | Query the optional knowledge graph |
249
- | `toche graph status` | Show graph node and edge counts |
250
- | `toche graph extract` | Rebuild the knowledge graph |
251
-
252
- </details>
253
-
254
- ### Per-request bypasses
255
-
256
- Set a header to `true`, case-insensitively, to skip a stage for one request.
257
- The umbrella bypass takes precedence over individual bypasses.
258
-
259
- | Header | Skips |
260
- |---|---|
261
- | `x-toche-bypass` | The complete optimization pipeline |
262
- | `x-toche-bypass-shield` | Request coalescing |
263
- | `x-toche-bypass-safe-cache` | Persistent cache lookup and storage |
264
- | `x-toche-bypass-reduce` | Tool-output reduction |
265
- | `x-toche-bypass-efficiency` | Efficiency instruction injection |
266
- | `x-toche-bypass-cache` | Provider prompt-cache injection |
267
-
268
- ## Configuration
269
-
270
- Profiles live in `~/.toche/profiles.toml`. Running `toche setup` generates a
271
- profile from your existing Claude Code configuration.
272
-
273
- <details>
274
- <summary><strong>Example profile</strong></summary>
275
-
276
- ```toml
277
- default = "default"
278
-
279
- [[profiles]]
280
- name = "default"
281
- upstream_url = "https://api.anthropic.com"
282
- auth_method = { type = "api_key", header_name = "x-api-key", key = "YOUR_ANTHROPIC_API_KEY" }
283
-
284
- [profiles.cache]
285
- enabled = true
286
- mode = "auto"
287
- breakpoint = "standard"
288
-
289
- [profiles.reduce]
290
- enabled = true
291
-
292
- [profiles.efficiency]
293
- mode = "concise"
294
-
295
- [profiles.safe_cache]
296
- enabled = true
297
- ttl_days = 30
298
- max_entry_bytes = 1048576
299
-
300
- [profiles.graphify]
301
- enabled = false
302
- ```
303
-
304
- </details>
305
-
306
- Set `TOCHE_CONFIG_DIR` to override the default `~/.toche/` directory.
307
-
308
- ## Troubleshooting
309
-
310
- <details>
311
- <summary><strong>The gateway will not start</strong></summary>
312
-
313
- - Check that nothing else is listening on port 8743.
314
- - Run `toche doctor` to verify that `profiles.toml` exists and is valid.
315
- - Enable debug logging with `RUST_LOG=toche=debug toche`.
316
-
317
- </details>
318
-
319
- <details>
320
- <summary><strong>Claude Code cannot connect</strong></summary>
321
-
322
- - Start the gateway before running `toche connect`.
323
- - Run `toche doctor` in a second terminal after connecting.
324
-
325
- </details>
326
-
327
- <details>
328
- <summary><strong>Stats or cache entries are empty</strong></summary>
329
-
330
- - The ledger records only requests routed through the gateway.
331
- - The persistent cache stores only eligible text-only responses without `tool_use` blocks.
332
- - Use `toche cache why <fingerprint>` to inspect a cache rejection.
333
-
334
- </details>
335
-
336
- <details>
337
- <summary><strong>Routing still points to Toche after disconnecting</strong></summary>
338
-
339
- Run `toche doctor`. If `env.ANTHROPIC_BASE_URL` still points to Toche while the
340
- gateway is stopped, inspect `~/.claude/settings.json` and its Toche backup.
341
-
342
- </details>
343
-
344
- ## Requirements
345
-
346
- - Rust 1.86 or newer, edition 2024
347
- - Claude Code or another Anthropic Messages API client
348
- - No hosted Toche service
349
- - SQLite is bundled through `rusqlite`
350
-
351
- ## Documentation
352
-
353
- - [Architecture](docs/ARCHITECTURE.md): pipeline, modules, databases, and storage
354
- - [Changelog](CHANGELOG.md): release history from 0.1.0 through 1.0.9
355
- - [Bug tracker](docs/BUG_TRACKER.md): issues found and fixed during dogfooding
356
- - [npm publishing](docs/NPM_PUBLISHING.md): maintainer checklist for the first npm release
357
- - [Third-party notices](THIRD_PARTY_NOTICES.md): reused ideas, integration decisions, and attribution
358
-
359
- ## Built from good work
360
-
361
- Toche's Rust implementation was informed by ideas and patterns from ccusage, RTK,
362
- Graphify, andrej-karpathy-skills, and caveman-claude. Their licenses and attribution
363
- are preserved in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
364
-
365
- ## License
366
-
367
- Licensed under the [Apache License 2.0](LICENSE).
1
+ <p align="center">
2
+ <img src="assets/branding/toche-wordmark.png" alt="Toche" width="620">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <strong>One local runtime. Multiple AI clients. Every request leaves a receipt.</strong>
7
+ </p>
8
+
9
+ <p align="center">
10
+ Toche is a local multi-client gateway that sits between your AI coding tools and
11
+ their upstream API endpoints. It removes avoidable work, isolates trust boundaries,
12
+ and keeps every optimization visible and reversible.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <img src="assets/branding/toche-status.svg" alt="Toche 1.1.0: Multi-client runtime, Claude Code and Codex, 65 filters, duplicate requests coalesced from many to one, zero hosted accounts" width="820">
17
+ </p>
18
+
19
+ <p align="center">
20
+ <a href="#what-toche-is">What Toche is</a> ·
21
+ <a href="#what-toche-is-not">What it is not</a> ·
22
+ <a href="#install">Install</a> ·
23
+ <a href="#how-it-works">How it works</a> ·
24
+ <a href="#supported-clients">Supported clients</a> ·
25
+ <a href="#command-reference">Commands</a> ·
26
+ <a href="#trust-and-isolation">Trust and isolation</a> ·
27
+ <a href="#documentation">Docs</a>
28
+ </p>
29
+
30
+ ## What Toche is
31
+
32
+ Toche is a local runtime that accepts connections from multiple AI coding clients
33
+ simultaneously and routes their requests to your configured upstream API endpoints.
34
+ While a request passes through, Toche can:
35
+
36
+ - **Coalesce identical in-flight requests** so N clients sharing the same upstream
37
+ and trust domain make one upstream call instead of N.
38
+ - **Replay eligible responses** from a persistent cross-session cache when the
39
+ workspace fingerprint matches.
40
+ - **Reduce known tool-output noise** with 65 built-in TOML-defined filters
41
+ while keeping the original content recoverable with `toche expand`.
42
+ - **Inject provider prompt-cache breakpoints** to maximize Anthropic cache hits.
43
+ - **Record every request** in a local SQLite ledger so `toche stats` can explain
44
+ what happened.
45
+
46
+ Toche does not host an account, send telemetry, or require a cloud service.
47
+
48
+ ## What Toche is not
49
+
50
+ Toche is not a provider account manager, a model load balancer, a protocol
51
+ translator, or a hosted API gateway. It does not select providers automatically
52
+ or fall back between them. It does not translate between Anthropic and OpenAI
53
+ protocols. These are explicit non-goals for the 1.1.0 release.
54
+
55
+ ## Install
56
+
57
+ ### Prerequisites
58
+
59
+ - Node.js 18 or newer for the npm installer.
60
+ - At least one supported AI coding client already installed and working.
61
+ - Windows x64, Linux x64, macOS Intel, or macOS Apple silicon.
62
+
63
+ Rust is not required when installing from npm.
64
+
65
+ ### One-time setup
66
+
67
+ ```shell
68
+ npm install -g @nzkbuild/toche
69
+ toche setup
70
+ toche
71
+ ```
72
+
73
+ Then, in other terminals, run your clients normally:
74
+
75
+ ```shell
76
+ claude
77
+ codex
78
+ ```
79
+
80
+ `toche setup` detects your existing client configurations, imports your current
81
+ upstreams, and writes a local `config.toml`. It never silently sends a paid model
82
+ request. You can run it again later to review or modify your configuration.
83
+
84
+ ### Managed mode (optional convenience)
85
+
86
+ Instead of starting the runtime separately, you can launch a client through Toche
87
+ in one step:
88
+
89
+ ```shell
90
+ toche run claude -- --dangerously-skip-permissions
91
+ toche run codex
92
+ ```
93
+
94
+ Managed mode uses the same runtime, configuration, protocol handling, trust
95
+ isolation, ledger, and optimization pipeline as persistent mode.
96
+
97
+ ### Normal daily use
98
+
99
+ After setup, the routine is:
100
+
101
+ 1. Run `toche` and leave it open.
102
+ 2. Run your clients in other terminals.
103
+
104
+ ### Clean uninstall
105
+
106
+ ```shell
107
+ toche disconnect claude
108
+ toche disconnect codex
109
+ npm uninstall -g @nzkbuild/toche
110
+ ```
111
+
112
+ <details>
113
+ <summary><strong>Build from source instead of npm</strong></summary>
114
+
115
+ You need Rust 1.86 or newer.
116
+
117
+ ```shell
118
+ git clone https://github.com/nzkbuild/toche.git
119
+ cd toche
120
+ cargo build --release
121
+ ```
122
+
123
+ The binary is `target/release/toche` (`.exe` on Windows).
124
+
125
+ </details>
126
+
127
+ ## How it works
128
+
129
+ ```mermaid
130
+ flowchart LR
131
+ subgraph Clients
132
+ A[Claude Code]
133
+ B[Codex CLI]
134
+ end
135
+ A --> C[Toche on 127.0.0.1:8743]
136
+ B --> C
137
+ C --> D{Protocol router}
138
+ D --> E[Anthropic Messages pipeline]
139
+ D --> F[OpenAI Responses pipeline]
140
+ E --> G[Shield coalescing]
141
+ F --> G
142
+ G --> H[Safe cache]
143
+ H --> I[Output reduction]
144
+ I --> J[Efficiency injection]
145
+ J --> K[Prompt cache injection]
146
+ K --> L[Configured upstream APIs]
147
+ L --> C
148
+ C --> M[Local ledger and CAS]
149
+ C --> A
150
+ C --> B
151
+ ```
152
+
153
+ In plain language, your AI clients send their normal API requests to Toche on
154
+ `127.0.0.1:8743`. Toche then:
155
+
156
+ 1. Routes the request through the correct protocol driver (Anthropic Messages
157
+ or OpenAI Responses).
158
+ 2. Gives the request a stable fingerprint.
159
+ 3. Shares an already-running identical request (within the same trust domain)
160
+ or checks for an eligible local replay.
161
+ 4. Shortens supported tool output and keeps the original locally recoverable.
162
+ 5. Applies the selected efficiency and provider prompt-cache policy.
163
+ 6. Forwards any remaining work to your configured upstream API endpoint.
164
+ 7. Records the outcome locally so `toche stats` can explain it.
165
+
166
+ The internal pipeline order is:
167
+
168
+ ```text
169
+ protocol dispatch → fingerprint → shield → safe cache → reduce → efficiency → cache → forward → ledger
170
+ ```
171
+
172
+ ## Supported clients
173
+
174
+ | Client | Protocol | Persistent mode | Managed mode | Setup |
175
+ |--------|----------|-----------------|--------------|-------|
176
+ | Claude Code | Anthropic Messages | `toche` + `claude` | `toche run claude` | `toche setup` |
177
+ | Codex CLI | OpenAI Responses | `toche` + `codex` | `toche run codex` | `toche setup` |
178
+
179
+ Multiple instances of the same client are supported. Claude Code and Codex can
180
+ run simultaneously through the same Toche runtime.
181
+
182
+ ### Persistent vs. managed mode
183
+
184
+ **Persistent mode** (`toche` in one terminal, client in another) is the primary
185
+ workflow. Start Toche once and launch as many clients as you need.
186
+
187
+ **Managed mode** (`toche run <client>`) is a convenience that starts Toche and
188
+ the client together. It uses the exact same pipeline as persistent mode.
189
+
190
+ ## Trust and isolation
191
+
192
+ Different credential references never share cache entries or in-flight request
193
+ coalescing. If you configure a personal Anthropic API key and a work OpenAI key,
194
+ their traffic is isolated by trust domain even if they happen to target the
195
+ same upstream URL.
196
+
197
+ Trust domains are derived from the combination of integration identity, upstream
198
+ identity, and credential reference. Raw credential values are never placed in
199
+ logs, IDs, hashes, database diagnostics, or receipts.
200
+
201
+ Attribution confidence is recorded honestly: Toche distinguishes between exact
202
+ process identity, client-reported identity, workspace-level identity, inference,
203
+ and unknown identity. It does not fabricate identity where it cannot be observed.
204
+
205
+ ## Data storage
206
+
207
+ Everything lives in `~/.toche/` (overridable with `TOCHE_CONFIG_DIR`):
208
+
209
+ | Path | Purpose |
210
+ |------|---------|
211
+ | `config.toml` | Runtime configuration, integrations, upstreams, policies |
212
+ | `ledger.db` | SQLite ledger of every routed request |
213
+ | `cas/` | Content-addressed storage for reduced originals and cached responses |
214
+ | `runtime_id` | Persistent UUIDv7 runtime identity |
215
+
216
+ Toche never sends your data to a cloud account.
217
+
218
+ ## Measurement confidence
219
+
220
+ Every value reported by `toche stats` is classified by how it was obtained:
221
+
222
+ | Confidence | Meaning |
223
+ |------------|---------|
224
+ | `measured` | Toche observed it directly |
225
+ | `provider-reported` | The upstream API reported it |
226
+ | `estimated` | Derived from available data (e.g. list-price estimate) |
227
+ | `configured` | Comes from your configuration |
228
+ | `unknown` | Could not be determined |
229
+
230
+ Missing prices do not become zero. Missing usage does not become fabricated
231
+ usage. Cost estimates are labelled as equivalent public list-price estimates,
232
+ not your actual billed cost.
233
+
234
+ ## Command reference
235
+
236
+ ### Primary commands
237
+
238
+ | Command | What it does |
239
+ |---------|-------------|
240
+ | `toche` | Start the runtime on `127.0.0.1:8743` |
241
+ | `toche setup` | Guided, rerunnable configuration |
242
+ | `toche setup --dry-run` | Preview changes without writing |
243
+ | `toche setup --force` | Regenerate configuration (backup created) |
244
+ | `toche connect [client]` | Route a client through Toche |
245
+ | `toche disconnect [client]` | Restore direct upstream routing |
246
+ | `toche run <client>` | Run a client in managed mode |
247
+ | `toche doctor` | Verify installation and configuration |
248
+ | `toche status` | Show runtime status, active flights, protocol counts |
249
+ | `toche status --json` | Machine-readable status |
250
+ | `toche stats` | Show usage, tokens, and cost estimates |
251
+ | `toche stats --json` | Machine-readable statistics |
252
+ | `toche stats --protocol anthropic` | Filter by protocol |
253
+ | `toche stats --integration <name>` | Filter by integration |
254
+ | `toche expand <hash>` | Restore original tool output from a reduction hash |
255
+
256
+ ### Advanced commands
257
+
258
+ | Command | What it does |
259
+ |---------|-------------|
260
+ | `toche cache inspect` | List persistent safe-cache entries |
261
+ | `toche cache clear` | Clear entries for the current project |
262
+ | `toche cache clear --all` | Clear all persistent cache entries |
263
+ | `toche cache why <fingerprint>` | Explain the cache decision for a fingerprint |
264
+ | `toche checkpoint save` | Save a session checkpoint |
265
+ | `toche checkpoint list` | List saved checkpoints |
266
+ | `toche checkpoint show` | Show the latest checkpoint |
267
+ | `toche checkpoint delete <id>` | Delete a checkpoint |
268
+ | `toche graph query <question>` | Query the optional knowledge graph |
269
+ | `toche graph status` | Show graph node and edge counts |
270
+ | `toche graph extract` | Rebuild the knowledge graph |
271
+
272
+ ### Per-request bypass headers
273
+
274
+ Set a header to `true` (case-insensitive) to skip a stage for one request.
275
+ The umbrella bypass takes precedence over individual bypasses.
276
+
277
+ | Header | Skips |
278
+ |--------|-------|
279
+ | `x-toche-bypass` | The complete optimization pipeline |
280
+ | `x-toche-bypass-shield` | Request coalescing |
281
+ | `x-toche-bypass-safe-cache` | Persistent cache lookup and storage |
282
+ | `x-toche-bypass-reduce` | Tool-output reduction |
283
+ | `x-toche-bypass-efficiency` | Efficiency instruction injection |
284
+ | `x-toche-bypass-cache` | Provider prompt-cache injection |
285
+
286
+ ## Configuration
287
+
288
+ Toche stores its configuration in `~/.toche/config.toml`. Running `toche setup`
289
+ generates it from your existing client configurations.
290
+
291
+ <details>
292
+ <summary><strong>Example config.toml</strong></summary>
293
+
294
+ ```toml
295
+ schema_version = 2
296
+
297
+ [runtime]
298
+ port = 8743
299
+ listen_address = "127.0.0.1"
300
+ request_timeout_ms = 300000
301
+
302
+ [defaults]
303
+ integration = "abc12345"
304
+
305
+ [[integrations]]
306
+ id = "abc12345"
307
+ name = "default"
308
+ upstream = "def67890"
309
+ policy = "pol11111"
310
+
311
+ [[upstreams]]
312
+ id = "def67890"
313
+ name = "Anthropic"
314
+ url = "https://api.anthropic.com"
315
+
316
+ [upstreams.auth]
317
+ secret_ref = { type = "environment", key = "ANTHROPIC_API_KEY" }
318
+ header_name = "x-api-key"
319
+
320
+ [upstreams.headers]
321
+ anthropic-version = "2023-06-01"
322
+
323
+ [[policies]]
324
+ id = "pol11111"
325
+ name = "default"
326
+
327
+ [policies.cache]
328
+ enabled = true
329
+ mode = "auto"
330
+ breakpoint = "standard"
331
+
332
+ [policies.reduce]
333
+ enabled = true
334
+
335
+ [policies.efficiency]
336
+ mode = "concise"
337
+
338
+ [policies.safe_cache]
339
+ enabled = true
340
+ ttl_days = 30
341
+ max_entry_bytes = 1048576
342
+ ```
343
+
344
+ </details>
345
+
346
+ ## Troubleshooting
347
+
348
+ <details>
349
+ <summary><strong>The runtime will not start</strong></summary>
350
+
351
+ - Check that nothing else is listening on port 8743.
352
+ - Run `toche doctor` to verify that `config.toml` exists and is valid.
353
+ - Enable debug logging with `RUST_LOG=toche=debug toche`.
354
+
355
+ </details>
356
+
357
+ <details>
358
+ <summary><strong>A client cannot connect</strong></summary>
359
+
360
+ - Start the runtime before running `toche connect`.
361
+ - Run `toche doctor` in a second terminal after connecting.
362
+ - Check that `toche status` shows the expected integrations.
363
+
364
+ </details>
365
+
366
+ <details>
367
+ <summary><strong>Stats or cache entries are empty</strong></summary>
368
+
369
+ - The ledger records only requests routed through the runtime.
370
+ - The persistent cache stores only eligible text-only responses without `tool_use` blocks.
371
+ - Use `toche cache why <fingerprint>` to inspect a cache rejection.
372
+
373
+ </details>
374
+
375
+ <details>
376
+ <summary><strong>Routing still points to Toche after disconnecting</strong></summary>
377
+
378
+ Run `toche doctor`. If environment variables or settings still reference Toche
379
+ while the runtime is stopped, run `toche disconnect` for each affected client.
380
+
381
+ </details>
382
+
383
+ ## Upgrading from 1.0.x
384
+
385
+ Toche 1.1.0 migrates your existing `profiles.toml` to the new `config.toml`
386
+ format automatically on first load. The migration:
387
+
388
+ - Converts each profile into separate Integration, Upstream, and Policy entries.
389
+ - Backs up `profiles.toml` to `profiles.toml.v1.bak`.
390
+ - Preserves your ledger, safe-cache metadata, CAS, checkpoints, and Graphify data.
391
+ - Is idempotent — running it again is a no-op.
392
+ - Fails safely on malformed configuration without modifying anything.
393
+
394
+ An older binary encountering a newer schema version will refuse to modify it.
395
+
396
+ ## Requirements
397
+
398
+ - Rust 1.86 or newer (edition 2024) when building from source
399
+ - At least one supported AI coding client
400
+ - No hosted Toche service
401
+ - SQLite is bundled through `rusqlite`
402
+
403
+ ## Documentation
404
+
405
+ - [Architecture](docs/ARCHITECTURE.md): system design, crate map, data flow, decision records
406
+ - [Changelog](CHANGELOG.md): release history from 1.0.0 through 1.1.0
407
+ - [Contributing](CONTRIBUTING.md): setup, conventions, and PR workflow
408
+ - [Code of Conduct](CODE_OF_CONDUCT.md): Contributor Covenant
409
+ - [Bug tracker](docs/BUG_TRACKER.md): issues found and fixed during dogfooding
410
+ - [npm publishing](docs/NPM_PUBLISHING.md): maintainer checklist for npm releases
411
+ - [Third-party notices](THIRD_PARTY_NOTICES.md): reused ideas, integration decisions, and attribution
412
+
413
+ ## Built from good work
414
+
415
+ Toche's Rust implementation was informed by ideas and patterns from ccusage, RTK,
416
+ Graphify, andrej-karpathy-skills, and caveman-claude. Their licenses and attribution
417
+ are preserved in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
418
+
419
+ ## License
420
+
421
+ Licensed under the [Apache License 2.0](LICENSE).