context-doctor 0.48.0 → 0.49.1
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 +16 -14
- package/dist/abclaude.js +1 -1
- package/dist/budget.d.ts +5 -2
- package/dist/budget.js +21 -7
- package/dist/cache.js +3 -3
- package/dist/cachemisses.d.ts +3 -0
- package/dist/cachemisses.js +8 -0
- package/dist/cachettl.js +6 -2
- package/dist/ccost.d.ts +195 -0
- package/dist/ccost.js +400 -0
- package/dist/cli.js +135 -32
- package/dist/cline.d.ts +41 -0
- package/dist/cline.js +174 -0
- package/dist/coldresume.d.ts +11 -0
- package/dist/coldresume.js +3 -3
- package/dist/coldreturns.d.ts +145 -0
- package/dist/coldreturns.js +282 -0
- package/dist/compactcost.d.ts +10 -4
- package/dist/compactcost.js +12 -7
- package/dist/compactwindow.js +2 -2
- package/dist/copilotusage.d.ts +78 -0
- package/dist/copilotusage.js +193 -0
- package/dist/doctor.d.ts +6 -0
- package/dist/doctor.js +17 -4
- package/dist/fix.d.ts +28 -2
- package/dist/fix.js +49 -5
- package/dist/install.js +1 -1
- package/dist/limits.d.ts +232 -14
- package/dist/limits.js +739 -33
- package/dist/mcp.js +19 -19
- package/dist/mcpdefer.d.ts +47 -0
- package/dist/mcpdefer.js +91 -0
- package/dist/mod/api.d.ts +72 -2
- package/dist/mod/api.js +5 -1
- package/dist/mod/logic.d.ts +289 -16
- package/dist/mod/logic.js +362 -38
- package/dist/mod/register.d.ts +37 -2
- package/dist/mod/register.js +290 -9
- package/dist/modmeasure.d.ts +6 -4
- package/dist/modmeasure.js +8 -4
- package/dist/opencode.d.ts +57 -0
- package/dist/opencode.js +234 -0
- package/dist/orgrates.d.ts +7 -0
- package/dist/orgrates.js +19 -0
- package/dist/overhead.d.ts +3 -0
- package/dist/overhead.js +5 -1
- package/dist/pricing.d.ts +59 -2
- package/dist/pricing.js +130 -10
- package/dist/proxy.d.ts +8 -1
- package/dist/proxy.js +13 -1
- package/dist/savings.d.ts +5 -1
- package/dist/savings.js +11 -5
- package/dist/scan.d.ts +3 -1
- package/dist/scan.js +8 -1
- package/dist/sessionprice.d.ts +5 -0
- package/dist/sessionprice.js +5 -1
- package/dist/sidecost.d.ts +65 -0
- package/dist/sidecost.js +117 -0
- package/dist/spend.d.ts +94 -3
- package/dist/spend.js +251 -23
- package/dist/spendplace.d.ts +40 -0
- package/dist/spendplace.js +93 -0
- package/dist/spendteam.d.ts +160 -0
- package/dist/spendteam.js +286 -0
- package/dist/starts.d.ts +106 -0
- package/dist/starts.js +406 -0
- package/dist/statusline.d.ts +2 -2
- package/dist/statusline.js +2 -2
- package/dist/subagentmodel.js +9 -7
- package/dist/subagentpay.d.ts +31 -2
- package/dist/subagentpay.js +232 -68
- package/dist/subagents.js +3 -3
- package/dist/tasks.js +3 -2
- package/dist/tooloutput.js +5 -5
- package/dist/usagepane.d.ts +77 -0
- package/dist/usagepane.js +287 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ AI agents re-send their whole context on every message: old tool output, pasted
|
|
|
9
9
|
```bash
|
|
10
10
|
npx context-doctor savings # what your recent sessions cost, and what each fix would have saved
|
|
11
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 and
|
|
12
|
+
npx context-doctor spend # one bill across Claude Code, Codex, Gemini CLI, Cursor, Copilot CLI, OpenCode and Cline
|
|
13
13
|
```
|
|
14
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">
|
|
@@ -30,17 +30,17 @@ Pick where you work. Each takes about a minute and is fully reversible.
|
|
|
30
30
|
| **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
31
|
| **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
32
|
| **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.
|
|
33
|
+
| **GitHub pull requests** | `uses: KushalP1/context-doctor@v0.49.1` comments how much a PR grows CLAUDE.md, AGENTS.md and rules, and can fail over a budget ([setup](./docs/ci.md)) |
|
|
34
34
|
|
|
35
35
|
## What it does
|
|
36
36
|
|
|
37
37
|
**Measure, in dollars, on your own history** ([profiling](./docs/profiling.md))
|
|
38
|
-
- `spend`: one bill across Claude Code (subagents and workflow agents included), Codex, Gemini CLI and
|
|
38
|
+
- `spend`: one bill across Claude Code (subagents and workflow agents included), Codex, Gemini CLI, Cursor, Copilot CLI, OpenCode and Cline, by tool, project, model and day, as billed at list rates ([spend and budget](./docs/spend.md)).
|
|
39
39
|
- `savings`: what your recent Claude Code sessions cost and what each fix below would have saved, replayed request by request against what you were billed.
|
|
40
40
|
- `overhead`: what every request re-reads before your message (system prompt, tools, MCP servers, CLAUDE.md, rules, memory), each file priced per month.
|
|
41
41
|
- `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
|
-
- `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.
|
|
43
|
-
- `limits`: your plan's 5-hour
|
|
42
|
+
- `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. `limits --report` prints it as a block to paste into a bug report, with no prompts, paths or ids.
|
|
44
44
|
- `cache-plan <request.json>`: where an Anthropic API request should carry `cache_control`, and what it saves over N calls.
|
|
45
45
|
- `session`, `watch`, `analyze`, `report`, `dashboard`: token breakdown and wasted-context findings for any session, conversation file or agent trace.
|
|
46
46
|
|
|
@@ -107,7 +107,7 @@ On a Claude subscription you do not pay list price; the same tokens come out of
|
|
|
107
107
|
| Where you work | Automatic, every request | What you get on top |
|
|
108
108
|
|---|---|---|
|
|
109
109
|
| **Claude Code** in the terminal, VS Code or JetBrains | **Autopilot** clears stale tool output (cold cache only, never more expensive). **Hook** on every prompt: real context size, largest waste, and a `/compact` offer when you return to a large session after the cache expired. **Compaction hook** on every compaction. **`compact-window`**, if you set one | Install via npm or as a **plugin**. Status bar context meter, `/context-doctor:savings`, `session`, `watch`, `report`, dashboard, MCP tools |
|
|
110
|
-
| **Claude Code** in the desktop app's Code tab | **Hooks**, as above, the cold-resume `/compact` offer shown to you as well as the model. **`compact-window`**, if you set one: Claude Code compacts earlier by itself. Not autopilot: the app sets its own API address and ignores the one in settings | Same as above |
|
|
110
|
+
| **Claude Code** in the desktop app's Code tab | **Hooks**, as above, the cold-resume `/compact` offer shown to you as well as the model. **`compact-window`**, if you set one: Claude Code compacts earlier by itself. Not autopilot: the app sets its own API address and ignores the one in settings | Same as above, and the plugin's mod: `/context-doctor-usage`, the usage view the app dropped (context ring, limit windows, tokens and dollars by model for today, 7 and 30 days, running subagents), and `/context-doctor-fix` ([Desktop](./docs/desktop.md)) |
|
|
111
111
|
| **Cursor** (agent) | A native **after-tool-call hook** (`~/.cursor/hooks.json`): in a heavy chat the agent gets the same hygiene guidance and the largest waste, once per 40% of growth. (Cursor's prompt hook can only allow or block a prompt, so this is the event where guidance reaches the model) | MCP tools, editor status bar extension, `cursor` profiler. With your own OpenAI key, autopilot too via a tokened tunnel ([how](./docs/proxy.md#putting-the-proxy-on-a-public-url-cursor-with-your-own-openai-key-remote-apps)) |
|
|
112
112
|
| **Codex** (ChatGPT app's Codex tab, IDE extension, CLI) | Every-prompt hook with the API's own token counts | MCP tools, skill, `session` reads Codex rollouts. On an API key, autopilot too (`autopilot on` sets `openai_base_url` in `~/.codex/config.toml`; Codex no longer reads `OPENAI_BASE_URL`) |
|
|
113
113
|
| **Gemini CLI** | Every-prompt hook (`BeforeAgent`) with the API's own token counts. On an API key, autopilot too: `GOOGLE_GEMINI_BASE_URL` set to the proxy on `127.0.0.1:8787`, plain HTTP (Google sign-in traffic goes elsewhere) | MCP tools, `session` and `watch` read its chats, `overhead` sizes GEMINI.md |
|
|
@@ -135,8 +135,8 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
135
135
|
| Command | What it does |
|
|
136
136
|
|---|---|
|
|
137
137
|
| `context-doctor install` / `uninstall` | Wire (or remove) everything it finds: the MCP server for Claude Desktop, Claude Code, Cursor, Codex, Gemini CLI, Google Antigravity and GitHub Copilot; the Agent Skill (Claude Code, Codex, Antigravity); the every-prompt hook (Claude Code, Codex, Gemini CLI's `BeforeAgent`, Cursor's `postToolUse`, `postToolUseFailure` and `sessionStart`); Claude Code's `PreCompact`, `SessionStart`, `PreToolUse` (the subagent price) and, on 2.1.251+, `PreModelSwitch` hooks; Copilot's `sessionStart` (the standing rules). `--statusline` adds the status bar line ([details](./docs/install.md)) |
|
|
138
|
-
| `context-doctor fix [--apply ids\|all] [--share]` / `fix undo` | Every lever ranked by what it would have saved on your last 30 days (compact earlier, the cache lifetime, autopilot, MCP tool search, unused servers, the subagents' model, long Bash output to a file, Codex's auto-compact limit), with what each costs in quality; applies one only on a yes (the subagents' model only when named), `fix undo` reverts exactly what it changed, later runs show what each saved since ([details](./docs/fix.md)) |
|
|
139
|
-
| `context-doctor spend [--days n] [--share]` | One bill across every tool on this machine: Claude Code (main conversation and subagents), Codex, Gemini CLI
|
|
138
|
+
| `context-doctor fix [--apply ids\|all] [--share]` / `fix undo` | Every lever ranked by what it would have saved on your last 30 days (compact earlier, the cache lifetime, autopilot, MCP tool search, MCP servers set to load up front, unused servers, the subagents' model, long Bash output to a file, Codex's auto-compact limit), with what each costs in quality; applies one only on a yes (the subagents' model only when named), `fix undo` reverts exactly what it changed, later runs show what each saved since ([details](./docs/fix.md)) |
|
|
139
|
+
| `context-doctor spend [--days n] [--by repo\|branch] [--share] [--export]`, `spend merge <folder>` | One bill across every tool on this machine: Claude Code (main conversation and subagents), Codex, Gemini CLI, Cursor (an estimate: no cache split), Copilot CLI (with the AI credits it counted), OpenCode and Cline, by tool, project (or repository or branch), model and day; `--export` writes a file of totals (no prompt or path) and `spend merge` adds up a team's files, with a month-end forecast, with what drives it, and Claude Code's own figure (its `cost-state`) beside ours with what the gap is made of: its side requests, prompt suggestions and requests that hung and were sent again, named; subagent output Claude Code 2.1.284-2.1.299 never settled in its rows, estimated from the content and counted ([docs](./docs/spend.md)) |
|
|
140
140
|
| `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 ([docs](./docs/spend.md#a-budget-the-hook-applies-context-doctor-budget)) |
|
|
141
141
|
| `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 |
|
|
142
142
|
| `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. `--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 |
|
|
@@ -148,23 +148,23 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
148
148
|
| `context-doctor handoff [list\|show <id>\|latest] [--copy]` | Handoffs saved from chat apps (the `handoff` prompt or `save_handoff`): list them, print one, or copy it to paste as a new chat's first message ([handoff](./docs/handoff.md)) |
|
|
149
149
|
| `context-doctor mcp [--http]` | The MCP server as a subcommand, for clients and registries that launch `npx -y context-doctor mcp` |
|
|
150
150
|
| `context-doctor-mcp` | The MCP server itself — stdio by default (what the installer wires); `--http [--port 8808] [--host H] [--allowed-hosts names] [--allowed-origins list] [--store-handoffs]` serves streamable HTTP at `/mcp` for URL-based clients like ChatGPT developer-mode connectors (only for the host names it knows: behind a tunnel, pass its name to `--allowed-hosts`) |
|
|
151
|
-
| `context-doctor session [file]` | Profile a Claude Code session: live context, findings, **measured tokens and prompt-cache economics**, **where the wall clock went** per tool, output's and reasoning's share of the cost, repeated identical (polling) tool calls priced,
|
|
151
|
+
| `context-doctor session [file]` | Profile a Claude Code session: live context, findings, **measured tokens and prompt-cache economics**, **where the wall clock went** per tool, output's and reasoning's share of the cost, repeated identical (polling) tool calls priced, **what its subagents cost** (their own windows, your bill; never in the parent's profile), and **Claude Code's own figure for it** (its `cost-state`) beside ours, with what the gap is made of. Also reads Codex rollouts, Gemini CLI chats and ChatGPT data exports (`conversations.json`); `--list` to browse |
|
|
152
152
|
| `context-doctor watch [file]` | Live monitor of a growing session transcript or agent trace (Claude Code / Codex JSONL, or a plain OpenAI/Anthropic conversation JSON file): token/cost line per change, findings as they appear |
|
|
153
153
|
| `context-doctor cursor [--list]` | Profile a chat from Cursor's local history (both storage formats) |
|
|
154
154
|
| `context-doctor analyze <file>` | Profile a conversation: token breakdown, findings, cost + latency estimates. `--exact` adds a true count; `--fail-over-budget` exits 1 on a breach, for CI |
|
|
155
155
|
| `context-doctor optimize <file>` | Apply the safe fixes; add `--strategy trim-tool-calls` for big inline file writes, `--strategy prune-history` for consented lossy compaction ([what each does](./docs/detectors.md)) |
|
|
156
156
|
| `context-doctor diff <before> <after>` | Compare two profiles: what moved by category, which findings were resolved or introduced, and what it saves in money and latency |
|
|
157
|
-
| `context-doctor overhead [--days n] [--mcp]` | What every request re-reads before your message: measured first-request size (Claude Code, Codex and Gemini CLI sessions), each memory file (CLAUDE.md and imports, rules, auto memory, AGENTS.md, Cursor rules, GEMINI.md) priced per month, MCP calls per server; `--mcp` sizes each configured server's tool definitions and flags unused ones |
|
|
157
|
+
| `context-doctor overhead [--days n] [--mcp]` | What every request re-reads before your message: measured first-request size (Claude Code, Codex and Gemini CLI sessions), each memory file (CLAUDE.md and imports, rules, auto memory, AGENTS.md, Cursor rules, GEMINI.md) priced per month, MCP calls per server; each session's and subagent's start per entrypoint (Desktop app, terminal, SDK) and subagent type, priced over the period, with the MCP tool definitions sent whole and whether any setting defers them; `--mcp` sizes each configured server's tool definitions and flags unused ones |
|
|
158
158
|
| `context-doctor overhead prune [--days n] [--write] [--undo]` | Per project, the MCP servers and skills its sessions never used in n days; `--write` switches them off for this folder's project in its `.claude/settings.local.json` (backup kept, every entry recorded), `--undo` takes exactly those out. Never the app's connectors, plugins, or context-doctor itself |
|
|
159
159
|
| `context-doctor overhead split <file> [--min-tokens n] [--write]` | Move a memory file's big or code-heavy sections word for word to `<name>.reference.md`, leaving pointers; indexes stay. A plan until `--write`, which backs up first |
|
|
160
160
|
| `context-doctor pack <files\|dirs\|-> -q "…"` | Only the chunks of big documents, logs or code a question needs, ranked and fit to `--max-tokens` (default 4000). No query: an outline; `--ids a#2,b#5` picks chunks from it. `--semantic` also ranks by meaning with a local Ollama model. Offline, no key |
|
|
161
161
|
| `context-doctor recall "<query>" [--session <id\|path>]` | Search this session's own transcript on disk (Claude Code or Codex; turns before a compaction and tool output cleared from the context included) and print the best excerpts with time and position, secrets masked. Never another project's session unless named with `--session`. Also the `recall` MCP tool |
|
|
162
162
|
| `context-doctor tasks [--days n]` | Cost per commit, per project: each session priced from its recorded usage against the commits it made |
|
|
163
163
|
| `context-doctor reads [--days n] [--limit n]` | Files read into session after session: reads, tokens, cost, and whether a CLAUDE.md summary or `pack` pays |
|
|
164
|
-
| `context-doctor subagents [--days n]` | Which subagents paid for themselves: each one's bill vs the same steps run in the parent session |
|
|
164
|
+
| `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
165
|
| `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
|
-
| `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); `--json` per model and version |
|
|
167
|
-
| `context-doctor limits [--days n]` | Your plan's limits in their own unit: each window's %, pace and run-out time (Claude's 5-hour
|
|
166
|
+
| `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; and #107157's re-added compacted segment with its re-write; `--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 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. `--report`: the same as a block to paste into a GitHub issue (no prompts, paths, session or account ids) |
|
|
168
168
|
| `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
169
|
| `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
170
|
| `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 +183,8 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
183
183
|
|
|
184
184
|
## What's new
|
|
185
185
|
|
|
186
|
+
- **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)).
|
|
187
|
+
- **0.49 Count what Claude Code counts, cold returns, limits you can paste, a Desktop usage pane, and teams**: `spend` and `doctor` show Claude Code's own cost (its `cost-state`) beside ours, 2% apart on the author's 30 days, and count the advisor's calls and replies a server-side fallback replaced. `cache-misses` replays every return after the cache expired three ways (as billed, compacted, kept warm) by time away (the author's: $894 in 183 returns), and the mod's `/context-doctor-keep-warm` keeps it warm on request only, capped in hours and dollars. `overhead` prices every session's and subagent's start ($455 a month here) and `fix` gains `mcp-defer`. `limits` gives dollars per 1% per weekly reset with the moves dated, `limits --report` a block for a bug report, and handles Ultra (no 5-hour window). `/context-doctor-usage` is a usage pane in the Desktop app. `spend` reads Copilot CLI, OpenCode and Cline, splits `--by repo|branch`, and `--export` / `spend merge` add up a team's totals with no prompt or path ([details](./ROADMAP.md#shipped-in-0490-count-what-claude-code-counts-cold-returns-limits-you-can-paste-a-desktop-usage-pane-and-teams)).
|
|
186
188
|
- **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)).
|
|
187
189
|
- **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)).
|
|
188
190
|
- **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)).
|
|
@@ -213,7 +215,7 @@ Every release, with the details: [docs/whats-new.md](./docs/whats-new.md).
|
|
|
213
215
|
- [Library](./docs/library.md): `profileConversation`, `optimizeConversation`, `packContext`, `withContextDoctor`
|
|
214
216
|
- [Budgets and CI](./docs/ci.md): the GitHub Action and `.contextdoctorrc`
|
|
215
217
|
- [Privacy](./docs/privacy.md) and [the directory submission](./docs/directory-submission.md): what the plugin reads, writes and sends; the package for Anthropic's plugin directory
|
|
216
|
-
- [Desktop app and VS Code](./docs/desktop.md): the plugin's mod: limit readings, Claude Code's own cost and `/context-doctor-
|
|
218
|
+
- [Desktop app and VS Code](./docs/desktop.md): the plugin's mod: limit readings, Claude Code's own cost, `/context-doctor-fix`, `/context-doctor-usage` (the context ring, limit windows, tokens and dollars by model, running subagents) and `/context-doctor-keep-warm` (Desktop app, VS Code, terminal), and an optional cache band with Compact first (`CONTEXT_DOCTOR_MOD_BAND=cold`; Desktop app and terminal only)
|
|
217
219
|
- [Editor and status line](./docs/editor-and-statusline.md): the VS Code / Cursor extension and Claude Code's status bar
|
|
218
220
|
- [Token counts](./docs/tokenizer.md): why counts are "~", how the Claude ratios were measured, exact counts
|
|
219
221
|
- [Performance](./docs/performance.md): what context-doctor itself costs (its six MCP tool definitions: at most ~2,344 tokens)
|
package/dist/abclaude.js
CHANGED
|
@@ -138,7 +138,7 @@ export function inspectClaudeCode(bin = claudeBin()) {
|
|
|
138
138
|
}
|
|
139
139
|
function whoPays(info) {
|
|
140
140
|
if (onPlan(info))
|
|
141
|
-
return `signed in to claude.ai${info.subscriptionType ? ` (${info.subscriptionType} plan)` : ""}: this draws on your plan's usage limits (the 5-hour
|
|
141
|
+
return `signed in to claude.ai${info.subscriptionType ? ` (${info.subscriptionType} plan)` : ""}: this draws on your plan's usage limits (the weekly window, and the 5-hour one on plans that have it), not dollars`;
|
|
142
142
|
if (info.authMethod === "api_key")
|
|
143
143
|
return `on an API key (${info.apiKeySource ?? "API key"}): this bills that key, in dollars`;
|
|
144
144
|
return `signed in as ${info.authMethod ?? "unknown"}: billed as your Claude Code is set up`;
|
package/dist/budget.d.ts
CHANGED
|
@@ -79,7 +79,10 @@ export declare function periodEnd(period: Period, now?: number): number;
|
|
|
79
79
|
* under another table or other rates is read again. `c` is where reading a
|
|
80
80
|
* Claude Code transcript's compactions stopped (compactcost.ts): each
|
|
81
81
|
* compaction's own request is in `k`/`d` too, estimated, keyed by its
|
|
82
|
-
* boundary's uuid.
|
|
82
|
+
* boundary's uuid. Each of `r` is a recent reply: its id, its index in
|
|
83
|
+
* k/d, the output counted, its output price, and what its iterations billed
|
|
84
|
+
* beyond its usage came to (billedCost's `extra`), so a later row that
|
|
85
|
+
* settles an advisor's call adds it once.
|
|
83
86
|
*/
|
|
84
87
|
export interface FileEntry {
|
|
85
88
|
t: Tool;
|
|
@@ -90,7 +93,7 @@ export interface FileEntry {
|
|
|
90
93
|
d: number[];
|
|
91
94
|
o?: number;
|
|
92
95
|
a?: string;
|
|
93
|
-
r?: Array<[string, number, number, number]>;
|
|
96
|
+
r?: Array<[string, number, number, number, number]>;
|
|
94
97
|
x?: Array<[number, string]>;
|
|
95
98
|
y?: Array<[number, string]>;
|
|
96
99
|
z?: Array<[number, string, string]>;
|
package/dist/budget.js
CHANGED
|
@@ -32,7 +32,7 @@ import { claudeCodePresent, claudeDir } from "./claudedir.js";
|
|
|
32
32
|
import { claudeFileUsage, codexSessionsRoot, rolloutFiles, SUBAGENT_LOOKBACK_MS, USAGE_ROWS } from "./limits.js";
|
|
33
33
|
import { subagentFiles } from "./subagents.js";
|
|
34
34
|
import { codexFileSpend, codexFiles, geminiFileSpend, geminiFiles, TOOL_NAME } from "./spend.js";
|
|
35
|
-
import { isUnbilledModel, priceChangedText, priceTableKey, requestCost } from "./pricing.js";
|
|
35
|
+
import { billedCost, isUnbilledModel, priceChangedText, priceTableKey, requestCost } from "./pricing.js";
|
|
36
36
|
import { orgRates, orgRatesLine } from "./orgrates.js";
|
|
37
37
|
import { anchorOf, rowsOf } from "./scan.js";
|
|
38
38
|
import { realModel } from "./tokens.js";
|
|
@@ -178,8 +178,12 @@ export function periodEnd(period, now = Date.now()) {
|
|
|
178
178
|
s.setDate(s.getDate() + (period === "week" ? 7 : 1));
|
|
179
179
|
return s.getTime();
|
|
180
180
|
}
|
|
181
|
-
/**
|
|
182
|
-
|
|
181
|
+
/**
|
|
182
|
+
* What a ledger entry counts: 2, each Claude Code compaction's own request
|
|
183
|
+
* too (compactcost.ts); 3, the iterations a reply's later row settles (`r`'s
|
|
184
|
+
* fifth figure). An entry counted otherwise is read again.
|
|
185
|
+
*/
|
|
186
|
+
const COUNTED = 3;
|
|
183
187
|
/** Replies remembered per transcript, to tell a later row of one from a new reply. */
|
|
184
188
|
const RECENT_REPLIES = 64;
|
|
185
189
|
function readState() {
|
|
@@ -354,7 +358,7 @@ function readFile(tool, file, since, size) {
|
|
|
354
358
|
continue;
|
|
355
359
|
}
|
|
356
360
|
const i = at.get(m.id) ?? -1;
|
|
357
|
-
last.set(m.id, [m.id, i, out, (i >= 0 ? reqs[i].rates : requestCost(realModel(m.model), m.usage, Date.parse(String(row.timestamp ?? "")))?.rates)?.outputPerM ?? 0]);
|
|
361
|
+
last.set(m.id, [m.id, i, out, (i >= 0 ? reqs[i].rates : requestCost(realModel(m.model), m.usage, Date.parse(String(row.timestamp ?? "")))?.rates)?.outputPerM ?? 0, i >= 0 ? (reqs[i].extra ?? []).reduce((n, x) => n + x.usd, 0) : 0]);
|
|
358
362
|
if (last.size > RECENT_REPLIES)
|
|
359
363
|
last.delete(last.keys().next().value);
|
|
360
364
|
}
|
|
@@ -461,12 +465,22 @@ function countLines(e, recent, text, since, own) {
|
|
|
461
465
|
e.d[known[1]] += ((out - known[2]) * known[3]) / 1e6;
|
|
462
466
|
known[2] = out;
|
|
463
467
|
}
|
|
468
|
+
// And iterations its usage leaves out that it settles on (an advisor's call once it ran): what they add, once.
|
|
469
|
+
if (u.iterations) {
|
|
470
|
+
const extra = billedCost(realModel(m.model), u, Date.parse(String(row.timestamp ?? "")))?.extra?.usd ?? 0;
|
|
471
|
+
if (extra > known[4]) {
|
|
472
|
+
if (known[1] >= 0)
|
|
473
|
+
e.d[known[1]] += extra - known[4];
|
|
474
|
+
known[4] = extra;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
464
477
|
continue;
|
|
465
478
|
}
|
|
466
479
|
const ts = Date.parse(String(row.timestamp ?? ""));
|
|
467
480
|
const tokens = [u.input_tokens, u.cache_read_input_tokens, u.cache_creation_input_tokens].reduce((t, v) => t + (Number(v) > 0 ? Number(v) : 0), 0);
|
|
468
481
|
const model = realModel(m.model);
|
|
469
|
-
|
|
482
|
+
// As billed: with the iterations its top-level usage leaves out (an advisor's, a declined attempt's).
|
|
483
|
+
const c = billedCost(model, u, ts);
|
|
470
484
|
let index = -1;
|
|
471
485
|
// A reply on <synthetic> was made by Claude Code itself, never billed: not a request at all.
|
|
472
486
|
// A row of another session (`own`): a copy of its history, its spend, not this session's.
|
|
@@ -484,7 +498,7 @@ function countLines(e, recent, text, since, own) {
|
|
|
484
498
|
e.d.push(c ? c.totalUsd : 0);
|
|
485
499
|
}
|
|
486
500
|
if (typeof m.id === "string")
|
|
487
|
-
recent.push([m.id, index, out, c?.rates.outputPerM ?? 0]);
|
|
501
|
+
recent.push([m.id, index, out, c?.rates.outputPerM ?? 0, c?.extra?.usd ?? 0]);
|
|
488
502
|
}
|
|
489
503
|
}
|
|
490
504
|
}
|
|
@@ -492,7 +506,7 @@ function countLines(e, recent, text, since, own) {
|
|
|
492
506
|
export function wellFormed(e) {
|
|
493
507
|
return Boolean(e) && typeof e === "object" && Array.isArray(e.k) && Array.isArray(e.d) && e.k.length === e.d.length &&
|
|
494
508
|
e.k.every((x) => typeof x === "string") && e.d.every((x) => typeof x === "number" && Number.isFinite(x)) &&
|
|
495
|
-
(e.a === undefined || typeof e.a === "string") && (e.x === undefined || (Array.isArray(e.x) && e.x.every((y) => Array.isArray(y) && typeof y[0] === "number"))) && (e.y === undefined || (Array.isArray(e.y) && e.y.every((y) => Array.isArray(y) && typeof y[0] === "number"))) && (e.r === undefined || (Array.isArray(e.r) && e.r.every((x) => Array.isArray(x) && x.length ===
|
|
509
|
+
(e.a === undefined || typeof e.a === "string") && (e.x === undefined || (Array.isArray(e.x) && e.x.every((y) => Array.isArray(y) && typeof y[0] === "number"))) && (e.y === undefined || (Array.isArray(e.y) && e.y.every((y) => Array.isArray(y) && typeof y[0] === "number"))) && (e.r === undefined || (Array.isArray(e.r) && e.r.every((x) => Array.isArray(x) && x.length === 5))) &&
|
|
496
510
|
(e.z === undefined || (Array.isArray(e.z) && e.z.every((z) => Array.isArray(z) && typeof z[0] === "number" && typeof z[2] === "string")));
|
|
497
511
|
}
|
|
498
512
|
/**
|
package/dist/cache.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* caching at all.
|
|
11
11
|
*/
|
|
12
12
|
import { readFileSync } from "node:fs";
|
|
13
|
-
import {
|
|
13
|
+
import { billedCost, cacheWriteSplit } from "./pricing.js";
|
|
14
14
|
import { replyCounter } from "./session.js";
|
|
15
15
|
import { realModel } from "./tokens.js";
|
|
16
16
|
export function analyzeCacheUsage(transcriptPath) {
|
|
@@ -65,8 +65,8 @@ export function analyzeCacheUsage(transcriptPath) {
|
|
|
65
65
|
cacheWrite1hTokens += cacheWriteSplit(usage).oneHour;
|
|
66
66
|
uncachedTokens += fresh;
|
|
67
67
|
// Each request at its own model's price: a session can switch models.
|
|
68
|
-
// As billed (requestCost): its tier, fast mode, US-only.
|
|
69
|
-
const cost =
|
|
68
|
+
// As billed (requestCost): its tier, fast mode, US-only; and the iterations its top-level usage leaves out (billedCost).
|
|
69
|
+
const cost = billedCost(model, usage, Date.parse(String(entry.timestamp ?? "")) || undefined);
|
|
70
70
|
const pricing = cost?.rates;
|
|
71
71
|
if (cost && pricing) {
|
|
72
72
|
priced++;
|
package/dist/cachemisses.d.ts
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
*/
|
|
37
37
|
import { type Extractor } from "./scan.js";
|
|
38
38
|
import { type DiagnosedMisses } from "./missledger.js";
|
|
39
|
+
import { type ColdReturnReport } from "./coldreturns.js";
|
|
39
40
|
export type MissCause = "model switch" | "context edited" | "after an API error" | "over 20 new blocks" | "nothing visible";
|
|
40
41
|
export interface CacheMiss {
|
|
41
42
|
path: string;
|
|
@@ -124,6 +125,8 @@ export interface CacheMissReport {
|
|
|
124
125
|
}>;
|
|
125
126
|
largest: LateRewrite[];
|
|
126
127
|
};
|
|
128
|
+
/** Returns after the cache expired, replayed as billed, compacted and kept warm (coldreturns.ts). */
|
|
129
|
+
coldReturns: ColdReturnReport;
|
|
127
130
|
}
|
|
128
131
|
/** One Claude Code version's requests (the `version` every transcript line carries). */
|
|
129
132
|
export interface VersionStats {
|
package/dist/cachemisses.js
CHANGED
|
@@ -40,6 +40,7 @@ import { formatTokens, isCodeLike, realModel, tokensForLength } from "./tokens.j
|
|
|
40
40
|
import { CACHE_WRITE_1H, CACHE_WRITE_5M, requestCost } from "./pricing.js";
|
|
41
41
|
import { compareVersions } from "./modelswitch.js";
|
|
42
42
|
import { diagnosedMisses, missLogPath } from "./missledger.js";
|
|
43
|
+
import { coldReturns, renderColdReturns } from "./coldreturns.js";
|
|
43
44
|
/** Dollars as a person reads them: "$1,925", "$12.26", "$0". */
|
|
44
45
|
function money(n) {
|
|
45
46
|
if (!(n > 0))
|
|
@@ -417,6 +418,7 @@ export function cacheMisses(days = 30, paths, onProgress, missLog = missLogPath(
|
|
|
417
418
|
...versionReport(versions),
|
|
418
419
|
diagnosed: diagnosedMisses(since, missLog),
|
|
419
420
|
late: lateReport(late),
|
|
421
|
+
coldReturns: coldReturns(days, targets),
|
|
420
422
|
};
|
|
421
423
|
}
|
|
422
424
|
/**
|
|
@@ -665,6 +667,9 @@ export function renderCacheMisses(r, limitLines) {
|
|
|
665
667
|
out.push("", ...late);
|
|
666
668
|
if (r.diagnosed.misses > 0)
|
|
667
669
|
out.push("", ...renderDiagnosed(r.diagnosed));
|
|
670
|
+
const cold = renderColdReturns(r.coldReturns);
|
|
671
|
+
if (cold.length)
|
|
672
|
+
out.push("", ...cold);
|
|
668
673
|
return out.join("\n");
|
|
669
674
|
}
|
|
670
675
|
const share = r.cacheWriteUsd > 0 ? ` (${Math.round((r.extraUsd / r.cacheWriteUsd) * 100)}% of your ${money(r.cacheWriteUsd)} of cache writes)` : "";
|
|
@@ -721,5 +726,8 @@ export function renderCacheMisses(r, limitLines) {
|
|
|
721
726
|
}
|
|
722
727
|
}
|
|
723
728
|
out.push("", "A miss: within the cache lifetime of both requests (5 min, or 1 h when written at", "the 1-hour TTL), no compaction between, previous context over 20k, and the request", "wrote over 60% of that context again. Model switches always miss: each model has", "its own cache. On Claude Code 2.1.251+, `context-doctor install` (or the plugin)", "shows that price before a /model switch.");
|
|
729
|
+
const cold = renderColdReturns(r.coldReturns);
|
|
730
|
+
if (cold.length)
|
|
731
|
+
out.push("", ...cold);
|
|
724
732
|
return out.join("\n");
|
|
725
733
|
}
|
package/dist/cachettl.js
CHANGED
|
@@ -38,7 +38,7 @@ import { join } from "node:path";
|
|
|
38
38
|
import { listSessions, replyCounter, isClaudeSession } from "./session.js";
|
|
39
39
|
import { REQUEST_ROWS } from "./coldresume.js";
|
|
40
40
|
import { rowsOf } from "./scan.js";
|
|
41
|
-
import { CACHE_WRITE_1H, CACHE_WRITE_5M, cacheWriteSplit, requestCost } from "./pricing.js";
|
|
41
|
+
import { billedCost, CACHE_WRITE_1H, CACHE_WRITE_5M, cacheWriteSplit, requestCost } from "./pricing.js";
|
|
42
42
|
import { priceBasis } from "./orgrates.js";
|
|
43
43
|
import { realModel } from "./tokens.js";
|
|
44
44
|
import { backupOnce } from "./install.js";
|
|
@@ -115,7 +115,11 @@ export function replayTtlTranscript(path, acc, since, until = Infinity, sidechai
|
|
|
115
115
|
if (!c || !p)
|
|
116
116
|
acc.unpriced++;
|
|
117
117
|
else {
|
|
118
|
-
|
|
118
|
+
// The iterations its usage leaves out (billedCost): billed, and the same in both arms.
|
|
119
|
+
const extra = (billedCost(model, u, at)?.promptUsd ?? c.promptUsd) - c.promptUsd;
|
|
120
|
+
acc.billedUsd += c.promptUsd + extra;
|
|
121
|
+
acc.at5mUsd += extra;
|
|
122
|
+
acc.at1hUsd += extra;
|
|
119
123
|
acc.writes += W;
|
|
120
124
|
acc.writes1h += split.oneHour;
|
|
121
125
|
const inp = p.inputPerM / 1e6;
|
package/dist/ccost.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code's own cost beside ours.
|
|
3
|
+
*
|
|
4
|
+
* Every Claude Code transcript carries `cost-state` rows: Claude Code's
|
|
5
|
+
* running total for the session (`totalCostUSD`, what /cost shows), and per
|
|
6
|
+
* model the tokens and dollars it counted (`modelUsage`). It writes one at
|
|
7
|
+
* points through a session and restores it on resume (one `startTime` per
|
|
8
|
+
* session, the total never falls: all 567 rows of the author's 79 sessions
|
|
9
|
+
* that have one). It counts every request its process made for the session,
|
|
10
|
+
* subagents included, and also what no transcript row records: a
|
|
11
|
+
* compaction's own request (which context-doctor estimates, compactcost.ts),
|
|
12
|
+
* the small requests it makes on its own (titles and the like, on a Haiku),
|
|
13
|
+
* web searches at their fee, and from Claude Code 2.1.325 other mods' own
|
|
14
|
+
* model calls.
|
|
15
|
+
*
|
|
16
|
+
* So it is the check ROADMAP K2 waited on the mod for, read from what is
|
|
17
|
+
* already on disk: per session, its last `cost-state` against our price of
|
|
18
|
+
* the same requests (the session's transcript and its subagents', from the
|
|
19
|
+
* session's start to the last reply before that row). The gap is taken
|
|
20
|
+
* apart, per model, with Claude Code's own token counts:
|
|
21
|
+
* - models it counted that no transcript row has (its side requests);
|
|
22
|
+
* - on the models both count, its tokens beyond ours, at our prices
|
|
23
|
+
* (requests the transcripts keep no usage for: compactions past our
|
|
24
|
+
* estimate of them, retries);
|
|
25
|
+
* - what is left is price: its dollars against ours for its own tokens
|
|
26
|
+
* (its price table, fast mode, a long prompt's tier, contracted rates).
|
|
27
|
+
* The mod's ledger (modmeasure.ts) stays for what it measures live; this is
|
|
28
|
+
* the comparison `spend`, `session` and `doctor` show.
|
|
29
|
+
*/
|
|
30
|
+
import type { SpendItem } from "./spend.js";
|
|
31
|
+
/** What one model's line of a `cost-state` holds, as numbers. */
|
|
32
|
+
export interface CcModel {
|
|
33
|
+
usd: number;
|
|
34
|
+
input: number;
|
|
35
|
+
output: number;
|
|
36
|
+
read: number;
|
|
37
|
+
write: number;
|
|
38
|
+
/** The writes by lifetime (`cacheCreationEphemeral1hInputTokens`, `...5m...`): both 0 where Claude Code did not split them (before ~2.1.317). */
|
|
39
|
+
write1h: number;
|
|
40
|
+
write5m: number;
|
|
41
|
+
searches: number;
|
|
42
|
+
}
|
|
43
|
+
/** A `cost-state` row as the usage scan keeps it (scan.ts: numbers and model names only). */
|
|
44
|
+
export interface CostStateRecord {
|
|
45
|
+
type: "cost-state";
|
|
46
|
+
usd: number;
|
|
47
|
+
/** The session's start (ms), restored with the total on resume. */
|
|
48
|
+
start?: number;
|
|
49
|
+
models: Record<string, CcModel>;
|
|
50
|
+
/** Claude Code said some model's cost was unknown to it (`hasUnknownModelCost`). */
|
|
51
|
+
unknown?: true;
|
|
52
|
+
/** The Claude Code version of the replies before it. */
|
|
53
|
+
version?: string;
|
|
54
|
+
}
|
|
55
|
+
/** A `cost-state` row, kept as numbers; undefined when it is not one. */
|
|
56
|
+
export declare function costStateRecord(e: any, version?: string): CostStateRecord | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* A request Claude Code sent, the model declined (a refusal), and Claude
|
|
59
|
+
* Code sent again on another model (`model_refusal_fallback`): billed, and
|
|
60
|
+
* no row records its usage. Kept by the usage scan as its model and time.
|
|
61
|
+
*/
|
|
62
|
+
export declare function refusalRecord(e: any): {
|
|
63
|
+
type: "refusal";
|
|
64
|
+
model: string;
|
|
65
|
+
timestamp?: string;
|
|
66
|
+
} | undefined;
|
|
67
|
+
/** A transcript's last `cost-state`, the time of the last reply before it (what it covers), and the declined requests before it, by model. */
|
|
68
|
+
export declare function lastCostState(rows: unknown[]): {
|
|
69
|
+
cs: CostStateRecord;
|
|
70
|
+
to: number;
|
|
71
|
+
first?: number;
|
|
72
|
+
declined: Record<string, number>;
|
|
73
|
+
} | undefined;
|
|
74
|
+
/** One model's two figures in a comparison. */
|
|
75
|
+
export interface ModelGap {
|
|
76
|
+
model: string;
|
|
77
|
+
/** Claude Code's dollars and tokens. */
|
|
78
|
+
ccUsd: number;
|
|
79
|
+
cc: {
|
|
80
|
+
input: number;
|
|
81
|
+
output: number;
|
|
82
|
+
read: number;
|
|
83
|
+
write: number;
|
|
84
|
+
searches: number;
|
|
85
|
+
};
|
|
86
|
+
/** Ours, on the same requests. */
|
|
87
|
+
ourUsd: number;
|
|
88
|
+
ours: {
|
|
89
|
+
input: number;
|
|
90
|
+
output: number;
|
|
91
|
+
read: number;
|
|
92
|
+
write: number;
|
|
93
|
+
requests: number;
|
|
94
|
+
};
|
|
95
|
+
/** Claude Code's tokens at our prices (atOurPrices): an estimate. */
|
|
96
|
+
ccAtOurUsd: number;
|
|
97
|
+
/** Requests on it that it declined and Claude Code sent again on another model (refusalRecord). */
|
|
98
|
+
declined?: number;
|
|
99
|
+
}
|
|
100
|
+
/** One session: Claude Code's figure and ours, and where the gap comes from. */
|
|
101
|
+
export interface SessionGap {
|
|
102
|
+
session: string;
|
|
103
|
+
project?: string;
|
|
104
|
+
/** What both cover: from the session's start to the last reply before Claude Code's last record. */
|
|
105
|
+
from: number;
|
|
106
|
+
to: number;
|
|
107
|
+
ccUsd: number;
|
|
108
|
+
ourUsd: number;
|
|
109
|
+
/** Of ours: the compactions' own requests, which we estimate (no row records their usage). */
|
|
110
|
+
compactionUsd: number;
|
|
111
|
+
compactions: number;
|
|
112
|
+
/**
|
|
113
|
+
* The main-thread turns that ended where Claude Code may send a prompt
|
|
114
|
+
* suggestion (sidecost.ts), and what one after each would cost: not in
|
|
115
|
+
* ours, since whether it was sent is in no file (gapText takes the count
|
|
116
|
+
* from Claude Code's own input tokens).
|
|
117
|
+
*/
|
|
118
|
+
turnEnds?: {
|
|
119
|
+
n: number;
|
|
120
|
+
usd: number;
|
|
121
|
+
};
|
|
122
|
+
/** Of ours: subagent replies whose rows never settled their output, estimated from their content (sidecost.ts). */
|
|
123
|
+
unsettledUsd?: number;
|
|
124
|
+
unsettled?: number;
|
|
125
|
+
/** Requests that hung and Claude Code sent again (stalledRetries): billed when the API had begun them, and in no row. */
|
|
126
|
+
stalled?: number;
|
|
127
|
+
version?: string;
|
|
128
|
+
unknown?: true;
|
|
129
|
+
models: ModelGap[];
|
|
130
|
+
}
|
|
131
|
+
/** The gap taken apart: each part is Claude Code's figure less ours, so they add up to ccUsd - ourUsd. */
|
|
132
|
+
export interface GapParts {
|
|
133
|
+
/** Models no transcript row has, of requests the model declined and Claude Code sent again elsewhere. */
|
|
134
|
+
declinedUsd: number;
|
|
135
|
+
declined: number;
|
|
136
|
+
declinedModels: string[];
|
|
137
|
+
/** Other models no transcript row has: Claude Code's own side requests (its web searches among them). */
|
|
138
|
+
sideUsd: number;
|
|
139
|
+
sideModels: string[];
|
|
140
|
+
sideSearches: number;
|
|
141
|
+
/** On the models both count: its tokens less ours, priced at ours. */
|
|
142
|
+
tokensUsd: number;
|
|
143
|
+
/** Its dollars against ours on its own tokens: price. */
|
|
144
|
+
priceUsd: number;
|
|
145
|
+
}
|
|
146
|
+
/** The parts of the gap of one or more sessions (see GapParts). */
|
|
147
|
+
export declare function gapParts(sessions: SessionGap[]): GapParts;
|
|
148
|
+
/** The turns of a main transcript's rows that ended where Claude Code may send a prompt suggestion, within [`from`, `to`], and their price (sidecost.ts). */
|
|
149
|
+
export declare function turnEnds(rows: unknown[], from: number, to: number): {
|
|
150
|
+
n: number;
|
|
151
|
+
usd: number;
|
|
152
|
+
};
|
|
153
|
+
/** A request no reply answers, sent again unchanged this long after or later: it hung. */
|
|
154
|
+
export declare const HUNG_MS = 60000;
|
|
155
|
+
/**
|
|
156
|
+
* Requests that hung: Claude Code sent one (an `api-request` row, 2.1.308+),
|
|
157
|
+
* no reply answers it, and Claude Code sent it again unchanged (a row whose
|
|
158
|
+
* `base` is it, with no new messages) a minute or more later, with no error
|
|
159
|
+
* between saying it never left the machine. On the author's machine they
|
|
160
|
+
* come in runs while the network is down or the machine sleeps (a subagent
|
|
161
|
+
* sent the same 380k-token prompt every ~16 minutes through a night), and
|
|
162
|
+
* the two stretches between Claude Code's cost-state records that hold most
|
|
163
|
+
* of them hold most of the gap: Claude Code bills a request the API had
|
|
164
|
+
* begun, and no row records its usage. Which ones the API had begun is in
|
|
165
|
+
* no file, so they are counted, not priced. Within [`from`, `to`].
|
|
166
|
+
*/
|
|
167
|
+
export declare function stalledRetries(files: string[], from: number, to: number): number;
|
|
168
|
+
/**
|
|
169
|
+
* The comparison for the sessions among `tops` whose Claude Code record and
|
|
170
|
+
* our requests both fall inside [`since`, `until`]: `items` are spend's
|
|
171
|
+
* Claude Code items (each request once, its session the transcript's name).
|
|
172
|
+
* A session whose last record starts after its first reply (a record that
|
|
173
|
+
* restarted on resume) is compared from where the record starts.
|
|
174
|
+
*/
|
|
175
|
+
export declare function compareSessions(tops: string[], items: SpendItem[], since?: number, until?: number): SessionGap[];
|
|
176
|
+
/** One session's figures, from Claude Code's record and our items over the same span. */
|
|
177
|
+
export declare function sessionGap(session: string, cs: CostStateRecord, mine: SpendItem[], from: number, to: number, declined?: Record<string, number>): SessionGap;
|
|
178
|
+
/** The version that counts other mods' model calls in Claude Code's cost (CHANGELOG 2.1.325). */
|
|
179
|
+
export declare const MODS_COUNTED_FROM = "2.1.325";
|
|
180
|
+
/** a >= b, as dotted versions. */
|
|
181
|
+
export declare function versionAtLeast(a: string | undefined, b: string): boolean;
|
|
182
|
+
/** Within this of Claude Code's figure is a match (ROADMAP K2, F1). */
|
|
183
|
+
export declare const CC_GAP_TARGET = 0.02;
|
|
184
|
+
/** What the gap is made of, in words, largest part first: what Claude Code's figure holds more (or less) than ours, and why. */
|
|
185
|
+
export declare function gapText(sessions: SessionGap[]): string[];
|
|
186
|
+
/** `spend`'s lines: Claude Code's figure beside ours on the sessions both cover; none when no session has a record in the window. */
|
|
187
|
+
export declare function renderComparison(sessions: SessionGap[]): string[];
|
|
188
|
+
/** `session`'s lines for one session; none when its transcript has no record. */
|
|
189
|
+
export declare function renderSessionComparison(s: SessionGap | undefined): string[];
|
|
190
|
+
/** `doctor`'s check: how close our price is to Claude Code's own, session by session. Undefined when no session has a record worth comparing. */
|
|
191
|
+
export declare function comparisonCheck(sessions: SessionGap[], days: number): {
|
|
192
|
+
label: string;
|
|
193
|
+
status: "ok" | "warn";
|
|
194
|
+
detail: string;
|
|
195
|
+
} | undefined;
|