token-harness 0.1.5 → 0.1.7

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.
Files changed (4) hide show
  1. package/README.md +155 -579
  2. package/package.json +2 -2
  3. package/sbom.json +4 -4
  4. package/token-harness.mjs +10617 -5665
package/README.md CHANGED
@@ -1,678 +1,259 @@
1
1
  # Token Harness
2
2
 
3
- Token Harness has one objective: **maximize the useful coding work you can get from Claude Code
4
- and Codex usage limits, without hiding quality regressions or pretending that opaque subscription
5
- quota is exactly equivalent to a token count**.
3
+ **Make Claude Code and Codex easier to understand and use efficiently.**
6
4
 
7
- The scarce resource is no longer just model context. Subscription users are constrained by rolling
8
- usage windows, weekly limits, model-dependent burn, long-session context growth, MCP/tool schema
9
- overhead, noisy tool output, and repeated work after poor model or effort choices. Token Harness is
10
- evolving from a token-reduction control plane into a **quota-aware efficiency layer** for coding
11
- harnesses.
5
+ Token Harness checks your coding agents, shows subscription allowance when it can be
6
+ observed reliably, reduces avoidable context overhead, and recommends one useful next
7
+ action. It runs locally and never presents local token estimates as subscription quota.
12
8
 
13
- The product therefore optimizes two related budgets:
9
+ ## The easy path
14
10
 
