context-doctor 0.51.0 → 0.53.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 +30 -32
- package/dist/cli.js +27 -7
- package/dist/doctor.js +26 -3
- package/dist/fix.d.ts +30 -0
- package/dist/fix.js +51 -5
- package/dist/limits.d.ts +80 -0
- package/dist/limits.js +185 -0
- package/dist/mcp.js +55 -55
- package/dist/modelids.d.ts +44 -0
- package/dist/modelids.js +174 -0
- package/dist/pricecheck.d.ts +11 -0
- package/dist/pricecheck.js +32 -0
- package/dist/pricing.js +12 -3
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.js +1 -1
- package/dist/sample.d.ts +8 -0
- package/dist/sample.js +86 -0
- package/dist/savings.d.ts +8 -1
- package/dist/savings.js +32 -7
- package/dist/starts.d.ts +39 -0
- package/dist/starts.js +157 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,30 +7,34 @@
|
|
|
7
7
|
AI agents re-send their whole context on every message: old tool output, pasted files, long instructions. A 500k-token session pays for all of it again each time, and at full price after a coffee break, when the prompt cache has expired. context-doctor measures that waste on your own sessions, in dollars, and removes it at the moments it pays: before it enters the context, while it sits there, and on every request. It runs on your machine, needs no API key, sends no telemetry, and works with **Claude Code** (terminal, IDE, desktop app), **Claude Desktop, ChatGPT, Codex, Cursor, Gemini CLI, GitHub Copilot**, any app on the **Anthropic, OpenAI or Gemini API**, and **CI**. MIT licensed, Node 20+, macOS, Linux and Windows.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npx context-doctor savings
|
|
11
|
-
npx context-doctor fix # the fixes ranked by dollars; applies only the ones you say yes to
|
|
12
|
-
npx context-doctor spend # one bill across Claude Code, Codex, Gemini CLI, Cursor, Copilot CLI, OpenCode and Cline
|
|
10
|
+
npx context-doctor savings
|
|
13
11
|
```
|
|
14
12
|
|
|
13
|
+
What your recent Claude Code sessions cost, and what each fix would have saved: replayed request by request against what you were billed, never modelled, and with nothing to measure it says so. Nothing to measure yet? `npx context-doctor savings --sample` runs the same report on generated example sessions, labelled SAMPLE.
|
|
14
|
+
|
|
15
15
|
<img src="https://raw.githubusercontent.com/KushalP1/context-doctor/main/assets/savings.svg" alt="npx context-doctor savings: input billed, what /compact at cold resumes, autopilot and an earlier auto-compact window would have saved" width="640">
|
|
16
16
|
|
|
17
|
+
*Measured on the author's own sessions, priced the way the prompt cache billed them; `savings` replays yours the same way and, with nothing to measure, says so.*
|
|
18
|
+
|
|
17
19
|
> **Which context-doctor is this?** Several projects share the name. This one is [`context-doctor` on npm](https://www.npmjs.com/package/context-doctor) and `io.github.KushalP1/context-doctor` in the official MCP Registry ([see the entry](https://registry.modelcontextprotocol.io/v0/servers/io.github.KushalP1%2Fcontext-doctor/versions/latest)). The registry is a service, not a list in a GitHub repo: the `modelcontextprotocol/servers` repository holds only reference servers and points to the registry for the rest. Built and maintained by [gAI Ventures](https://gai.ventures).
|
|
18
20
|
|
|
19
21
|
## Quick start
|
|
20
22
|
|
|
21
23
|
**See it first, nothing installed:** in a terminal, `npx context-doctor` reads your last 30 days of Claude Code sessions on this machine and shows what the fixes with no quality cost would have saved, as one total, then asks once: `y` applies them all, `npx context-doctor fix undo` puts them back. The fixes that trade something (compacting earlier, the subagents' model) are listed with their dollars and the command for each.
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
**Claude Code** (terminal, IDE, desktop app): inside Claude Code, `/plugin marketplace add KushalP1/context-doctor`, then `/plugin install context-doctor@context-doctor`. You get the every-prompt check, the compaction hook, the MCP tools and `/context-doctor:fix`, `:spend`, `:savings`, `:checkup`, `:overhead`, `:pack`, `:autopilot`, `:compact-window`.
|
|
26
|
+
|
|
27
|
+
**Everything on this machine at once:** `npm install -g context-doctor && context-doctor install` wires Claude Code, Claude Desktop, Cursor, Codex, Gemini CLI, Google Antigravity and GitHub Copilot: MCP server, skill and hooks ([what it writes](./docs/install.md)). `context-doctor doctor` checks it; `context-doctor uninstall` removes it. Then, for Claude Code in a terminal or IDE, `context-doctor autopilot on`.
|
|
28
|
+
|
|
29
|
+
Each takes about a minute and is fully reversible. Work somewhere else? Same idea, other surfaces:
|
|
24
30
|
|
|
25
31
|
| You use | Do this |
|
|
26
32
|
|---|---|
|
|
27
|
-
| **Claude Code** (terminal, IDE, desktop app) | Inside Claude Code: `/plugin marketplace add KushalP1/context-doctor`, then `/plugin install context-doctor@context-doctor`. You get the every-prompt check, the compaction hook, the MCP tools and `/context-doctor:fix`, `:spend`, `:savings`, `:checkup`, `:overhead`, `:pack`, `:autopilot`, `:compact-window` |
|
|
28
|
-
| **Everything on this machine at once** | `npm install -g context-doctor && context-doctor install` wires Claude Code, Claude Desktop, Cursor, Codex, Gemini CLI, Google Antigravity and GitHub Copilot: MCP server, skill and hooks ([what it writes](./docs/install.md)). `context-doctor doctor` checks it; `context-doctor uninstall` removes it. Then, for Claude Code in a terminal or IDE, `context-doctor autopilot on` |
|
|
29
33
|
| **Claude Desktop, Cursor or any MCP client** | Add the server to the client's MCP config (or install the one-click `.mcpb` from the [latest release](https://github.com/KushalP1/context-doctor/releases/latest) in Claude Desktop):<br>`{"mcpServers": {"context-doctor": {"command": "npx", "args": ["-y", "context-doctor", "mcp"]}}}` |
|
|
30
34
|
| **claude.ai, ChatGPT, phone apps** | `npx context-doctor instructions --copy`, then paste into the app's personal preferences (it tells you where). ChatGPT can also reach the MCP server at a URL ([how](./docs/chat-apps.md#chatgpt)) |
|
|
31
35
|
| **Your own app on an LLM API** | Run `npx context-doctor proxy --autopilot` and point `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL` (add `/v1`) or `GOOGLE_GEMINI_BASE_URL` at the proxy on `127.0.0.1:8787`, plain HTTP ([exact values](./docs/proxy.md)). No proxy possible? Wrap the SDK client: `withContextDoctor(new Anthropic())` ([library](./docs/library.md)) |
|
|
32
36
|
| **Python / RAG pipelines** | `pip install "git+https://github.com/KushalP1/context-doctor#subdirectory=python"` (PyPI release coming), then `pack_documents(retrieved_docs, question, budget=4000)` trims LangChain or LlamaIndex results to the chunks that matter. [Python README](./python/README.md) |
|
|
33
|
-
| **GitHub pull requests** | `uses: KushalP1/context-doctor@v0.
|
|
37
|
+
| **GitHub pull requests** | `uses: KushalP1/context-doctor@v0.53.0` comments how much a PR grows CLAUDE.md, AGENTS.md and rules, and can fail over a budget ([setup](./docs/ci.md)) |
|
|
34
38
|
|
|
35
39
|
## What it does
|
|
36
40
|
|
|
@@ -40,7 +44,7 @@ Pick where you work. Each takes about a minute and is fully reversible.
|
|
|
40
44
|
- `overhead`: what every request re-reads before your message (system prompt, tools, MCP servers, CLAUDE.md, rules, memory), each file priced per month.
|
|
41
45
|
- `tasks`, `reads`, `subagents`, `compactions`: cost per commit; files read into session after session; whether each subagent was cheaper than the same steps in the parent; whether sessions work worse after compacting.
|
|
42
46
|
- `cache-misses`: requests that re-wrote the prompt cache while it should still have been warm, priced, by model and context size, with the cause where the transcript shows one. And the cold returns (back after the cache expired): each one as billed, compacted on return, and kept warm by a cache read every 55 minutes, by how long you were away; what keeping warm for up to 1-8 hours would have netted; and a compacted segment the Desktop app put back ([#107157](https://github.com/anthropics/claude-code/issues/107157)).
|
|
43
|
-
- `limits`: your plan's weekly and 5-hour windows (Claude Pro, Max and Ultra, which has no 5-hour window; recorded by the plugin's mod, the status line or the proxy) and Codex's, the pace and when each runs out, what 1M tokens of each kind cost in % of the limit, and for each weekly window the API-equivalent dollars and tokens per 1%, by entrypoint and model, with every move in that figure dated and checked against the model mix (a week moved to a model that uses the limit faster per dollar is said to be the mix, not the limit draining faster), and, when a limit ran out and Claude Code kept going on usage credits, when and about how much (or, with extra usage on and the weekly limit on pace to run out early, about how much the hours until the reset would cost). `limits --report` prints it as a block to paste into a bug report, with no prompts, paths or ids.
|
|
47
|
+
- `limits`: your plan's weekly and 5-hour windows (Claude Pro, Max and Ultra, which has no 5-hour window; recorded by the plugin's mod, the status line or the proxy) and Codex's, the pace and when each runs out, what 1M tokens of each kind cost in % of the limit, and for each weekly window the API-equivalent dollars and tokens per 1%, by entrypoint and model, with every move in that figure dated and checked against the model mix (a week moved to a model that uses the limit faster per dollar is said to be the mix, not the limit draining faster), what a full 5-hour window costs of the weekly limit and whether that moved (both windows count the same requests, so the model mix cannot explain a move in it), and, when a limit ran out and Claude Code kept going on usage credits, when and about how much (or, with extra usage on and the weekly limit on pace to run out early, about how much the hours until the reset would cost). `limits --report` prints it as a block to paste into a bug report, with no prompts, paths or ids.
|
|
44
48
|
- `cache-plan <request.json>`: where an Anthropic API request should carry `cache_control`, and what it saves over N calls.
|
|
45
49
|
- `session`, `watch`, `analyze`, `report`, `dashboard`: token breakdown and wasted-context findings for any session, conversation file or agent trace.
|
|
46
50
|
|
|
@@ -63,36 +67,37 @@ Pick where you work. Each takes about a minute and is fully reversible.
|
|
|
63
67
|
|
|
64
68
|
## What it saves
|
|
65
69
|
|
|
66
|
-
Measured, not modelled, on every Claude Code session on the author's machine (mostly Opus 5 and Fable 5 with the 1M window), priced the way the prompt cache bills it (cached reads at each model's read rate, 2.5-10% of input; writes 1.25x input for the 5-minute cache, 2x for the hour) at API list prices. Re-measured on 2026-
|
|
70
|
+
Measured, not modelled, on every Claude Code session on the author's machine (mostly Opus 5.5 and the Fable 5 models with the 1M window), priced the way the prompt cache bills it (cached reads at each model's read rate, 2.5-10% of input; writes 1.25x input for the 5-minute cache, 2x for the hour) at API list prices. Re-measured on 2026-11-24 with each request at its own model and current prices (Opus 5.5 is $4 per million input tokens with $0.20 reads). `context-doctor savings` runs the same measurement on yours.
|
|
67
71
|
|
|
68
|
-
**1. Compacting when you come back** (every Claude Code surface, desktop app included).
|
|
72
|
+
**1. Compacting when you come back** (every Claude Code surface, desktop app included). 146 days, 729 returns to a session over 150k tokens after its prompt cache expired (65 idle minutes on the 1-hour cache, 10 on the 5-minute one that Claude Code 2.1.295 often writes); median context at the return, 497k tokens.
|
|
69
73
|
|
|
70
74
|
| | |
|
|
71
75
|
|---|---|
|
|
72
|
-
| Net saving had you run `/compact` after the first reply | **$
|
|
73
|
-
| Returns where it paid off |
|
|
76
|
+
| Net saving had you run `/compact` after the first reply | **$3,554 (about $740 a month)** |
|
|
77
|
+
| Returns where it paid off | about 2 in 3 |
|
|
74
78
|
| Worst single case | −$1.79 (a session left a few messages later) |
|
|
75
79
|
|
|
76
80
|
Each return counts only the messages up to the next return, and the compaction request is charged as a cost. Not counted: files the model may re-read after compacting, and what the summary leaves out. That is why this is advice with the numbers attached, not something done for you.
|
|
77
81
|
|
|
78
|
-
**2. Autopilot** (Claude Code in a terminal or IDE, API apps).
|
|
82
|
+
**2. Autopilot** (Claude Code in a terminal or IDE, API apps). 146 days, 108 sessions, replayed through the shipped autopilot code with real timestamps:
|
|
79
83
|
|
|
80
84
|
| | Without autopilot | With autopilot | Saved |
|
|
81
85
|
|---|---|---|---|
|
|
82
|
-
| Input cost at API list price | $
|
|
83
|
-
| Sessions made more expensive | | | **0 of
|
|
86
|
+
| Input cost at API list price | $14,318 | $12,561 | **$1,757 (12.3%, about $365 a month)** |
|
|
87
|
+
| Sessions made more expensive | | | **0 of 108** |
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
43 of 108 sessions save something, the best 41.6%: long sessions that go idle are where the money is. These sessions ran in the desktop app, which autopilot cannot reach, so for the author this is what the same sessions would have saved in a terminal; `context-doctor savings` separates the two for you. [How it works →](./docs/autopilot.md)
|
|
86
90
|
|
|
87
91
|
**3. Compacting earlier** <a id="3-compacting-earlier-automatic"></a>(automatic, every Claude Code surface, desktop app included). The offer in 1 is advice, and on the author's machine it was followed 1 time in 33. Claude Code has a native setting that needs nobody to follow anything: `autoCompactWindow` in `~/.claude/settings.json` makes it compact as if the window were that size. `context-doctor compact-window` replays each session request by request at several sizes, priced as the cache bills (each simulated compaction pays its own request and a 20k-token summary at the output rate), and changes nothing until you pick one:
|
|
88
92
|
|
|
89
93
|
| Window | Input cost, last 30 days | Saved | Compactions a week |
|
|
90
94
|
|---|---|---|---|
|
|
91
|
-
| as now (
|
|
92
|
-
|
|
|
93
|
-
|
|
|
94
|
-
|
|
|
95
|
-
|
|
|
95
|
+
| as now (not set) | $1,680 | | 8.6 |
|
|
96
|
+
| 800k | $1,532 | $149 (9%) | 8.6 |
|
|
97
|
+
| 600k | $1,324 | $357 (21%) | 8.9 |
|
|
98
|
+
| **400k** | **$1,053** | **$628 (37%)** | **11.9** |
|
|
99
|
+
| 300k | $958 | $723 (43%) | 17.0 |
|
|
100
|
+
| 200k | $881 | $799 (48%) | 30.6 |
|
|
96
101
|
|
|
97
102
|
41 sessions. The cost is real: each compaction replaces the session's history with a summary, so a smaller window trades detail for money. That is why the command shows the table first and sets a window only when you name one (`context-doctor compact-window 400k`; `off` undoes it, and a backup of settings.json is kept).
|
|
98
103
|
|
|
@@ -140,7 +145,7 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
140
145
|
| `context-doctor budget [<$>/day\|<$>/week [--block]\|off]` | A spend budget the every-prompt hook applies: a line at 50%, 80% and 100%, and with `--block` prompts over it are held until you raise it or turn it off; past your plan's limit, the line and `budget` say how much was paid from usage credits, and `budget` what running out before the weekly reset would cost on them ([docs](./docs/spend.md#a-budget-the-hook-applies-context-doctor-budget)) |
|
|
141
146
|
| `context-doctor doctor` | Self-check the whole installation — one pasteable ✓/✗ diagnosis with fixes, including which surfaces autopilot can reach and any other program on its port, whether extra usage (usage credits past a plan's limit) is on, which Claude Code versions sent requests the prompt cache never saw in the last 30 days and what they cost, what you answered the Desktop app's own auto-compact offer, when there is an answer on file, and which MCP servers your newest Desktop session handed the mod (their type, and whether `fix --apply desktop-tools-defer` reaches them) |
|
|
142
147
|
| `context-doctor savings [--days n] [--share [--copy]]` | What your recent Claude Code sessions cost, and what `/compact` at cold resumes, autopilot and an earlier auto-compact window would save, replayed through the shipped code against your actual billed usage (the main conversations' input: `spend` has the whole bill, output and subagents included). `--share` prints totals only (no project names or paths) to post. A bare `context-doctor` in a terminal shows `fix`'s plan instead, with one question for the fixes that cost nothing in quality |
|
|
143
|
-
| `context-doctor autopilot on\|off\|pause\|resume\|status` | Every new Claude Code session started in a terminal or IDE goes through the local proxy, which clears stale tool output only when the prompt cache is cold: measured 12.
|
|
148
|
+
| `context-doctor autopilot on\|off\|pause\|resume\|status` | Every new Claude Code session started in a terminal or IDE goes through the local proxy, which clears stale tool output only when the prompt cache is cold: measured 12.3% less input cost, no session worse ([details](./docs/autopilot.md)) |
|
|
144
149
|
| `context-doctor proxy --autopilot` | Local proxy for your own Anthropic, OpenAI and Gemini API apps: clears stale tool output only when the prompt cache is cold, so it never costs more. Plain `proxy` runs the optimizing strategies (dedupe, trim, strip base64), which can cost more on cached traffic. `--token` for a public URL; `/stats` for cumulative savings ([details](./docs/proxy.md)) |
|
|
145
150
|
| `context-doctor compact-window [status\|off\|<size>]` | Replay your last 30 days at auto-compact windows from 200k to 800k: input cost, saving, and how many more compactions each means. `400k` (or `250000`, `0.4m`) sets Claude Code's `autoCompactWindow`, with a backup; `off` removes it. Works in every Claude Code surface, the desktop app included. When you answered the Desktop app's own window offer, it says what the app offered and what you chose, and leaves that model's sessions out of the replay ([docs](./docs/fix.md#the-desktop-apps-own-window-offer-compact-window)) |
|
|
146
151
|
| `context-doctor cache-ttl [status\|1h\|5m\|off] [--subagents]` | The main conversation's (or subagents') prompt cache lifetime: what 5 minutes and 1 hour would each have cost on your last 30 days, then set or remove `promptCacheTtl` / `subagentPromptCacheTtl` (Claude Code 2.1.243+, every surface). Price only: the same content is sent ([details](./docs/fix.md)) |
|
|
@@ -164,7 +169,7 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
164
169
|
| `context-doctor subagents [--days n]` | Which subagents paid for themselves: each one's bill vs the same steps run in the parent session (read through the transcript cache: 15 s to 0.3 s warm on the author's machine) |
|
|
165
170
|
| `context-doctor compactions [--days n]` | Do sessions work worse right after compacting? Re-reads, tool errors and your corrections, before vs after each compaction |
|
|
166
171
|
| `context-doctor cache-misses [--days n]` | Requests that re-wrote the prompt cache within its lifetime (no compaction between, previous context over 20k, over 60% of it written again): priced above the cache-read rate, by model and context size, with the cause where visible and the model versions that miss less; by Claude Code version, with step changes after an upgrade flagged (the 1-hour cache share, the first request's size, a model's miss rate). Then the cold returns, each replayed as billed, compacted on return and kept warm (a cache read every 55 min while away, 4.5 on a 5-minute cache), by time away (<1h to >8h); keeping warm for up to 1, 2, 4 and 8 hours priced with every ping a timer would send; #107157's re-added compacted segment with its re-write; and requests the cache never saw (no cache write, most of the prompt billed as new input, [#111948](https://github.com/anthropics/claude-code/issues/111948)) by Claude Code version, priced against a working cache; `--json` per model and version |
|
|
167
|
-
| `context-doctor limits [--days n] [--report [--copy]]` | Your plan's limits in their own unit: each window's %, pace (from the window's reset when it began within the last hour, or day for a weekly one) and run-out time (Claude's weekly and 5-hour windows, from the readings the plugin's mod, the status line or the proxy record; Ultra has no 5-hour window; Codex's from its rollouts), and % of the limit per 1M tokens of input, cache read, cache write and output, fitted on your readings with the fit's error; too-thin data is said to be thin, never quoted. Each weekly window, reset to reset: API-equivalent $ and tokens per 1%, split by entrypoint (`cli`, `claude-desktop`, `sdk-cli`) and model, and where that moved, by how much and on what date, checked against the model mix (a move the mix explains is said to be the mix, not the limit draining faster). With extra usage on and the weekly limit on pace to run out before its reset, one line says about how many dollars the hours until the reset would go on usage credits (at the last 24 hours' pace, list prices, an estimate). When a limit ran out and Claude Code kept going on usage credits (extra usage), one line says when, how many requests and about how much at API list prices (an estimate), from the API's own headers where the proxy read them, else inferred from a 100% reading and said to be. `--report`: the same as a block to paste into a GitHub issue (no prompts, paths, session or account ids) |
|
|
172
|
+
| `context-doctor limits [--days n] [--report [--copy]]` | Your plan's limits in their own unit: each window's %, pace (from the window's reset when it began within the last hour, or day for a weekly one) and run-out time (Claude's weekly and 5-hour windows, from the readings the plugin's mod, the status line or the proxy record; Ultra has no 5-hour window; Codex's from its rollouts), and % of the limit per 1M tokens of input, cache read, cache write and output, fitted on your readings with the fit's error; too-thin data is said to be thin, never quoted. Each weekly window, reset to reset: API-equivalent $ and tokens per 1%, split by entrypoint (`cli`, `claude-desktop`, `sdk-cli`) and model, and where that moved, by how much and on what date, checked against the model mix (a move the mix explains is said to be the mix, not the limit draining faster). One line says what a full 5-hour window costs of the weekly limit (the weekly rise over the 5-hour rise between the same readings, with its error), about how many fit in a week, and whether that moved, from what to what and at which weekly reset (both windows count the same requests, so the model mix cannot explain it); too-thin data is said to be thin, with no figure, and a plan with no 5-hour window gets no line. Codex's 5-hour and weekly windows the same way. With extra usage on and the weekly limit on pace to run out before its reset, one line says about how many dollars the hours until the reset would go on usage credits (at the last 24 hours' pace, list prices, an estimate). When a limit ran out and Claude Code kept going on usage credits (extra usage), one line says when, how many requests and about how much at API list prices (an estimate), from the API's own headers where the proxy read them, else inferred from a 100% reading and said to be. `--report`: the same as a block to paste into a GitHub issue (no prompts, paths, session or account ids) |
|
|
168
173
|
| `context-doctor cache-plan <request.json> [--calls n] [--out file] [--explicit]` | Where an Anthropic API request should carry `cache_control` (top-level automatic caching for the moving end, unless `--explicit`), and what it saves over n calls; `--out` writes it applied |
|
|
169
174
|
| `context-doctor accuracy` | How much of what you are billed for is visible in your transcript (the fixed harness baseline, per-turn injected content), plus a tokenizer check: real chars/token per model from the API's own counts, next to the ratio the estimator uses |
|
|
170
175
|
| `context-doctor report` | Machine-wide impact report (proxy savings persist across restarts): exact proxy savings, hook activity, how often the cold-resume `/compact` offer was followed by a compaction, recoverable waste in recent sessions |
|
|
@@ -183,6 +188,8 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
183
188
|
|
|
184
189
|
## What's new
|
|
185
190
|
|
|
191
|
+
- **0.53 The 5-hour window's share of the week, warnings for the Claude Code you run, and a price check that checks prices**: `limits` says what a full 5-hour window costs of your weekly limit (the author's: 16.1%, about 6 a week, unchanged since Nov 16), the one limit figure your model mix cannot move, and flags it with a date when it does; Codex's windows too. `fix` warns about an old Claude Code only where your sessions run: the Desktop app's own for the Desktop tools lever, and a terminal install no session used is said to be unused. The Desktop tools lever is priced net of re-loading tools after compactions (claude-code #111915; 22 of the author's 39 compactions). The weekly price check compares every figure on OpenAI's, Anthropic's and Google's price pages with ours, not only that a model has a price: it fixed GPT-6 Rosalind (we charged 1.5x), GPT-6 Astra for Law's missing long-prompt tier and four unpriced healthcare models, and an ending promotion is now its own step so it cannot hide a new red ([details](./ROADMAP.md#shipped-in-0530-the-5-hour-windows-share-of-the-week-warnings-for-the-claude-code-you-run-and-a-price-check-that-checks-prices)).
|
|
192
|
+
- **0.52 An honest empty state, a sample report, and one command up front**: with nothing of yours to replay, `savings` says so, offers `savings --sample`, the same report on generated example sessions, labelled SAMPLE, and says when to run it again; the measured report's footer says it too. `doctor` no longer says "All good" when nothing is protected: the verdict distinguishes no supported app, installed-but-not-wired ("not actively protecting any workflow") and wired. The README leads with one audience and one command, the savings figure captioned as measured on the author's own sessions, the other surfaces in a table. A new bug-report template asks for `doctor` output and `limits --report`, never transcripts; security reports go through private advisories ([details](./ROADMAP.md#shipped-in-0520-an-honest-empty-state-a-sample-report-and-one-command-up-front)).
|
|
186
193
|
- **0.51 Limits that tell the model mix from the limit, proof before a lever, and the cache in the usage pane**: `limits` no longer reads a switch to a hungrier model as the limit draining faster: it says when the move comes from your model mix, and claims a drain only when what is left is 1.5x or more. `limits` and `budget` say when the weekly limit would run out at your current pace and, with extra usage on, about what would go on usage credits before the reset; `budget` counts what credits already paid. The mod records which tools the Desktop app hands over, so `fix` and `doctor` confirm or withdraw `desktop-tools-defer` before you apply it. The `/context-doctor-usage` pane shows how long the cache stays warm and what your next message costs now and after it expires. `cache-misses` and `doctor` count requests the cache never saw (claude-code #111948). Progress summaries are priced in the form Claude Code really sends on your setup; `overhead` gives one total; `doctor` shows the Desktop app's auto-compact offer. Fixes: "1000k" for a 1M window, a flaky download-budget test, the ledger path `doctor` names ([details](./ROADMAP.md#shipped-in-0510-limits-that-tell-the-model-mix-from-the-limit-proof-before-a-lever-and-the-cache-in-the-usage-pane)).
|
|
187
194
|
- **0.50 The Desktop app's own tools, money past the limit, a Codex status line, and two audits**: `fix --apply desktop-tools-defer` has the mod keep the Desktop app's own tools (browser, terminal, sessions, visualize) behind tool search until a session needs them (about $70 a month on the author's history; opt-in, undo with `fix undo`). `limits` says when a plan limit ran out and usage credits paid, `spend` splits dollars inside the plan and past it, `doctor` says whether extra usage is on. `compact-window` and `fix` read the window the Desktop app offered and your answer. Progress summaries are priced on the small model Claude Code 2.1.328 uses. Codex users can turn on a status line served by the MCP server. Gemini 4 Neon is priced. Two audits fixed 14 issues: a crash on a bad date, `limits` reading pace from a burst after a reset, subagent counts that disagreed, a false "contracted rates" warning, and more ([details](./ROADMAP.md#shipped-in-0500-the-desktop-apps-own-tools-money-past-the-limit-a-codex-status-line-and-two-audits)).
|
|
188
195
|
- **0.49.1 The Desktop band off by default, and the rest of Claude Code's figure explained**: the band above the prompt in the Desktop app no longer shows unless `CONTEXT_DOCTOR_MOD_BAND=cold` (a cold return, with **Compact first**) or `always`; the mod still records limits and cost. Subagent replies Claude Code 2.1.284-2.1.299 never finished writing are counted, and the gap to Claude Code's own cost names its prompt suggestions and requests that hung ([details](./ROADMAP.md#shipped-in-0491-the-desktop-band-off-by-default-and-the-rest-of-claude-codes-figure-explained)).
|
|
@@ -190,15 +197,6 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
190
197
|
- **0.48 Directory-ready, quality on your own plan, and MCP SDK v2**: a build of the plugin for Anthropic's directory (strict-clean, with and without the mod); `ab --via claude-code` measures the subagent lever on your own sign-in, no API key; the price check covers OpenAI, Google, Codex and Gemini CLI and warns before a price ends; the MCP server speaks protocol 2026-07-28 to Claude Code and the old handshake to everyone else. Fixed: installing the plugin from the marketplace no longer pulls 80 MB of build tools into Claude Code's cache ([details](./ROADMAP.md#shipped-in-0480-a-directory-ready-plugin-quality-on-your-own-plan-prices-that-change-under-us-and-mcp-sdk-v2)).
|
|
191
198
|
- **0.47 One keystroke to a saving, the mod through `install`, a weekly live check, and an audit of 0.46**: a bare `context-doctor` in a terminal shows the fixes that cost no quality as one monthly total and asks once (the author's: $469 a month: long Bash output to a file, the 1-hour cache). On Claude Code 2.1.286+, `install` enables the plugin, so npm users get the mod too (limit readings and Claude Code's own cost after each turn, Compact first, `/context-doctor-fix`). A weekly canary runs the plugin and mod in the newest Claude Code against a local mock API. `spend` estimates compaction requests and, for terminal sessions, subagent progress summaries, and `fix` can switch the summaries off. An audit fixed, among others, the GitHub Action's YAML (it could not load), programs planted in a cloned repository running on Windows, `pack_context` opening network shares, a re-pricing gap after upgrades, and a test that would have failed from 2026-12-16 ([details](./ROADMAP.md#shipped-in-0470-one-keystroke-the-mod-through-install-a-weekly-live-check-and-an-audit-of-046)).
|
|
192
199
|
- **0.46 Fable 5.2, the Desktop app, and an audit**: Claude Fable 5.2 is priced (0.45 read it 1.5x too high); managed `modelPricing` is honoured; a check catches new models without a price. The plugin's new mod brings limit readings, Claude Code's own cost and `/context-doctor-fix` with Apply and Undo buttons to the Desktop app, VS Code and the terminal, and a cache-expiry band with **Compact first** to the Desktop app and the terminal (Claude Code draws a mod's band on no other surface) ([Desktop](./docs/desktop.md), [details](./ROADMAP.md#shipped-in-0460-fable-52-the-desktop-app-and-an-audit-of-045)).
|
|
193
|
-
- **0.45 Price what is billed, and a security pass**: fast mode, US-only inference, Haiku 5.5's long-prompt rates, web searches and OpenAI's and Gemini's long-prompt tiers are priced per request in every report, and prices that end on a known day say so. A security pass fixed a cloned repository approving its own MCP servers for `overhead --mcp`, a PDF's name running as a command through `pack` on macOS, the agents' API-key configs being packed, and the proxy answering a DNS-rebinding page ([details](./ROADMAP.md#shipped-in-0450-price-what-is-billed-and-a-security-pass-on-044)).
|
|
194
|
-
- **0.44 Workflow agents on the bill, current prices, and an audit**: Claude Code's workflow agents were in no report: on the author's last 30 days $1,494 of $5,542. `spend`, the budget, a session's price, `subagents` and `fix` now count them, and `spend` equals an independent sum of every transcript to the cent. Prices re-read from each provider (Sonnet 5.5's cache read $0.10, gpt-5.5 $5/$30, the gpt-6 family); estimates are labelled. An audit fixed `overhead --mcp` launching a cloned repository's unapproved MCP servers, `pack_context` returning the agents' sign-in files, and more ([details](./ROADMAP.md#shipped-in-0440-workflow-agents-on-the-bill-current-prices-and-an-audit-of-043)).
|
|
195
|
-
- **0.43 Long tool output, `fix` for Codex, and a session's price**: every Bash result stays in the conversation and is re-read on every later message until a compaction; `fix` now replays them at lower caps and, on a yes, sets Claude Code's `bashOutputMaxChars`, so longer output goes to a file the model can still open after a 2,000-character preview (the author's 30 days: $323 less at 8k, 9% of input). `fix` also works for Codex: it replays your rollouts at earlier auto-compact limits and sets `model_auto_compact_token_limit` in `config.toml`, on a machine with only Codex too. And the every-prompt hook now tells you once when a session passes $25, $100 and $500, with what each message costs from there (the author's: 15 sessions passed $25 in 30 days and spent $3,369 after).
|
|
196
|
-
- **0.42 An audit of 0.41**: each Codex request counts once (forks repeat their parent's), the budget no longer double-counts a reply streamed across midnight, unpriced models show as such instead of $0, Cursor is read after it quits, and `CODEX_HOME` is followed everywhere. `fix`'s subagent lever reads agent files the way Claude Code merges them, and every writer of `settings.json` takes one lock, so concurrent runs lose nothing ([details](./ROADMAP.md#shipped-in-0420-an-audit-of-041)).
|
|
197
|
-
- **0.41 One bill, a budget, and the subagents' model**: `context-doctor spend` puts Claude Code (subagents included), Codex, Gemini CLI and Cursor on one bill by tool, project, model and day. `context-doctor budget 50/day` has the every-prompt hook tell you at 50%, 80% and 100%, and with `--block` holds prompts over budget; the status line shows `$12/$50 today`, at about 5 ms a prompt. `fix` gains `subagent-model`: subagents run on your main conversation's model (Opus or Fable included), and `CLAUDE_CODE_SUBAGENT_MODEL` set to Sonnet 5.5 would have cost the author $632 less in 30 days (38% of the subagents' $1,658); it changes the model, so it is applied only when you name it, and `fix undo` reverts it.
|
|
198
|
-
- **0.40 Reports in under a second**: `fix`, `savings`, `compact-window`, `cache-ttl`, `cache-misses` and `overhead` read each transcript once and keep what they took from it in `~/.cache/context-doctor`, so a second run reads only what was appended: `fix` 23.5 s → 0.4 s, `savings` 41 s → 0.6 s on the author's 2.7 GB history, every figure unchanged ([details](./docs/performance.md#the-transcript-cache)). Also from a QA pass on 0.39: `install` then `uninstall` gives every config back byte for byte, and `doctor` warns about an out-of-date skill.
|
|
199
|
-
- **0.39 `fix`, the cache lifetime, the cache clock, and Antigravity**: `context-doctor fix` turns the measurements into changes: every lever ranked by what it would have saved on your own sessions, with what each costs in quality, applied only on a yes, undone with `fix undo`, and re-measured afterwards (`/context-doctor:fix` in the plugin). `cache-ttl` replays your pauses at a 5-minute and a 1-hour prompt cache and sets Claude Code's `promptCacheTtl` to the cheaper one, a price-only change. On Claude Code 2.1.251+ the status line says until when the cache is warm and what going cold costs, `cache-misses` explains misses in Claude Code's own words, and `install` wires Google Antigravity.
|
|
200
|
-
- **0.38 Your limits in their own unit, regressions after upgrades, recall, and a subagent price**: `context-doctor limits` shows each plan window's %, pace and run-out time (Claude Pro/Max through the status line, Codex from its rollouts) and what 1M tokens cost in % of it, fitted on your readings with the error; `savings` then speaks in your limit too. `cache-misses` flags step changes after a Claude Code upgrade, `recall` searches the session's own transcript (compacted turns included), a hook prices a subagent before it starts (never blocking), and `overhead prune` switches off unused MCP servers and skills per project, reversibly. OpenAI caches count as warm for up to 24 hours. An independent QA pass's findings were fixed before the release.
|
|
201
|
-
- **0.37 Desktop chat apps: a handoff, uploads, compact results, and a security pass**: a chat app's history cannot be edited, so the `handoff` prompt (Claude Desktop's **+** menu) has the model write a ≤400-token brief and save it with `save_handoff` (secrets masked, `handoff://latest` to attach in the next chat, the per-turn saving reported: a 52k-token chat drops to ~600). `ask_file` answers from a big file through `pack_context`, which over `--http` also takes ChatGPT uploads; ChatGPT gets compact results. An independent QA pass's eleven findings were fixed with tests; **behind a tunnel, `--http` now needs `--allowed-hosts <tunnel host>`** ([handoff](./docs/handoff.md)).
|
|
202
200
|
|
|
203
201
|
Every release, with the details: [docs/whats-new.md](./docs/whats-new.md).
|
|
204
202
|
|
package/dist/cli.js
CHANGED
|
@@ -27,7 +27,8 @@ import { latestModelComparison } from "./abstore.js";
|
|
|
27
27
|
import { buildImpactReport } from "./impact.js";
|
|
28
28
|
import { measureTokenizer, renderTokenizer } from "./tokenizer-measure.js";
|
|
29
29
|
import { autopilotOff, autopilotOn, autopilotPauseResult, autopilotPaths, autopilotStatus, DEFAULT_AUTOPILOT_PORT } from "./autopilot.js";
|
|
30
|
-
import { estimateSavings, renderSavings, renderShare, savingsRows } from "./savings.js";
|
|
30
|
+
import { estimateSavings, renderSampleSavings, renderSavings, renderShare, savingsRows } from "./savings.js";
|
|
31
|
+
import { writeSampleHistory } from "./sample.js";
|
|
31
32
|
import { prescan } from "./scan.js";
|
|
32
33
|
import { REQUEST_ROWS } from "./coldresume.js";
|
|
33
34
|
import { coldReturns } from "./coldreturns.js";
|
|
@@ -59,7 +60,8 @@ import { analyzeCacheUsage, renderCacheReport } from "./cache.js";
|
|
|
59
60
|
import { renderToolTimings } from "./timing.js";
|
|
60
61
|
import { packContextSemantic, readSources, renderPack } from "./pack.js";
|
|
61
62
|
import { measureBaselines, measureMcpSizes, overheadReport, renderOverhead } from "./overhead.js";
|
|
62
|
-
import { CALL_ROWS, deferrableApp, deferrableConfigured, measureStarts, START_ROWS } from "./starts.js";
|
|
63
|
+
import { CALL_ROWS, deferrableApp, deferrableConfigured, measureStarts, RELOAD_ROWS, sessionHosts, START_ROWS } from "./starts.js";
|
|
64
|
+
import { HOST_ROWS } from "./limits.js";
|
|
63
65
|
import { DEFER_APP_TOOLS_ENV } from "./mod/logic.js";
|
|
64
66
|
import { applySplit, planSplit, renderSplit } from "./split.js";
|
|
65
67
|
import { ciReport, renderCiMarkdown, renderCiText } from "./ci.js";
|
|
@@ -125,7 +127,7 @@ Start here:
|
|
|
125
127
|
Cursor's postToolUse), Claude Code's PreCompact
|
|
126
128
|
hook, which tells each compaction what to keep,
|
|
127
129
|
and Copilot's sessionStart (the standing rules)
|
|
128
|
-
context-doctor savings [--days n] [--share [--copy]]
|
|
130
|
+
context-doctor savings [--days n] [--share [--copy]] [--sample]
|
|
129
131
|
What your recent Claude Code sessions cost, and what
|
|
130
132
|
/compact at cold resumes, autopilot and an earlier
|
|
131
133
|
auto-compact window would save, replayed and priced
|
|
@@ -427,8 +429,8 @@ async function measureFixInputs(days) {
|
|
|
427
429
|
const configured = claudeMcpConfigs(cwd).some((c) => c.scope !== ".mcp.json");
|
|
428
430
|
// Each transcript read once for every replay below; what an earlier run kept is not read again (scan.ts).
|
|
429
431
|
prescan([
|
|
430
|
-
{ paths: claudeTranscripts(days), extractors: [savingsRows(!autopilotOnNow), REQUEST_ROWS, TOOL_OUTPUT_ROWS, START_ROWS, CALL_ROWS] },
|
|
431
|
-
{ paths: subagentTranscripts(Date.now() - days * 86_400_000), extractors: [REQUEST_ROWS, SUBAGENT_ROWS, TOOL_OUTPUT_ROWS, PROGRESS_ROWS, START_ROWS, CALL_ROWS] },
|
|
432
|
+
{ paths: claudeTranscripts(days), extractors: [savingsRows(!autopilotOnNow), REQUEST_ROWS, TOOL_OUTPUT_ROWS, START_ROWS, CALL_ROWS, HOST_ROWS, RELOAD_ROWS] },
|
|
433
|
+
{ paths: subagentTranscripts(Date.now() - days * 86_400_000), extractors: [REQUEST_ROWS, SUBAGENT_ROWS, TOOL_OUTPUT_ROWS, PROGRESS_ROWS, START_ROWS, CALL_ROWS, RELOAD_ROWS] },
|
|
432
434
|
...(setWindow === undefined ? [{ paths: claudeTranscripts(60), extractors: [QUALITY_ROWS] }] : []),
|
|
433
435
|
{ paths: codexRollouts(Date.now() - days * 86_400_000), extractors: [CODEX_COMPACT_ROWS] },
|
|
434
436
|
], replaying.tick);
|
|
@@ -507,7 +509,7 @@ async function measureFixInputs(days) {
|
|
|
507
509
|
userSettings = JSON.parse(readFileSync(join(claudeDir(), "settings.json"), "utf8")) ?? {};
|
|
508
510
|
}
|
|
509
511
|
catch { /* none */ }
|
|
510
|
-
const starts = measureStarts({ days, cwd });
|
|
512
|
+
const starts = measureStarts({ days, cwd, compactions: true });
|
|
511
513
|
const deferrable = configured ? deferrableConfigured(starts) : [];
|
|
512
514
|
const appTools = deferrableApp(starts);
|
|
513
515
|
// CONTEXT_DOCTOR_DEFER_MCP: the user's settings.json env (fix writes it there), else a shell's own value (not the session's copy of a settings value).
|
|
@@ -544,7 +546,7 @@ async function measureFixInputs(days) {
|
|
|
544
546
|
mcpServers: toolSearchOff ? servers.length : 0,
|
|
545
547
|
prune: prunePlan,
|
|
546
548
|
...(deferrable.length ? { mcpDefer: { servers: deferrable, days } } : {}),
|
|
547
|
-
...(appTools.length ? { desktopTools: { servers: appTools.map((s) => ({ name: s.name, tools: s.tools, tokens: s.tokens, starts: s.starts, calledStarts: s.calledStarts, usd: s.usd, unusedUsd: s.unusedUsd, calledUsd: s.calledUsd })), days } } : {}),
|
|
549
|
+
...(appTools.length ? { desktopTools: { servers: appTools.map((s) => ({ name: s.name, tools: s.tools, tokens: s.tokens, starts: s.starts, calledStarts: s.calledStarts, usd: s.usd, unusedUsd: s.unusedUsd, calledUsd: s.calledUsd })), days, ...(starts.compactions ? { compactions: starts.compactions } : {}) } } : {}),
|
|
548
550
|
...(desktopToolsSet ? { desktopToolsSet } : {}),
|
|
549
551
|
// What context-doctor's mod saw Claude Code hand over (apptools.ts): proof the lever reaches the app, or why not.
|
|
550
552
|
...(appToolsSeen.length ? { appToolsSeen } : {}),
|
|
@@ -562,6 +564,8 @@ async function measureFixInputs(days) {
|
|
|
562
564
|
recordProblem,
|
|
563
565
|
// The installs a setting is too new for are named on its fix.
|
|
564
566
|
claudeCodeInstalls: claudeCodeInstallsFromEnv(),
|
|
567
|
+
// …and whether any of the period's sessions ran on them.
|
|
568
|
+
sessionHosts: sessionHosts(claudeTranscripts(days), Date.now() - days * 86_400_000),
|
|
565
569
|
coldResume: { netUsd: Math.max(0, report.coldResumeNetUsd), returns: report.coldResumes, hooked: claudePluginEnabled() || /context-doctor|cli\.js"?\s+hook/.test(JSON.stringify(userSettings.hooks?.UserPromptSubmit ?? [])) },
|
|
566
570
|
...(keepWarm ? { keepWarm } : {}),
|
|
567
571
|
},
|
|
@@ -618,6 +622,7 @@ const FLAGS = [
|
|
|
618
622
|
{ names: ["--dry-run"], set: (a) => { a.dryRun = true; } },
|
|
619
623
|
{ names: ["--copy"], set: (a) => { a.copy = true; } },
|
|
620
624
|
{ names: ["--share"], set: (a) => { a.share = true; } },
|
|
625
|
+
{ names: ["--sample"], set: (a) => { a.sample = true; } },
|
|
621
626
|
{ names: ["--report"], set: (a) => { a.report = true; } },
|
|
622
627
|
{ names: ["--by"], value: "text", set: (a, v) => { a.by = v; } },
|
|
623
628
|
{ names: ["--export"], set: (a) => { a.exportSpend = true; } },
|
|
@@ -1186,6 +1191,8 @@ async function main() {
|
|
|
1186
1191
|
if (args.command === "savings" || (!args.command && process.stdout.isTTY && hasClaudeSessions())) {
|
|
1187
1192
|
// `savings`, and a bare `context-doctor --json` or `--share` in a terminal
|
|
1188
1193
|
// with Claude Code history (what a bare run printed before the one-question screen).
|
|
1194
|
+
if (args.sample && (args.json || args.share))
|
|
1195
|
+
usageError("--sample is a demonstration for the terminal; it does not go with --json or --share.");
|
|
1189
1196
|
const replaying = progressLine("Replaying your Claude Code sessions through autopilot");
|
|
1190
1197
|
// Each transcript read once for every report below; what an earlier run kept is not read again (scan.ts).
|
|
1191
1198
|
prescan([
|
|
@@ -1194,6 +1201,19 @@ async function main() {
|
|
|
1194
1201
|
], replaying.tick);
|
|
1195
1202
|
const report = estimateSavings(args.days ?? 30, {}, undefined, replaying.tick);
|
|
1196
1203
|
replaying.clear();
|
|
1204
|
+
// --sample: the real report on a generated history, said to be a sample.
|
|
1205
|
+
// Never substituted for the real one: with no history the empty report
|
|
1206
|
+
// says so and offers this flag (renderSavings' empty branch).
|
|
1207
|
+
if (args.sample) {
|
|
1208
|
+
const demo = writeSampleHistory();
|
|
1209
|
+
try {
|
|
1210
|
+
console.log(renderSampleSavings(estimateSavings(30, {}, demo.paths)));
|
|
1211
|
+
}
|
|
1212
|
+
finally {
|
|
1213
|
+
demo.cleanup();
|
|
1214
|
+
}
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1197
1217
|
const setWindow = currentCompactWindow();
|
|
1198
1218
|
const measuring = progressLine("Measuring your compactions");
|
|
1199
1219
|
const reread = compactionQuality(60, undefined, measuring.tick).extraRereadTokensPerCompaction;
|
package/dist/doctor.js
CHANGED
|
@@ -1092,12 +1092,35 @@ export async function runDoctor() {
|
|
|
1092
1092
|
const warns = checks.filter((c) => c.status === "warn");
|
|
1093
1093
|
if (fails.length > 0)
|
|
1094
1094
|
process.exitCode = 1;
|
|
1095
|
+
// "All good" must mean something is actually protected. A clean bill on an
|
|
1096
|
+
// empty machine is not that: say what is missing instead of reassuring.
|
|
1097
|
+
// Presence is what each section above already decides: the app's config or
|
|
1098
|
+
// home folder, its binary. (The app rows cannot be re-read for this — the
|
|
1099
|
+
// Claude Code row watches ~/.claude.json while the app lives in ~/.claude.)
|
|
1100
|
+
const home = homedir();
|
|
1101
|
+
const appsDetected = existsSync(claudeDesktopConfigPath()) ||
|
|
1102
|
+
claudeCodePresent() ||
|
|
1103
|
+
existsSync(join(claudeDir(), "settings.json")) ||
|
|
1104
|
+
existsSync(join(home, ".cursor")) ||
|
|
1105
|
+
existsSync(codexDir()) ||
|
|
1106
|
+
geminiCliPresent() ||
|
|
1107
|
+
antigravityPresent() ||
|
|
1108
|
+
copilotPresent() ||
|
|
1109
|
+
devinCheck(home).status !== "skip";
|
|
1110
|
+
// An ok that means a workflow is protected, not internal plumbing (the
|
|
1111
|
+
// ledger, the MCP handshake with itself, optional config files existing).
|
|
1112
|
+
const INTERNAL_OK = new Set(["Ledger", "MCP server handshake", "Project config", "Spend budget", "Desktop chat tool use", "Extra usage", "Desktop app tools", "Desktop compact offer", "Autopilot port"]);
|
|
1113
|
+
const protecting = checks.filter((c) => c.status === "ok" && !INTERNAL_OK.has(c.label));
|
|
1095
1114
|
console.log("");
|
|
1096
1115
|
console.log(fails.length > 0
|
|
1097
1116
|
? `${fails.length} issue(s) found — fixes suggested above.`
|
|
1098
|
-
:
|
|
1099
|
-
?
|
|
1100
|
-
|
|
1117
|
+
: protecting.length === 0
|
|
1118
|
+
? !appsDetected
|
|
1119
|
+
? withInvocation("Installed and healthy, but no supported AI app was found on this machine: nothing is being measured or protected yet. On a machine with Claude Code, Cursor, Codex or Gemini CLI, `context-doctor install` wires it (`context-doctor uninstall` removes it).")
|
|
1120
|
+
: withInvocation("Installed and healthy, but nothing is wired up yet: context-doctor is not actively protecting any workflow. `context-doctor install` wires the apps on this machine (`context-doctor uninstall` removes it).")
|
|
1121
|
+
: warns.length > 0
|
|
1122
|
+
? `No problems; ${warns.length} note(s) marked ! above.`
|
|
1123
|
+
: "All good.");
|
|
1101
1124
|
}
|
|
1102
1125
|
/** "3.18.25" >= major.minor. */
|
|
1103
1126
|
function versionAtLeast(v, major, minor) {
|
package/dist/fix.d.ts
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
*/
|
|
41
41
|
import { type CacheTtlReport, type CurrentTtl } from "./cachettl.js";
|
|
42
42
|
import { type ClaudeCodeInstall } from "./modelswitch.js";
|
|
43
|
+
import type { SessionHost } from "./starts.js";
|
|
43
44
|
import { type ProjectPlan } from "./prune.js";
|
|
44
45
|
import { type DeferEntry } from "./mcpdefer.js";
|
|
45
46
|
import { type ToolsLine } from "./apptools.js";
|
|
@@ -81,6 +82,20 @@ export interface Fix {
|
|
|
81
82
|
tooOld?: string;
|
|
82
83
|
/** More lines under it in the plan (the subagents' model: per agent type). */
|
|
83
84
|
detail?: string[];
|
|
85
|
+
/**
|
|
86
|
+
* desktop-tools-defer: the tool loads compactions would have cost with the
|
|
87
|
+
* servers behind tool search (#111915: loaded tools are deferred again after
|
|
88
|
+
* a compaction). `reloads` counts each server once per compaction, over
|
|
89
|
+
* `compactions` of the period's `ofCompactions`; `usd` is already taken off
|
|
90
|
+
* `savedUsd`.
|
|
91
|
+
*/
|
|
92
|
+
reloadsAfterCompaction?: {
|
|
93
|
+
reloads: number;
|
|
94
|
+
compactions: number;
|
|
95
|
+
ofCompactions: number;
|
|
96
|
+
usd: number;
|
|
97
|
+
unpriced?: number;
|
|
98
|
+
};
|
|
84
99
|
}
|
|
85
100
|
/** The measurements a plan is made from (so the plan itself is testable without a machine's history). */
|
|
86
101
|
export interface FixInputs {
|
|
@@ -158,6 +173,12 @@ export interface FixInputs {
|
|
|
158
173
|
codexCompact?: CodexCompactReport;
|
|
159
174
|
/** The Claude Code installs found here (CLI and desktop app), to name the ones a setting is too new for. */
|
|
160
175
|
claudeCodeInstalls?: ClaudeCodeInstall[];
|
|
176
|
+
/**
|
|
177
|
+
* The entrypoints and versions the period's sessions ran on (starts.ts
|
|
178
|
+
* sessionHosts): an install too old for a setting that ran none of them is
|
|
179
|
+
* still named, with "no session ran there".
|
|
180
|
+
*/
|
|
181
|
+
sessionHosts?: SessionHost[];
|
|
161
182
|
/** model_auto_compact_token_limit at the top of the user's config.toml, as written: never overwritten. */
|
|
162
183
|
codexCompactSet?: {
|
|
163
184
|
raw: string;
|
|
@@ -203,6 +224,15 @@ export interface FixInputs {
|
|
|
203
224
|
calledUsd?: number;
|
|
204
225
|
}>;
|
|
205
226
|
days: number;
|
|
227
|
+
/** The period's compactions and, per compaction, each server called after it with what loading it again would cost (starts.ts; #111915). */
|
|
228
|
+
compactions?: {
|
|
229
|
+
total: number;
|
|
230
|
+
after: Array<Array<{
|
|
231
|
+
server: string;
|
|
232
|
+
usd: number;
|
|
233
|
+
unpriced?: true;
|
|
234
|
+
}>>;
|
|
235
|
+
};
|
|
206
236
|
};
|
|
207
237
|
/** CONTEXT_DOCTOR_DEFER_MCP where the user (or fix) set it: applied, never overwritten. */
|
|
208
238
|
desktopToolsSet?: {
|
package/dist/fix.js
CHANGED
|
@@ -72,6 +72,38 @@ export const DESKTOP_TOOLS_DEFER_SINCE = "2.1.326";
|
|
|
72
72
|
* is not in 2.1.62 and the changelog does not say when it came: not named.
|
|
73
73
|
*/
|
|
74
74
|
const SINCE = { "mcp-defer": MCP_DEFER_SINCE, "desktop-tools-defer": DESKTOP_TOOLS_DEFER_SINCE, "cache-ttl": CACHE_TTL_SINCE, "cache-ttl-subagents": CACHE_TTL_SINCE, "tool-output": BASH_OUTPUT_SINCE, "progress-summaries": PROGRESS_SUMMARIES_SINCE };
|
|
75
|
+
/** Levers that act only in the Desktop app: an old CLI elsewhere on the machine never reads them. */
|
|
76
|
+
const DESKTOP_ONLY = new Set(["desktop-tools-defer"]);
|
|
77
|
+
/**
|
|
78
|
+
* Whether any of the period's sessions could have run on this install: the
|
|
79
|
+
* app's own when a Desktop session ran; a CLI's when a session outside the
|
|
80
|
+
* app ran its version or an older one (the same binary before an update).
|
|
81
|
+
* Unknown (no sessions recorded) counts as ran.
|
|
82
|
+
*/
|
|
83
|
+
function ranThere(c, hosts) {
|
|
84
|
+
if (!hosts?.length)
|
|
85
|
+
return true;
|
|
86
|
+
if (c.source === "desktop app")
|
|
87
|
+
return hosts.some((h) => h.entrypoint === "claude-desktop");
|
|
88
|
+
return hosts.some((h) => h.entrypoint !== "claude-desktop" && (h.version === undefined || compareVersions(h.version, c.version) <= 0));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* "Claude Code 2.1.311 (…) predates this setting …: update it for it to take
|
|
92
|
+
* effect there", and, for an install none of the period's sessions ran on,
|
|
93
|
+
* that none did. Kept rather than dropped: the setting sits in the
|
|
94
|
+
* settings.json every Claude Code here reads, so a session started there
|
|
95
|
+
* tomorrow would still ignore it; it just did not cost the figure above.
|
|
96
|
+
*/
|
|
97
|
+
function tooOldLine(old, since, hosts, days) {
|
|
98
|
+
const one = (n, a, b) => (n === 1 ? a : b);
|
|
99
|
+
const ran = old.filter((c) => ranThere(c, hosts));
|
|
100
|
+
const idle = old.filter((c) => !ranThere(c, hosts));
|
|
101
|
+
const none = `no session ran there in the last ${days} days`;
|
|
102
|
+
if (!ran.length)
|
|
103
|
+
return `${describeInstalls(idle)} ${one(idle.length, "predates", "predate")} this setting (Claude Code ${since}+) and ${one(idle.length, "ignores", "ignore")} it, but ${none}: update ${one(idle.length, "it", "them")} before you use ${one(idle.length, "it", "them")} again`;
|
|
104
|
+
const line = `${describeInstalls(ran)} ${one(ran.length, "predates", "predate")} this setting (Claude Code ${since}+) and ${one(ran.length, "ignores", "ignore")} it: update ${one(ran.length, "it", "them")} for it to take effect there`;
|
|
105
|
+
return idle.length ? `${line}; ${describeInstalls(idle)} ${one(idle.length, "is", "are")} older too, but ${none}` : line;
|
|
106
|
+
}
|
|
75
107
|
/** Below this a priced fix is not worth a setting. */
|
|
76
108
|
const MIN_USD = 1;
|
|
77
109
|
export const money = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : `$${n.toFixed(2)}`);
|
|
@@ -312,7 +344,18 @@ export function planFixes(i) {
|
|
|
312
344
|
const verdict = i.appToolsSeen ? appToolsVerdict(i.appToolsSeen, candidates.map((s) => s.name)) : undefined;
|
|
313
345
|
const pick = verdict ? candidates.filter((s) => verdict.reach.some((r) => r.server === s.name)) : candidates;
|
|
314
346
|
const kept = dt.servers.filter((s) => !pick.includes(s)).map((s) => s.name);
|
|
315
|
-
const
|
|
347
|
+
const gross = pick.reduce((t, s) => t + s.unusedUsd, 0);
|
|
348
|
+
// #111915: after a compaction, a tool loaded through tool search is deferred again, so the first call to each
|
|
349
|
+
// moved server after a compaction loads it once more. Each such load is taken off the figure.
|
|
350
|
+
const names = new Set(pick.map((s) => s.name));
|
|
351
|
+
const hit = (dt.compactions?.after ?? []).map((c) => c.filter((r) => names.has(r.server))).filter((c) => c.length);
|
|
352
|
+
const reloadUsd = hit.reduce((t, c) => t + c.reduce((x, r) => x + r.usd, 0), 0);
|
|
353
|
+
const reloads = hit.reduce((t, c) => t + c.length, 0);
|
|
354
|
+
const unpricedReloads = hit.reduce((t, c) => t + c.filter((r) => r.unpriced).length, 0);
|
|
355
|
+
const usd = gross - reloadUsd;
|
|
356
|
+
const after = reloads
|
|
357
|
+
? `. Less ${money(reloadUsd)}${unpricedReloads ? ` (${unpricedReloads} on a model with no price, not counted)` : ""} for loading them again after compactions: a compaction puts loaded tools back behind tool search, and ${hit.length} of the ${dt.compactions.total} compactions in those days were followed by a call to one of them (${reloads} load${reloads === 1 ? "" : "s"}, a server once per compaction, each priced as one more request at the context then plus the tool's definition)`
|
|
358
|
+
: "";
|
|
316
359
|
if (verdict && candidates.length && !pick.length) {
|
|
317
360
|
// Withdrawn before anyone applies it, with the reason the mod saw.
|
|
318
361
|
fixes.push({ id: "desktop-tools-defer", title: "The Desktop app's own tools behind tool search", basis: "", quality: "", change: "", state: "not-here", note: `not offered: ${verdictLines(verdict).join(" ")}` });
|
|
@@ -326,8 +369,9 @@ export function planFixes(i) {
|
|
|
326
369
|
id: "desktop-tools-defer",
|
|
327
370
|
title: `Keep the Desktop app's own tools behind tool search (${pick.map((s) => s.name).join(", ")})`,
|
|
328
371
|
savedUsd: usd,
|
|
329
|
-
basis: `the Desktop app sends these tools' definitions whole into every session and subagent start, and each step re-reads them: ${pick.map((s) => `${s.name} ~${s.tokens < 1000 ? s.tokens : k(s.tokens)} tokens, called in ${s.calledStarts} of ${s.starts} starts`).join("; ")}. The figure is what that cost in the ${i.desktopTools.days} days' starts that never called them (${money(all)} counting the ones that did${exact ? "" : ", as overhead lists it"}; those would load a tool through tool search instead)`,
|
|
330
|
-
|
|
372
|
+
basis: `the Desktop app sends these tools' definitions whole into every session and subagent start, and each step re-reads them: ${pick.map((s) => `${s.name} ~${s.tokens < 1000 ? s.tokens : k(s.tokens)} tokens, called in ${s.calledStarts} of ${s.starts} starts`).join("; ")}. The figure is what that cost in the ${i.desktopTools.days} days' starts that never called them (${money(all)} counting the ones that did${exact ? "" : ", as overhead lists it"}; those would load a tool through tool search instead)${after}`,
|
|
373
|
+
...(dt.compactions ? { reloadsAfterCompaction: { reloads, compactions: hit.length, ofCompactions: dt.compactions.total, usd: reloadUsd, ...(unpricedReloads ? { unpriced: unpricedReloads } : {}) } } : {}),
|
|
374
|
+
quality: `Claude loads one of these tools through tool search the first time a conversation needs it, and again after each compaction (Claude Code issue #111915, reported on 2.1.321 to 2.1.331: a compaction puts loaded tools back behind tool search; those loads are taken off the figure): one more step each time. Kept in front: ${[...KEEP_APP_SERVERS, ...kept.filter((n) => !KEEP_APP_SERVERS.includes(n))].join(", ")} (called in most sessions). It takes effect in new sessions only, so no running conversation's cache is written again. Not measured here: applied only when named`,
|
|
331
375
|
change: `${where}: env.${DEFER_APP_TOOLS_ENV} = "${value}", read by context-doctor's mod (its plugin, Claude Code ${DESKTOP_TOOLS_DEFER_SINCE}+)`,
|
|
332
376
|
state: "available",
|
|
333
377
|
value,
|
|
@@ -343,9 +387,11 @@ export function planFixes(i) {
|
|
|
343
387
|
if (o?.length && f.state === "available")
|
|
344
388
|
f.overriddenBy = o;
|
|
345
389
|
const since = SINCE[f.id];
|
|
346
|
-
|
|
390
|
+
// A lever that acts only in the Desktop app is read only by the Claude Code the app bundles.
|
|
391
|
+
const installs = (i.claudeCodeInstalls ?? []).filter((c) => !DESKTOP_ONLY.has(f.id) || c.source === "desktop app");
|
|
392
|
+
const old = since && f.state === "available" ? installs.filter((c) => compareVersions(c.version, since) < 0) : [];
|
|
347
393
|
if (old.length)
|
|
348
|
-
f.tooOld =
|
|
394
|
+
f.tooOld = tooOldLine(old, since, i.sessionHosts, i.days);
|
|
349
395
|
}
|
|
350
396
|
const rank = (f) => (f.state === "available" ? 0 : f.state === "applied" ? 2 : 3) + (f.savedUsd === undefined ? 1 : 0);
|
|
351
397
|
return fixes.sort((a, b) => rank(a) - rank(b) || (b.savedUsd ?? 0) - (a.savedUsd ?? 0));
|
package/dist/limits.d.ts
CHANGED
|
@@ -516,6 +516,78 @@ export declare function reportModel(model: string | undefined): string;
|
|
|
516
516
|
* stretches): `cause` says whether the limit moved or the mix did.
|
|
517
517
|
*/
|
|
518
518
|
export declare function slopeChanges(windows: ResetWindow[], usage?: UsagePoint[], readings?: LimitReading[], stretchMs?: number): SlopeChange[];
|
|
519
|
+
/**
|
|
520
|
+
* Both of a plan's windows count the same requests, so the ratio of their
|
|
521
|
+
* rises is the one limit figure the model mix cancels out of: a move in it
|
|
522
|
+
* is a move in one of the two limits, never in your models. People measured
|
|
523
|
+
* it moving on Pro from 10% to 12% of the week per full 5-hour window
|
|
524
|
+
* (claude-code#111886, #111759, #111593). Each 5-hour period is paired with
|
|
525
|
+
* the weekly reading taken at the same moment: the line the recorder wrote
|
|
526
|
+
* beside it, or, where the weekly % had not moved (the recorder writes a
|
|
527
|
+
* window only when it moves, and again every 15 minutes), the weekly line
|
|
528
|
+
* before it. The ratio is the sum of the weekly rises over the sum of the
|
|
529
|
+
* 5-hour rises, per weekly window and pooled; its error is the larger of the
|
|
530
|
+
* whole-percent steps' and the spread between 5-hour windows'.
|
|
531
|
+
*/
|
|
532
|
+
/** One 5-hour period's rise and the weekly limit's rise between the same two moments. */
|
|
533
|
+
export interface ExchangeSample {
|
|
534
|
+
from: number;
|
|
535
|
+
to: number;
|
|
536
|
+
fivePct: number;
|
|
537
|
+
weekPct: number;
|
|
538
|
+
}
|
|
539
|
+
/** A ratio over some 5-hour windows, or why there is none worth quoting. */
|
|
540
|
+
export interface ExchangeFigure {
|
|
541
|
+
/** 5-hour windows with weekly readings beside them, and the points each limit rose over them. */
|
|
542
|
+
windows: number;
|
|
543
|
+
fivePct: number;
|
|
544
|
+
weekPct: number;
|
|
545
|
+
/** % of the weekly limit a full 5-hour window (100 points) costs: 100 × weekly rise / 5-hour rise. */
|
|
546
|
+
pct?: number;
|
|
547
|
+
/** Its standard error, in points of the weekly limit. */
|
|
548
|
+
err?: number;
|
|
549
|
+
/** Why it is not quoted, when it is not (pct may still be there, too loose to say). */
|
|
550
|
+
why?: string;
|
|
551
|
+
}
|
|
552
|
+
/** One weekly window, reset to reset, and the ratio inside it. */
|
|
553
|
+
export interface ExchangeWeek extends ExchangeFigure {
|
|
554
|
+
start: number;
|
|
555
|
+
resetsAt: number;
|
|
556
|
+
current: boolean;
|
|
557
|
+
}
|
|
558
|
+
/** A move in the ratio between two weekly windows that each have one. */
|
|
559
|
+
export interface ExchangeMove {
|
|
560
|
+
/** The later window's start, and the earlier one's reset (equal unless a window is missing between them). */
|
|
561
|
+
at: number;
|
|
562
|
+
prevEnd: number;
|
|
563
|
+
pctBefore: number;
|
|
564
|
+
errBefore: number;
|
|
565
|
+
pctAfter: number;
|
|
566
|
+
errAfter: number;
|
|
567
|
+
/** How many standard errors apart. */
|
|
568
|
+
sigma: number;
|
|
569
|
+
}
|
|
570
|
+
/** One app's exchange: the figure since its last move (or since the first reading), each weekly window, and the moves. */
|
|
571
|
+
export interface Exchange extends ExchangeFigure {
|
|
572
|
+
app: "claude" | "codex";
|
|
573
|
+
/** "Claude", "Codex (plus)". */
|
|
574
|
+
label: string;
|
|
575
|
+
/** The two windows paired ("five_hour" and "seven_day"; Codex's 300- and 10080-minute ones). */
|
|
576
|
+
short: string;
|
|
577
|
+
long: string;
|
|
578
|
+
/** The first moment the figure counts from. */
|
|
579
|
+
since: number;
|
|
580
|
+
/** Weekly windows with a figure of their own: two or more were compared. */
|
|
581
|
+
compared: number;
|
|
582
|
+
weeks: ExchangeWeek[];
|
|
583
|
+
moves: ExchangeMove[];
|
|
584
|
+
}
|
|
585
|
+
/** One app's exchange from its short (5-hour) and long (weekly) readings; undefined when either is missing (Ultra has no 5-hour window). */
|
|
586
|
+
export declare function exchangeOf(short: LimitReading[], long: LimitReading[], opts: {
|
|
587
|
+
app: "claude" | "codex";
|
|
588
|
+
label: string;
|
|
589
|
+
now?: number;
|
|
590
|
+
}): Exchange | undefined;
|
|
519
591
|
export interface LimitsReport {
|
|
520
592
|
days: number;
|
|
521
593
|
now: number;
|
|
@@ -533,6 +605,8 @@ export interface LimitsReport {
|
|
|
533
605
|
claudeWindows: string[];
|
|
534
606
|
/** How many Claude readings each recorder wrote ("statusline", "mod", "proxy"; "earlier" for lines from before 0.49). */
|
|
535
607
|
claudeSources: Record<string, number>;
|
|
608
|
+
/** What a full 5-hour window costs of the weekly limit, Claude's then Codex's (exchangeOf); none on a plan without a 5-hour window. */
|
|
609
|
+
exchange: Exchange[];
|
|
536
610
|
}
|
|
537
611
|
export interface LimitsOptions {
|
|
538
612
|
now?: number;
|
|
@@ -586,6 +660,12 @@ export declare function limitSavingsLines(fit: LimitFit | undefined, items: Arra
|
|
|
586
660
|
* Code), or the autopilot proxy (from the API's rate-limit headers).
|
|
587
661
|
*/
|
|
588
662
|
export declare const HOW_TO_RECORD = "To record them: `context-doctor install` (the plugin's mod writes them after each turn, Claude Code 2.1.286+; `install --statusline` on older ones), or `context-doctor autopilot on` (its proxy reads them from the API's replies).";
|
|
663
|
+
/**
|
|
664
|
+
* The exchange in one line: what a full 5-hour window costs of the weekly
|
|
665
|
+
* limit, its error, how many fit in a week, and whether it moved (from what
|
|
666
|
+
* to what, and when). Too thin: says so, with no figure.
|
|
667
|
+
*/
|
|
668
|
+
export declare function exchangeLine(e: Exchange): string;
|
|
589
669
|
/** "claude-fable-5-2" as "Fable 5.2"; any other id as it is. */
|
|
590
670
|
export declare function modelLabel(key: string | undefined): string;
|
|
591
671
|
/**
|