15
- 1. **subscription headroom** — observe the usage windows the harness itself exposes, pace work
16
- against reset time, and choose native model/effort settings that fit the task and remaining
17
- budget;
18
- 2. **context sent to the model** — keep instructions, MCP schemas, conversation history, repository
19
- context, and tool output as small as possible without removing information needed to finish the
20
- task correctly.
11
+ You need [Node.js 22.13 or newer](https://nodejs.org/) and at least one signed-in coding
12
+ agent: Claude Code or Codex.
21
13
 
22
- RTK and HarnessTrim remain useful providers, but reducers are now one layer of the system rather
23
- than the product definition. Native harness controls come first because choosing the right model,
24
- effort, context shape, and enabled tools can avoid an expensive turn entirely.
25
-
26
- ## What Token Harness should optimize
27
-
28
- | Layer | Target behavior |
29
- | --- | --- |
30
- | Usage-window observability | Read five-hour, weekly, model-specific, or credit-backed limits only from surfaces the harness can actually prove; show reset time, headroom, and burn rate |
31
- | Native model policy | Prefer economical models/effort for routine work, escalate only for tasks whose expected quality benefit justifies the extra quota |
32
- | Session hygiene | Detect task boundaries, oversized conversations, and stale context; recommend clear/compact/new-session actions before history dominates each turn |
33
- | Instruction budget | Keep `CLAUDE.md` / `AGENTS.md` concise and hierarchical instead of injecting one large global instruction file everywhere |
34
- | MCP/tool budget | Disable irrelevant MCP servers, defer schemas where the harness supports it, and expose only the tools required by the current task |
35
- | Tool-output budget | Reduce logs, diffs, test output, and repeated command results before they re-enter model context |
36
- | Cross-harness scheduling | When Claude Code and Codex have independent headroom, recommend the harness that can do the task with the best expected quality per remaining quota |
37
- | Measurement | Correlate quota delta, model/effort, context size, tool traffic, and task outcome; never convert local token savings into an unproven subscription-quota claim |
38
-
39
- ## Optimization ecosystem
40
-
41
- The priority order below is deliberately different from the original Token Harness roadmap. A tool
42
- is high priority only when it helps **included Claude Code/Codex capacity**, not merely API cost,
43
- provider routing, or benchmark token counts.
44
-
45
- | Tool or surface | Optimization layer | Token Harness direction |
46
- | --- | --- | --- |
47
- | **Claude Code native controls** | Usage status, model/effort choice, context inspection, clear/compact lifecycle | **P0 — build into core**. Prefer native surfaces over third-party credential scraping; discover available models dynamically |
48
- | **Codex native app-server + profiles** | Structured rate-limit telemetry; model, reasoning effort, verbosity, tool-output and MCP/context controls | **P0 — build into core**. `account/rateLimits/read` is the preferred live quota source when available |
49
- | [cclimits](https://github.com/cruzanstx/cclimits) | Live/local quota companion across coding tools | **P0 — optional observational companion for Claude**. Token Harness uses only cacheless Claude JSON mode, never reads its credentials, and labels the result `reported` or `cached`. Codex keeps its native app-server reader |
50
- | [ccusage](https://github.com/ccusage/ccusage) | Local historical token/session/cost analytics for Claude Code and Codex | **P0 — high-priority read-only companion**. Useful for history and baselines; not a substitute for live subscription-limit telemetry |
51
- | [RTK](https://github.com/rtk-ai/rtk) | Shell-command rewriting and command-output reduction | **P1 — active, keep**. Reduces context that would otherwise be resent on later turns |
52
- | [HarnessTrim](https://github.com/giuliastro/HarnessTrim) | Deterministic reducers, harness adapters, skills, pipes, and MCP reduction | **P1 — active, keep**. Continue only on proven non-overlapping surfaces |
53
- | [Lazy MCP](https://gitlab.com/gitlab-org/ai/lazy-mcp) | Load MCP tool schemas only when needed | **P1 — high priority**. Directly attacks schema/context overhead; benchmark against native Codex tool deferral before installing another owner |
54
- | [Context Mode](https://github.com/mksglu/context-mode) | Keep raw tool/MCP results outside model context | **P2 — alternative broad context owner**. Evaluate against Headroom, not alongside overlapping reducers by default |
55
- | [Headroom](https://github.com/headroomlabs-ai/headroom) | Compress tool, MCP, file, and RAG payloads | **P2 — alternative broad context owner**. Admit only after pair-specific quality and attribution fixtures |
56
- | [Dejavu](https://github.com/Salnika/dejavu) | Emit only the delta when command output repeats | **P2 — useful for test/rerun loops** after the normal output-reduction path is measured |
57
- | [repowise](https://github.com/repowise-dev/repowise) | Retrieve task-specific repository context | **P2 — conditional**. Its MCP overhead must be lower than the repository context it avoids |
58
- | LiteLLM, Claude Code Router, RouteLLM, LLMRouter, vLLM Semantic Router | Route requests across models/providers | **P3 — overflow/API routing only**. Useful after included quota is exhausted or for explicit external-provider policy; not a core subscription-quota optimizer |
59
- | [LLMLingua](https://github.com/microsoft/LLMLingua) | Generic prompt compression | **Research only** until a harness-aware lifecycle proves must-keep recall and quality |
60
- | [Caveman](https://github.com/JuliusBrussee/caveman) | Reduce visible model-output verbosity | **De-prioritized**. Use native verbosity/effort controls first and measure their effect before adding another instruction owner |
61
-
62
- Candidate status still means that Token Harness neither installs nor configures the tool until its
63
- installation, conflicts, rollback behavior, verification, quality gates, and metrics attribution are
64
- implemented and tested. The intake evidence lives in
65
- [docs/provider-landscape.md](docs/provider-landscape.md).
66
-
67
- ### Why generic routers moved down
68
-
69
- The original roadmap treated model routers as high priority. For the new objective that is backwards:
70
- a router can reduce API cost by sending work to another provider while consuming **none of the
71
- included Claude Code or Codex allowance**, or it can bypass subscription authentication entirely.
72
- That can be valuable as explicit overflow, but it does not demonstrate better use of the allowance
73
- the user already paid for.
74
-
75
- Token Harness should first exploit the harness-native choices that are actually inside the plan:
76
- model tier, reasoning effort, verbosity, session lifecycle, instruction size, MCP exposure, and tool
77
- output. External routing becomes an opt-in second budget, never an invisible shortcut.
78
-
79
- ## Quick start
80
-
81
- Install the CLI:
14
+ Open a terminal and paste:
82
15
 
83
16
  ```sh
84
- npm install --global token-harness
85
- token-harness --version
17
+ npm install --global token-harness@latest
18
+ token-harness setup
86
19
  ```
87
20
 
88
- Then run the complete workflow from the project in which you use your coding agent:
89
-
90
- ```sh
91
- # 1. Inspect the machine. This does not change agent configuration.
92
- token-harness doctor
93
-
94
- # 2. Inspect subscription headroom and avoidable context. Still read-only.
95
- token-harness budget
96
- token-harness context
97
- token-harness history --since 7d
98
- token-harness optimize
99
-
100
- # Optional: Claude live quota can use an already-installed cclimits build that
101
- # supports --no-cache-write. Token Harness never installs it automatically.
21
+ That is the whole first-time check. `setup` tells you:
102
22
 
103
- # 3. Preview every proposed configuration change.
104
- token-harness plan
23
+ - which coding agents it found;
24
+ - whether an optimization provider is active;
25
+ - whether the current setup works;
26
+ - what it changed, if anything;
27
+ - exactly one next step.
105
28
 
106
- # 4. Apply the reviewed plan. This is the first configuration-changing step.
107
- token-harness apply --yes
108
-
109
- # 5. Restart the coding agent, then run a normal shell command through it.
110
-
111
- # 6. Check configuration, real interception evidence, and savings.
112
- token-harness status
113
- token-harness verify
114
- token-harness metrics --since 7d
115
- ```
116
-
117
- `doctor` ends with a `NEXT` section. If you are unsure what to do, run the command shown
118
- there.
119
-
120
- To try the read-only diagnosis without installing Token Harness globally:
29
+ The first run does not change Claude Code, Codex, or project configuration. If Token
30
+ Harness finds a supported improvement, it shows the safe plan and may suggest:
121
31
 
122
32
  ```sh
123
- npx token-harness doctor
33
+ token-harness setup --yes
124
34
  ```
125
35
 
126
- `npx` may download Token Harness into npm's cache, but it does not install or configure RTK,
127
- HarnessTrim, or a coding agent.
128
-
129
- ### Managed compatibility rows
130
-
131
- Token Harness changes a harness configuration only when a reviewed compatibility row covers the
132
- exact provider version, harness version, platform, and configuration schema. Three rows ship, and each
133
- names the recording it stands on:
134
-
135
- | Provider | Harness | Platform | Tested versions | Tier |
136
- | --- | --- | --- | --- | --- |
137
- | RTK | Claude Code | Windows | rtk 0.44.0, Claude Code 2.1.220 | `canary` |
138
- | HarnessTrim | Claude Code | Windows | harnesstrim 0.1.0, Claude Code 2.1.220 | `config-only` |
139
- | HarnessTrim | Codex | Windows | harnesstrim 0.1.0, Codex 0.146.0 | `config-only` |
140
-
141
- Everything else is refused, and that is the design rather than a gap: `doctor` detects and reports on
142
- every supported platform, and only the *mutation* is narrower. An uncovered combination exits 9 and
143
- the diagnostic names what is missing — the reviewed fixture, or the nearest row it does have.
144
-
145
- A live Linux check on 2026-09-02 with Codex 0.152.1 confirmed that boundary: the current row covers
146
- Codex 0.146.0 on Windows only, so `plan` and `apply --yes` refused with exit 9 and wrote nothing.
147
- That combination can still be observed and benchmarked with a provider installed through its own
148
- installer; it is not promoted to managed mutation until a real compatibility fixture is recorded.
149
-
150
- What is not covered today, and why:
151
-
152
- - **macOS and Linux.** No row on either. The recordings a row needs are states of a real machine, and
153
- a fixture cannot be written from a machine nobody ran. On those platforms `plan` and `apply` refuse;
154
- install the provider with its own installer and Token Harness will detect, verify, and measure it.
155
- - **OpenCode, and permanently rather than pending.** Both providers are detected, adopted, verified
156
- and measured there, and neither is written. RTK reaches OpenCode through a plugin module its own
157
- installer places globally, which this build has no action for. HarnessTrim's OpenCode installer
158
- writes a plugin wrapper *and runs an npm install*, so a containment boundary covering what it wrote
159
- would hold a `node_modules` tree — and that is not a decision deferred for want of a fixture. A
160
- dependency tree is not configuration, so it cannot be a reviewed write set; snapshotting it on
161
- every apply to keep the rollback honest would be slow and would be restoring upstream's install
162
- rather than our change; and excluding it would leave a transaction claiming a reversibility it does
163
- not have. So the assignment is not producible, and RFC 0003 is explicit about what that means: a
164
- capability the provider has but cannot be asked for is not an assignable capability. OpenCode stays
165
- adoption-only by decision.
166
- - **RTK on Codex.** Not managed, and no row: RTK writes a Claude-shaped hook list and nothing else.
167
- - **A newer Claude Code.** The range is a single observed version. `2.1.221` reads `unknown-newer` and
168
- refuses rather than assuming it behaves like `2.1.220`.
169
-
170
- The recordings are under `tests/fixtures/rows/`, one directory per row, each with a README stating
171
- which stages exist and which do not.
172
-
173
- ## How the components fit together
174
-
175
- There are three separate layers. Installing one does not automatically provide the others.
176
-
177
- | Layer | Examples | Who installs it? |
178
- | --- | --- | --- |
179
- | Coding agent (harness) | Claude Code, Codex, OpenCode, Hermes, Pi | You, using the agent's official installer |
180
- | Token Harness | `token-harness` | You, from npm or this repository |
181
- | Optimization provider | RTK, HarnessTrim | Both can be installed by Token Harness where a compatibility row covers the combination; otherwise install them with their own installers and Token Harness detects and measures them |
182
-
183
- Token Harness does not install Claude Code, Codex, OpenCode, Hermes, or Pi. Install and run at least one of
184
- them first so that `token-harness doctor` can detect it.
185
-
186
- | Provider | Claude Code | Codex | OpenCode | Hermes | Pi | Installed by Token Harness |
187
- | --- | --- | --- | --- | --- | --- | --- |
188
- | RTK | Configure, verify, and measure | Not managed | Detect, adopt, verify, and measure | Not managed | Not managed | **Yes**, for the supported Claude Code path |
189
- | HarnessTrim | Claude skills only; no reducer hook or reduce-pipe instruction | Detect, adopt, verify, and measure | Detect, adopt, verify, and measure | Detect, verify, and measure | Detect, verify, and measure | **Yes**, on a covered row — see above |
36
+ `--yes` is always explicit. The change is backed up, applied transactionally, and
37
+ verified. Unsupported combinations are left untouched.
190
38
 
191
- "Not managed" does not mean the upstream tool cannot support that agent. It means this release
192
- does not claim ownership of that integration and will not modify it.
39
+ ## Open the dashboard
193
40
 
194
- Hermes is read-only in both directions: the adapter finds the HarnessTrim plugin, reads whether it
195
- is enabled, and imports the telemetry it writes to `~/.hermes/harnesstrim-metrics.jsonl`, but nothing
196
- here enables the plugin or restarts the gateway. Enabling it is
197
- `hermes plugins enable harnesstrim`, and that stays your command to run. No compatibility row ships
198
- for Hermes because a row is the precondition for a *mutation*, and none is proposed.
199
-
200
- Pi is read-only in both directions too: the adapter finds the HarnessTrim extension module in the
201
- directories Pi auto-loads (`~/.pi/agent/extensions/` and `<project>/.pi/extensions/`) and verifies
202
- the configuration, but nothing here installs it, and nothing here can say which mode it runs in —
203
- the extension defaults to `dryrun` and only `HARNESSTRIM_MODE=active` in Pi's environment makes it
204
- reduce. Installing it is `harnesstrim install pi --apply`, and that stays your command to run. No
205
- compatibility row ships for Pi because a row is the precondition for a *mutation*, and none is
206
- proposed.
207
-
208
- RTK on OpenCode is detected and verified, not written: `rtk init -g --opencode` installs a plugin
209
- module at `~/.config/opencode/plugins/rtk.ts`, and Token Harness reads that file rather than
210
- producing it. Note that the plugin is inert under OpenCode Desktop — see
211
- [docs/matrices.md](docs/matrices.md) for what was measured.
212
-
213
- The generated compatibility tables, tested version ranges, platform coverage, and known
214
- limitations are in [docs/matrices.md](docs/matrices.md).
215
-
216
- ## Installing each component
217
-
218
- ### 1. Install Token Harness
219
-
220
- Recommended, from npm:
41
+ After setup, run:
221
42
 
222
43
  ```sh
223
- npm install --global token-harness
224
- token-harness --help
44
+ token-harness ui
225
45
  ```
226
46
 
227
- If the command is not found after installation, find npm's global binary directory with:
228
-
229
- ```sh
230
- npm prefix --global
231
- ```
47
+ The dashboard opens in your browser and shows harness status, active providers,
48
+ allowance windows, the main recommendation, and the next action. It is a small local
49
+ web page served only on `127.0.0.1`: no Electron app, account, or cloud service.
232
50
 
233
- Ensure that directory's executable location is on `PATH`, then open a new terminal.
234
-
235
- #### Build and install from source
236
-
237
- The repository uses the pnpm version declared in `package.json`.
51
+ Use `Ctrl+C` in the terminal to close it. If you do not want it to open a browser:
238
52
 
239
53
  ```sh
240
- git clone https://github.com/giuliastro/token-harness.git
241
- cd token-harness
242
- corepack enable
243
- pnpm install
244
- pnpm build
245
- pnpm package
246
- npm install --global ./dist/package
247
- token-harness --version
54
+ token-harness ui --no-open
248
55
  ```
249
56
 
250
- `pnpm build` creates the self-contained CLI at `dist/bundle/token-harness.mjs`.
251
- `pnpm package` creates the installable package under `dist/package`.
252
- If `corepack` is unavailable, install the pinned package manager with
253
- `npm install --global pnpm@10.33.4` instead.
57
+ ## Ask your AI to install Token Harness
254
58
 
255
- ### 2. Install or adopt RTK
59
+ You can give this prompt to Claude Code or Codex:
256
60
 
257
- When a reviewed compatibility row covers the installed versions, you normally do **not** install RTK yourself:
258
-
259
- ```sh
260
- token-harness plan --harness claude --provider rtk
61
+ ```text
62
+ Install the latest stable Token Harness from npm on this computer, then run
63
+ `token-harness setup`. Do not install or replace Claude Code, Codex, or any
64
+ optimization provider unless Token Harness's supported plan explicitly requires it.
65
+
66
+ Explain the setup result in plain language: what was detected, what already works,
67
+ what would change, and the single next step. Do not expose credentials, cookies,
68
+ tokens, raw home paths, or private project contents. If setup proposes a supported
69
+ configuration change, show me the short plan and ask before running
70
+ `token-harness setup --yes`. After an approved change, verify it and start
71
+ `token-harness ui`. If anything is unsupported, stop safely and explain why.
261
72
  ```
262
73
 
263
- Once a matching compatibility row exists, if RTK is absent, the plan contains two actions:
74
+ The AI should ask before the `--yes` step because that is the point where coding-agent
75
+ configuration may change.
264
76
 
265
- 1. install RTK through the selected package manager;
266
- 2. append one RTK entry to Claude Code's `PreToolUse` hook configuration.
77
+ ## What normal output looks like
267
78
 
268
- The channel selected by this release is:
79
+ Human output is intentionally short:
269
80
 
270
- | Platform | Channel used by the plan | Required command on `PATH` |
271
- | --- | --- | --- |
272
- | Windows | WinGet package `rtk-ai.rtk` | `winget` |
273
- | macOS | Cargo package `rtk` | `cargo` |
274
- | Linux and WSL | Cargo package `rtk` | `cargo` |
81
+ ```text
82
+ TOKEN HARNESS - READY
275
83
 
276
- The Cargo path in this release invokes `cargo install rtk`. That channel is declared but has not
277
- been exercised by this project, and upstream documents a crates.io name collision. On macOS,
278
- Linux, and WSL, the safer current route is to install RTK with an upstream-recommended method,
279
- confirm that `rtk gain` works, and let Token Harness adopt and configure the existing binary.
84
+ DETECTED
85
+ Claude Code: detected
86
+ Codex: configured
87
+ harnesstrim: active on Codex
280
88
 
281
- Review the plan's `Network`, `Elevation`, and `Actions` sections before applying it:
89
+ CHANGES
90
+ Nothing changed.
282
91
 
283
- ```sh
284
- token-harness apply --yes --harness claude --provider rtk
92
+ NEXT STEP
93
+ token-harness ui
94
+ Open the dashboard to see status, allowance, and advice.
285
95
  ```
286
96
 
287
- If RTK is already installed and configured, Token Harness adopts it instead of reinstalling or
288
- rewriting it. User-owned configuration remains user-owned.
289
-
290
- Important boundaries:
291
-
292
- - Token Harness writes the reviewed hook itself; it does not run `rtk init`.
293
- - A package install is not reversed by file rollback. `rollback` restores configuration files,
294
- not installed binaries.
295
- - `uninstall` removes only integration entries written by Token Harness; it deliberately leaves
296
- the RTK executable installed.
297
- - On native Windows, Claude Code exposes both Bash and PowerShell tool families. The current RTK
298
- matcher covers Bash only, so `doctor` can correctly report PowerShell as bypassed.
299
-
300
- For manual installation or use outside Token Harness's managed surface, follow the
301
- [RTK installation guide](https://github.com/rtk-ai/rtk/blob/master/INSTALL.md), then run:
97
+ Need the evidence behind the summary? Add `--verbose`:
302
98
 
303
99
  ```sh
304
- rtk --version
305
- rtk gain
306
- token-harness doctor --provider rtk
100
+ token-harness doctor --verbose
307
101
  ```
308
102
 
309
- `rtk gain` is an important identity check because another unrelated package also uses the name
310
- `rtk`.
311
-
312
- ### 3. Install or adopt HarnessTrim
313
-
314
- With HarnessTrim on `PATH`, `token-harness plan --harness claude` can install its Claude skills
315
- without creating the competing Bash hook or reduce-pipe instruction. The invocation it delegates to
316
- is:
103
+ Need stable machine-readable output for automation? Add `--json`:
317
104
 
318
105
  ```sh
319
- harnesstrim install claude <project> --apply --no-hook --no-instructions
106
+ token-harness doctor --json
107
+ token-harness ui --json
320
108
  ```
321
109
 
322
- Codex and OpenCode remain adoption-only. Install those integrations with HarnessTrim's own CLI,
323
- first as a dry run and then with its explicit apply flag. Consult the
324
- [HarnessTrim README](https://github.com/giuliastro/HarnessTrim#quick-start) because its adapter
325
- contents, modes, and telemetry differ by coding agent.
110
+ `--json` keeps the complete schema-1 result and diagnostics; it is not shortened.
326
111
 
327
- After installing it:
112
+ ## Three commands to remember
328
113
 
329
114
  ```sh
330
- token-harness doctor --provider harnesstrim
331
- token-harness status --provider harnesstrim
332
- token-harness verify --provider harnesstrim
333
- token-harness metrics --provider harnesstrim --since 7d
115
+ token-harness setup
116
+ token-harness ui
117
+ token-harness optimize
334
118
  ```
335
119
 
336
- Do not configure RTK and HarnessTrim to reduce the same shell output. In the `safe` profile,
337
- Token Harness gives that exclusive surface to RTK and treats an existing overlap as a hard
338
- conflict instead of guessing an execution order. It never deletes the competing entry for you.
339
-
340
- HarnessTrim telemetry is opt-in in some adapters. Without a `.harnesstrim/metrics.jsonl` file,
341
- verification can still inspect configuration, but `metrics` has no HarnessTrim events to import.
120
+ | Command | Answer |
121
+ | --- | --- |
122
+ | `setup` | Is Token Harness ready, and what is my one next step? |
123
+ | `ui` | What is active, how much allowance is visible, and what should I do? |
124
+ | `optimize` | What is the best evidence-based action for the task I am starting? |
342
125
 
343
- From `0.1.0`, HarnessTrim publishes a machine-readable capability declaration: the surfaces it
344
- intercepts per coding agent, the flags that narrow an install, and the paths each install writes.
126
+ For example:
345
127
 
346
128
  ```sh
347
- harnesstrim capabilities
129
+ token-harness optimize --task hard --profile quality
130
+ token-harness optimize --task mechanical --profile economy
348
131
  ```
349
132
 
350
- Detection reads that declaration and compares it against the one Token Harness records, so an
351
- upstream change is reported rather than assumed compatible. A disagreement becomes a
352
- `provider-capabilities-drift` warning naming both sides. A build older than the command cannot
353
- answer; Token Harness then falls back to its own recorded declaration and reports nothing, because a
354
- provider that cannot be asked must still be describable.
355
-
356
- ## The recommended operating workflow
133
+ ## Safety and privacy
357
134
 
358
- ### Step 1: diagnose
135
+ Token Harness is conservative by design:
359
136
 
360
- ```sh
361
- token-harness doctor
362
- ```
137
+ - normal read-only commands do not change coding-agent or project configuration;
138
+ - `setup --yes`, `apply --yes`, `update --yes`, `rollback --yes`, and
139
+ `uninstall --yes` are the explicit configuration-changing forms;
140
+ - plans are checked again immediately before they are applied;
141
+ - existing files are backed up before a managed write;
142
+ - only exact Token Harness-owned entries are removed by `uninstall`;
143
+ - newer or untested combinations are reported, not guessed;
144
+ - the dashboard binds only to the local loopback address and provides no mutation API;
145
+ - source code, prompts, command contents, credentials, and cookies are not sent to a
146
+ Token Harness service.
363
147
 
364
- This answers:
148
+ Plans, receipts, metrics, and backups stay in the local Token Harness state directory.
149
+ See [RFC 0004](docs/rfcs/0004-execution-safety-ownership-update.md) for the execution
150
+ model and [RFC 0006](docs/rfcs/0006-cli-contract.md) for CLI/JSON guarantees.
365
151
 
366
- - which supported coding agents are installed;
367
- - which providers are installed and runnable;
368
- - which agent configuration files exist;
369
- - which provider is wired to which agent;
370
- - whether Token Harness owns the integration or merely adopted it;
371
- - whether a version, configuration file, or tool-family matcher needs attention;
372
- - whether the installed provider's own capability declaration still agrees with the one Token
373
- Harness records.
152
+ ## Supported optimizations
374
153
 
375
- Common states:
154
+ Token Harness can detect and measure several independent local tools:
376
155
 
377
- | State | Meaning |
378
- | --- | --- |
379
- | `not found` / `absent` | The executable and usable configuration were not detected |
380
- | `installed` | The provider runs but is not connected to a supported agent |
381
- | `configured` | A relevant hook or plugin entry exists |
382
- | `broken` | Configuration refers to something missing or unreadable |
383
- | `set up by you` | Token Harness adopted existing configuration and will not remove it |
384
- | `set up by this tool` | A committed Token Harness transaction owns the exact entry |
156
+ | Provider | Purpose | Management |
157
+ | --- | --- | --- |
158
+ | [RTK](https://github.com/rtk-ai/rtk) | Shell-command rewriting and output reduction | Managed only for reviewed combinations |
159
+ | [HarnessTrim](https://github.com/giuliastro/HarnessTrim) | Deterministic reducers and harness adapters | Managed only for reviewed combinations |
160
+ | [cclimits](https://github.com/cruzanstx/cclimits) | Optional live/local quota companion | Read-only; never installed automatically |
161
+ | [ccusage](https://github.com/ccusage/ccusage) | Local usage history | Read-only; never installed automatically |
385
162
 
386
- `doctor` is diagnostic. An empty machine is a valid state and exits successfully.
163
+ A provider you installed yourself remains yours. Token Harness can adopt observable
164
+ configuration without claiming ownership of the executable.
387
165
 
388
- ### Step 2: review the plan
166
+ Exact reviewed provider/harness/platform/version combinations are generated in
167
+ [docs/matrices.md](docs/matrices.md). A combination outside that table can still be
168
+ detected and inspected, but Token Harness will not mutate it.
389
169
 
390
- ```sh
391
- token-harness plan
392
- ```
170
+ ## Advanced commands
393
171
 
394
- Narrow the operation when useful:
172
+ Most people do not need this section. Run `token-harness <command> --help` for details.
395
173
 
396
- ```sh
397
- token-harness plan --harness claude
398
- token-harness plan --provider rtk
399
- token-harness plan --project /path/to/project
400
- ```
401
-
402
- Read these sections before proceeding:
174
+ | Command | Purpose | Changes agent/project config? |
175
+ | --- | --- | --- |
176
+ | `doctor` | Detect harnesses, providers, versions, and problems | No |
177
+ | `budget` | Read authoritative/reported allowance windows | No |
178
+ | `context` | Inspect model settings, instructions, and MCP exposure | No |
179
+ | `mcp` | Focus on MCP server/tool health | No |
180
+ | `history` | Summarize local usage through an installed ccusage | No |
181
+ | `plan` | Prepare exact supported changes | No; stores local plan state |
182
+ | `apply` | Apply a reviewed stored plan | Yes, only with `--yes` |
183
+ | `verify` | Check the declared integration tier | No |
184
+ | `metrics` | Report attributable reducer savings | No |
185
+ | `status` | Report pipelines, drift, and importer modes | No |
186
+ | `update` | Check/update installed providers | Yes, only with `--yes` |
187
+ | `rollback` | Restore the latest transaction snapshot | Yes, only with `--yes` |
188
+ | `uninstall` | Remove owned integration entries | Yes, only with `--yes` |
189
+ | `schedule` | Compare Claude Code and Codex using available evidence | No |
190
+ | `handoff` | Build a bounded cross-harness handoff | No |
191
+ | `benchmark*`, `transfer*` | Capture and compare empirical evidence | Local state only |
403
192
 
404
- - `Capability ownership`: which provider is allowed to transform each surface;
405
- - `Excluded`: detected providers intentionally left out;
406
- - `Actions`: every package operation and file change;
407
- - `Network`: destinations contacted by later mutation;
408
- - `Elevation`: whether administrator/root access would be required;
409
- - `Backups`: how many files will be snapshotted.
193
+ ## Troubleshooting
410
194
 
411
- `plan` does not modify agent or project configuration. It may persist the serialized plan in
412
- Token Harness's private state directory so the exact reviewed artifact can be applied later.
195
+ ### `token-harness` is not found
413
196
 
414
- If the plan prints an ID, apply that exact plan with:
197
+ Check that Node is new enough and the package is installed:
415
198
 
416
199
  ```sh
417
- token-harness apply --plan <plan-id> --yes
200
+ node --version
201
+ npm list --global token-harness
418
202
  ```
419
203
 
420
- The stored plan is rejected before any action runs if the project, versions, ownership, or file
421
- preconditions changed after review.
204
+ Node must be at least 22.13. Reopen the terminal after installation if needed.
422
205
 
423
- ### Step 3: apply
206
+ ### Setup needs attention
207
+
208
+ Run the single command it prints. For technical evidence:
424
209
 
425
210
  ```sh
426
- token-harness apply --yes
211
+ token-harness doctor --verbose
427
212
  ```
428
213
 
429
- Without `--yes`, `apply` shows what it would do and exits with code 8. Every affected file is
430
- snapshotted before mutation, including the prior absence of a newly created file. A failure
431
- triggers automatic restoration and the result states whether that restoration was verified.
432
-
433
- After a successful apply, restart the coding agent so it reloads its hooks or plugins.
434
-
435
- ### Step 4: create real traffic
436
-
437
- Passive verification needs evidence from an operation that actually passed through the provider.
438
- Open the configured coding agent and ask it to run a normal shell command such as `git status` or
439
- a test command. Then return to the terminal.
214
+ Do not force an unsupported plan. Open an issue with the redacted `--json` result if
215
+ you believe the combination should be supported.
440
216
 
441
- ### Step 5: verify configuration and execution
217
+ ### Verification says `not-exercised`
442
218
 
443
- Use both commands; they answer different questions:
219
+ Restart the coding agent, use it for one normal command, and run:
444
220
 
445
221
  ```sh
446
- token-harness status
447
222
  token-harness verify
448
223
  ```
449
224
 
450
- `status` compares the live environment with committed receipts. It finds drift, changed versions,
451
- and competing entries on exclusive surfaces.
225
+ No observed operation is different from a failed integration, so Token Harness reports
226
+ the two states separately.
452
227
 
453
- `verify` checks the strongest evidence the integration declares:
228
+ ## Updating or undoing
454
229
 
455
- | Tier | What it proves |
456
- | --- | --- |
457
- | `presence` | The executable resolves and reports a version |
458
- | `config-only` | The expected configuration entry exists |
459
- | `canary` | Provider records show a real operation crossed the interception point |
460
-
461
- `config-only` is not proof that the hook ran. It is the honest ceiling for integrations whose
462
- runtime state cannot be observed externally.
463
-
464
- `not-exercised` means no attributable operation has been observed yet. It is neither success nor
465
- failure: run a command through the agent and check again.
466
-
467
- ### Step 6: inspect savings
230
+ Update the CLI:
468
231
 
469
232
  ```sh
470
- token-harness metrics
471
- token-harness metrics --since 24h
472
- token-harness metrics --since 2026-07-01 --until 2026-08-01
473
- token-harness metrics --provider rtk --since 7d
233
+ npm install --global token-harness@latest
234
+ token-harness setup
474
235
  ```
475
236
 
476
- The default window is seven days. Durations such as `12h`, `7d`, and `2w`, plus ISO dates, are
477
- accepted. Date boundaries are midnight UTC.
478
-
479
- The report keeps measurement types and units separate:
480
-
481
- | Report line | Interpretation |
482
- | --- | --- |
483
- | `Exact local` | Before and after token counts were observed for the same operation |
484
- | `Estimated local` | The payload changed, but the reported unit or tokenizer is an estimate |
485
- | `Counterfactual` | A dry run measured what could have changed; it is not realized saving |
486
- | `End-to-end billed` | Comparable billed sessions were measured; otherwise it says `no A/B run` |
487
- | `Coverage` | Share of relevant operations that were actually changed |
488
- | `Bypassed` | Operations observed but passed through unchanged or outside coverage |
489
-
490
- Token counts are never added to character counts, and estimated or counterfactual values are never
491
- silently merged into an exact total.
492
-
493
- The report covers one project: the one `--project` names, or the current directory. An operation a
494
- provider recorded without a directory belongs to no project and is excluded, with a count reported
495
- so the difference is reconcilable. When no project identity can be established the report says so
496
- rather than presenting every project's events as one project's figures.
497
-
498
- ## Undoing changes
499
-
500
- Choose the command based on what you want to undo:
237
+ Remove only Token Harness-owned integration entries:
501
238
 
502
239
  ```sh
503
- # Remove only exact integration entries owned by Token Harness.
504
240
  token-harness uninstall --yes
505
-
506
- # Restore all files from the most recent committed transaction snapshot.
507
- token-harness rollback --yes
508
241
  ```
509
242
 
510
- `uninstall` is usually the safer choice after subsequent manual edits: it is surgical and refuses
511
- to remove an owned entry if its content no longer matches what Token Harness wrote.
512
-
513
- `rollback` restores whole files to their pre-transaction bytes. Changes made to those files after
514
- the transaction are therefore also reverted. It does not restore or remove provider packages.
515
-
516
- Neither command removes user-owned RTK or HarnessTrim configuration.
517
-
518
- ## Command reference
519
-
520
- | Command | Purpose | Changes agent/project configuration? |
521
- | --- | --- | --- |
522
- | `doctor` | Detect agents, providers, ownership, and problems | No |
523
- | `plan` | Resolve ownership and preview exact actions | No; stores the plan in private state |
524
- | `apply` | Apply a plan transactionally | Yes, only with `--yes` |
525
- | `status` | Detect drift and competing hooks | No |
526
- | `verify` | Check the declared verification tier | No |
527
- | `metrics` | Import provider records and report savings | No; updates only Token Harness state |
528
- | `update` | Query channels and update installed providers | Yes, only with `--yes` |
529
- | `rollback` | Restore files from the latest committed transaction | Yes, only with `--yes` |
530
- | `uninstall` | Remove owned integration entries | Yes, only with `--yes` |
531
-
532
- Every command supports `--help`. Common filters are:
533
-
534
- ```text
535
- --harness claude|codex|opencode
536
- --provider rtk|harnesstrim
537
- --project <directory>
538
- --json
539
- ```
540
-
541
- ## Automation and JSON output
542
-
543
- Use `--json` in scripts:
243
+ Restore complete files from the latest committed transaction snapshot:
544
244
 
545
245
  ```sh
546
- token-harness doctor --json
547
- token-harness verify --json
548
- token-harness metrics --since 7d --json
549
- ```
550
-
551
- stdout contains exactly one JSON document with this top-level contract:
552
-
553
- ```json
554
- {
555
- "schemaVersion": 1,
556
- "command": "verify",
557
- "toolVersion": "0.1.0",
558
- "status": "ok",
559
- "exitCode": 0,
560
- "data": {},
561
- "diagnostics": []
562
- }
563
- ```
564
-
565
- Important exit codes:
566
-
567
- | Code | Meaning |
568
- | ---: | --- |
569
- | 0 | Completed with nothing actionable |
570
- | 2 | Invalid command or argument |
571
- | 3 | A read-only check found an actionable problem |
572
- | 4 | A capability conflict blocks the plan |
573
- | 5 | The environment drifted from the stored plan or journal |
574
- | 6 | Mutation failed and rollback was verified |
575
- | 7 | Mutation failed and state was not fully restored; inspect the named paths |
576
- | 8 | The command needs explicit confirmation (`--yes`) |
577
- | 9 | Unsupported or unverifiable environment |
578
-
579
- Do not treat every non-zero code as the same failure. In particular, code 8 is the expected result
580
- of previewing a mutating command without approval.
581
-
582
- ## State, backups, and privacy
583
-
584
- Token Harness stores plans, journals, backups, receipts, import cursors, and normalized metrics
585
- outside the repository:
586
-
587
- | Platform | Default state root |
588
- | --- | --- |
589
- | Windows | `%LOCALAPPDATA%\TokenHarness` |
590
- | macOS | `~/Library/Application Support/TokenHarness` |
591
- | Linux and WSL | `${XDG_STATE_HOME:-~/.local/state}/token-harness` |
592
-
593
- Normalized metrics do not contain raw command text, tool output, source code, prompts, credentials,
594
- or raw file paths. Provider records are read in place; Token Harness imports only normalized event
595
- data.
596
-
597
- ## Troubleshooting
598
-
599
- ### `token-harness` is not found
600
-
601
- Confirm Node and the global npm installation:
602
-
603
- ```sh
604
- node --version
605
- npm list --global token-harness
606
- npm prefix --global
246
+ token-harness rollback --yes
607
247
  ```
608
248
 
609
- Node must be at least 22.13.0. Add npm's global executable directory to `PATH`, then reopen the
610
- terminal.
611
-
612
- ### `plan` says there is nothing to do
613
-
614
- Run `token-harness doctor`. The usual causes are:
615
-
616
- - no supported coding agent was detected;
617
- - the requested provider does not claim that coding agent in this release;
618
- - an existing user-managed integration already satisfies the target state;
619
- - the safe profile excluded an overlapping provider.
620
-
621
- RTK is written only for Claude Code in 0.1.0. It claims OpenCode too, but the plan builder appends
622
- a `hooks` entry, which is Claude Code's schema — OpenCode's integration is a plugin module, so an
623
- OpenCode scope produces no action and the existing installation is adopted instead. A Codex-only
624
- machine produces no RTK action at all.
625
-
626
- ### The plan is blocked by `exclusive-scope-contested`
249
+ `rollback` is whole-file time travel, so it can also revert later manual edits to those
250
+ files. Prefer `uninstall` when you only want to remove Token Harness-owned entries.
627
251
 
628
- RTK and HarnessTrim both claim the same reducing surface. Token Harness will not choose an order or
629
- overwrite either configuration. Remove or disable one integration using the tool that owns it, then
630
- run `doctor` and `plan` again.
631
-
632
- ### `verify` reports `not-exercised`
633
-
634
- Restart the coding agent, ask it to run a shell command through the configured tool family, then
635
- run `token-harness verify` again. For a `config-only` integration, no stronger external receipt may
636
- exist; the output states that limitation explicitly.
637
-
638
- ### `metrics` shows no data
639
-
640
- Check all of the following:
641
-
642
- - the provider has processed at least one operation in the requested time window;
643
- - `rtk gain` works for RTK;
644
- - HarnessTrim telemetry is enabled and `.harnesstrim/metrics.jsonl` exists for the project;
645
- - `--project` points to the project whose records you expect;
646
- - `--since` is not excluding older events.
647
-
648
- An empty metrics report exits 0 because it is a valid observation, not a command failure.
649
-
650
- ### `doctor` or `status` reports `provider-capabilities-drift`
651
-
652
- The installed provider's own capability declaration no longer agrees with the one Token Harness
653
- records. The warning names both sides: what the recorded declaration claims, and what the installed
654
- build reported. Nothing is modified, and the recorded declaration still drives planning.
655
-
656
- Three disagreements are reported:
657
-
658
- - a coding agent that Token Harness records a capability on is missing from the build's declaration;
659
- - the reduction surface Token Harness records is absent from the surfaces the build reports;
660
- - the build no longer covers a reviewed write-set path, or declares a path outside the reviewed
661
- containment boundary.
662
-
663
- The last one matters most before a delegated install. Rollback restores the reviewed boundary, so a
664
- path outside it would survive a rollback. Re-review the write set at the installed version, or hold
665
- at the reviewed one.
666
-
667
- ### A newer provider or agent version is reported
668
-
669
- The tested ranges record versions actually exercised by this project. A newer version is reported
670
- and handled conservatively rather than assumed compatible. Check [docs/matrices.md](docs/matrices.md)
671
- and the upstream release notes before applying configuration changes.
672
-
673
- ## Development
252
+ ## Develop from source
674
253
 
675
254
  ```sh
255
+ git clone https://github.com/giuliastro/token-harness.git
256
+ cd token-harness
676
257
  corepack enable
677
258
  pnpm install
678
259
  pnpm typecheck
@@ -684,15 +265,10 @@ pnpm package
684
265
  pnpm smoke:install
685
266
  ```
686
267
 
687
- Tests use temporary homes and fake process runners; they do not install third-party tools.
688
- `pnpm smoke` runs the bundle from outside the workspace, and `pnpm smoke:install` validates the
689
- packed npm artifact.
690
-
691
- Before changing architecture or public behavior, read [PLAN.md](PLAN.md) and the accepted RFCs in
692
- [docs/rfcs](docs/rfcs). The CLI and JSON contract is defined by
693
- [RFC 0006](docs/rfcs/0006-cli-contract.md).
268
+ Read [PLAN.md](PLAN.md) and the accepted [RFCs](docs/rfcs) before changing public
269
+ behavior or architecture.
694
270
 
695
271
  ## License
696
272
 
697
- Token Harness is licensed under the [Apache License 2.0](LICENSE). RTK and HarnessTrim are
698
- independent upstream projects distributed under their own licenses.
273
+ [Apache License 2.0](LICENSE). Referenced provider tools are independent projects with
274
+ their own licenses.