context-doctor 0.49.1 → 0.50.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 +15 -14
- package/dist/appwindow.d.ts +69 -0
- package/dist/appwindow.js +147 -0
- package/dist/ccost.js +8 -4
- package/dist/claudedir.d.ts +15 -0
- package/dist/claudedir.js +19 -1
- package/dist/cli.js +59 -23
- package/dist/clihelp.d.ts +5 -1
- package/dist/clihelp.js +9 -1
- package/dist/codexstatusline.d.ts +176 -0
- package/dist/codexstatusline.js +353 -0
- package/dist/compactwindow.d.ts +14 -2
- package/dist/compactwindow.js +30 -5
- package/dist/credits.d.ts +130 -0
- package/dist/credits.js +265 -0
- package/dist/doctor.d.ts +6 -0
- package/dist/doctor.js +15 -1
- package/dist/fanout.d.ts +2 -0
- package/dist/fanout.js +12 -2
- package/dist/fix.d.ts +37 -1
- package/dist/fix.js +67 -9
- package/dist/limits.d.ts +45 -1
- package/dist/limits.js +121 -9
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +106 -100
- package/dist/mod/api.d.ts +27 -1
- package/dist/mod/api.js +2 -1
- package/dist/mod/logic.d.ts +39 -0
- package/dist/mod/logic.js +42 -1
- package/dist/mod/register.d.ts +4 -0
- package/dist/mod/register.js +25 -1
- package/dist/modelids.js +2 -2
- package/dist/orgrates.d.ts +4 -2
- package/dist/orgrates.js +21 -3
- package/dist/overhead.js +2 -1
- package/dist/pricing.js +7 -0
- package/dist/progresssummaries.d.ts +20 -1
- package/dist/progresssummaries.js +33 -3
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.js +9 -4
- package/dist/savings.js +3 -1
- package/dist/spend.d.ts +28 -1
- package/dist/spend.js +38 -5
- package/dist/starts.d.ts +27 -1
- package/dist/starts.js +81 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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.50.0` 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, Cursor, Copilot CLI, OpenCode and Cline, by tool, project, model and day, as billed at list rates ([spend and budget](./docs/spend.md)).
|
|
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; past your plan's limit, what Claude Code ran on usage credits ([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
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.
|
|
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, when a limit ran out and Claude Code kept going on usage credits, when and about how much. `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,9 +107,9 @@ 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, 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),
|
|
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), `/context-doctor-fix`, and, once you apply `fix --apply desktop-tools-defer`, the app's own browser, session, preview and terminal tools kept behind tool search in new sessions (Claude Code 2.1.326+) ([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
|
-
| **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`) |
|
|
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. Codex 0.171+: a footer status line from the MCP server (context, the session's cost, the plan's limits), once you turn on Codex's Custom status line experiment and pick it ([how](./docs/editor-and-statusline.md#codexs-footer-codex-0171)). 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 |
|
|
114
114
|
| **GitHub Copilot** (Copilot CLI, the Copilot app, VS Code agent sessions) | A **session-start hook** (`~/.copilot/hooks/context-doctor.json`) gives every new or resumed session the standing rules. No size check: Copilot passes a transcript only to hooks that cannot add context | MCP tools (`~/.copilot/mcp-config.json`, which VS Code's Copilot sessions read too) |
|
|
115
115
|
| **Your own apps on the Anthropic, OpenAI or Gemini API** | Autopilot on `/v1/messages`, `/v1/chat/completions`, `/v1/responses` and Gemini's `generateContent` (`ANTHROPIC_BASE_URL` / `OPENAI_BASE_URL` / `GOOGLE_GEMINI_BASE_URL`), or the optimizing proxy (which can cost more on cached traffic); no proxy possible (serverless, edge)? `withContextDoctor(client)` runs autopilot inside the SDK client | Exact usage and cache hit rates in `/stats`, prompt-cache placement advice ([proxy](./docs/proxy.md)) |
|
|
@@ -135,14 +135,14 @@ 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, 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)) |
|
|
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, the Desktop app's own tools kept behind tool search through the plugin's mod, unused servers, the subagents' model, long Bash output to a file, Codex's auto-compact limit, subagent progress summaries), with what each costs in quality; applies one only on a yes (the subagents' model and the two MCP deferrals 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; subagent progress summaries estimated beside the total (from Claude Code 2.1.328, short notes on Haiku 5.5). When a plan limit ran out and requests kept going (extra usage), Claude Code's dollars split into past the limit, on usage credits, and inside the plan (at API list prices, an estimate) ([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
|
-
| `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
|
-
| `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 |
|
|
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, and whether extra usage (usage credits past a plan's limit) is on |
|
|
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 (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
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.7% less input cost, no session worse ([details](./docs/autopilot.md)) |
|
|
144
144
|
| `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
|
-
| `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 |
|
|
145
|
+
| `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
146
|
| `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)) |
|
|
147
147
|
| `context-doctor instructions [--copy]` | The ~190-token standing rules (~130 on GPT) for claude.ai / ChatGPT preferences, for web and phones where no server runs |
|
|
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)) |
|
|
@@ -164,7 +164,7 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
164
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
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) |
|
|
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. 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
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 |
|
|
@@ -173,7 +173,7 @@ Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand
|
|
|
173
173
|
| `context-doctor init [preset]` | Write a `.contextdoctorrc` from a preset (`chat`, `agent`, `batch`) — a budget you can adopt in one command and tune later |
|
|
174
174
|
| `context-doctor experiment --task "…"` | Run one task twice from the same commit, in a fresh session and forked from an `--existing` one, same model and tools; compare bill, cache split, wall clock, and whether `--check` passed. The only command here that spends money, so it caps spend per arm and refuses a dirty tree ([details](./docs/experiment.md)) |
|
|
175
175
|
| `context-doctor ab [--lever …] [--yes]` | Does a lever cost quality? Eight small coding tasks, each a tiny repository scored by a hidden check, run with and without the standing rules, autopilot's clearing, `pack_context` or the PreCompact instructions through the Messages API; pass counts, tokens and cost side by side. Bills `ANTHROPIC_API_KEY`: prints the estimate, sends nothing without `--yes`, stops at `--budget` ([details](./docs/ab.md)) |
|
|
176
|
-
| `context-doctor statusline` | Claude Code status bar: live context vs window, cache share, cost, and (Claude Code 2.1.251+) until when the cache is warm and what the next turn costs once it is cold. Wired by `install --statusline`; never overwrites a statusLine you already have ([details](./docs/editor-and-statusline.md)) |
|
|
176
|
+
| `context-doctor statusline` | Claude Code status bar: live context vs window, cache share, cost, and (Claude Code 2.1.251+) until when the cache is warm and what the next turn costs once it is cold. Wired by `install --statusline`; never overwrites a statusLine you already have. Codex has its own: the MCP server's `statusline`, picked in Codex's `/statusline` ([details](./docs/editor-and-statusline.md)) |
|
|
177
177
|
| `context-doctor hook` | The every-prompt hook (Claude Code, Codex, Gemini CLI, Cursor) and Claude Code's compaction hook, registered by `install`; `hook copilot` is GitHub Copilot's session-start hook; you never run these yourself. Warning threshold tunable via `CONTEXT_DOCTOR_WARN_TOKENS` (default 80000) |
|
|
178
178
|
| `context-doctor --version` | Print the installed version. `--help` lists every flag |
|
|
179
179
|
|
|
@@ -183,6 +183,7 @@ 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.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)).
|
|
186
187
|
- **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
188
|
- **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)).
|
|
188
189
|
- **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)).
|
|
@@ -215,8 +216,8 @@ Every release, with the details: [docs/whats-new.md](./docs/whats-new.md).
|
|
|
215
216
|
- [Library](./docs/library.md): `profileConversation`, `optimizeConversation`, `packContext`, `withContextDoctor`
|
|
216
217
|
- [Budgets and CI](./docs/ci.md): the GitHub Action and `.contextdoctorrc`
|
|
217
218
|
- [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
|
|
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)
|
|
219
|
-
- [Editor and status line](./docs/editor-and-statusline.md): the VS Code / Cursor extension
|
|
219
|
+
- [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), the Desktop app's own tools behind tool search once you apply `fix --apply desktop-tools-defer`, and an optional cache band with Compact first (`CONTEXT_DOCTOR_MOD_BAND=cold`; Desktop app and terminal only)
|
|
220
|
+
- [Editor and status line](./docs/editor-and-statusline.md): the VS Code / Cursor extension, Claude Code's status bar and Codex's footer
|
|
220
221
|
- [Token counts](./docs/tokenizer.md): why counts are "~", how the Claude ratios were measured, exact counts
|
|
221
222
|
- [Performance](./docs/performance.md): what context-doctor itself costs (its six MCP tool definitions: at most ~2,344 tokens)
|
|
222
223
|
- [Experiment](./docs/experiment.md) and [A/B suite](./docs/ab.md): does a smaller context help, and does a lever cost quality? Measured on real tasks
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auto-compact window the Desktop app chose, and the one Anthropic's
|
|
3
|
+
* server sets: read (never written) so `compact-window` and `fix` do not
|
|
4
|
+
* offer a second window over one the person just answered.
|
|
5
|
+
*
|
|
6
|
+
* Read from the 2.1.329 binary (`strings`; ROADMAP "Research 2026-11-20"):
|
|
7
|
+
* - The Code tab is testing an offer of a lower auto-compact window. It
|
|
8
|
+
* passes the person's answer to Claude Code in its own (flag) settings,
|
|
9
|
+
* `autoCompactOfferAnswer: { model, choice: 'accept'|'keep'|'undo',
|
|
10
|
+
* tokens, at }` ("`tokens` is the window they chose or kept, and `at` is
|
|
11
|
+
* when they answered"), and Claude Code records it in `~/.claude.json`
|
|
12
|
+
* as `autoCompactOfferCodeTab[account][model] = { choice, tokens, at }`
|
|
13
|
+
* (the account lowercased, the model as its settings key). Claude Code
|
|
14
|
+
* reads that record back only to keep an older answer from replacing a
|
|
15
|
+
* newer one: nothing in the binary sets a window from it. Whether
|
|
16
|
+
* accepting changes the window Claude Code uses depends on what the app
|
|
17
|
+
* passes in its own settings, which are not on disk. So this says what
|
|
18
|
+
* the app offered and what the person chose, and assumes nothing about
|
|
19
|
+
* the window that followed.
|
|
20
|
+
* - `autoCompactRaisedForLoad` (also the app's own settings only): true
|
|
21
|
+
* "lets a conversation compact at twice what is still in each request
|
|
22
|
+
* after a summary (system prompt, tools, instruction files), where that is
|
|
23
|
+
* above its auto-compact threshold".
|
|
24
|
+
* - `autoCompactWindowsCache` in `~/.claude.json`: the per-model windows
|
|
25
|
+
* Anthropic's server sends with the account (`auto_compact_windows`, on
|
|
26
|
+
* the Anthropic API only). Claude Code uses one for its model when no
|
|
27
|
+
* environment variable or settings file sets a window (its "server"
|
|
28
|
+
* source), so this one is a window in effect.
|
|
29
|
+
*/
|
|
30
|
+
export type OfferChoice = "accept" | "keep" | "undo";
|
|
31
|
+
/** One answer to the Desktop app's offer, the newest for its model. */
|
|
32
|
+
export interface AppWindowAnswer {
|
|
33
|
+
/** The model as Claude Code keyed it (its settings key, e.g. "claude-opus-5-5"). */
|
|
34
|
+
model: string;
|
|
35
|
+
choice: OfferChoice;
|
|
36
|
+
/** The window the person chose or kept. */
|
|
37
|
+
tokens: number;
|
|
38
|
+
/** When they answered (epoch ms). */
|
|
39
|
+
at: number;
|
|
40
|
+
/** Where it was read: ~/.claude.json, or a settings file. */
|
|
41
|
+
where: string;
|
|
42
|
+
}
|
|
43
|
+
export interface AppWindows {
|
|
44
|
+
answers: AppWindowAnswer[];
|
|
45
|
+
/** Windows Anthropic's server sets for this account, per model (autoCompactWindowsCache). */
|
|
46
|
+
served: Array<{
|
|
47
|
+
model: string;
|
|
48
|
+
window: number;
|
|
49
|
+
}>;
|
|
50
|
+
/** A settings file with autoCompactRaisedForLoad: true. */
|
|
51
|
+
raisedForLoad?: string;
|
|
52
|
+
}
|
|
53
|
+
/** Read-only: ~/.claude.json and the settings files. Nothing found: empty lists. */
|
|
54
|
+
export declare function readAppWindows(opts?: {
|
|
55
|
+
home?: string;
|
|
56
|
+
cwd?: string;
|
|
57
|
+
env?: NodeJS.ProcessEnv;
|
|
58
|
+
}): AppWindows;
|
|
59
|
+
/** Anything to say: an answer, a served window, or the raised-for-load switch. */
|
|
60
|
+
export declare const hasAppWindows: (a: AppWindows | undefined) => a is AppWindows;
|
|
61
|
+
/** A model id as a settings key: lowercase, no "[1m]", no date suffix, no Bedrock or Vertex wrapping. */
|
|
62
|
+
export declare function modelKey(model: string): string;
|
|
63
|
+
/** Whether a transcript's model is the one an answer names ("opus" and the like match their family). */
|
|
64
|
+
export declare function sameModel(answer: string, model: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The lines `compact-window` and `fix` say about it (none when nothing is on
|
|
67
|
+
* file). `left`: the sessions the replay left as they ran, when known.
|
|
68
|
+
*/
|
|
69
|
+
export declare function appWindowLines(a: AppWindows, left?: number): string[];
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auto-compact window the Desktop app chose, and the one Anthropic's
|
|
3
|
+
* server sets: read (never written) so `compact-window` and `fix` do not
|
|
4
|
+
* offer a second window over one the person just answered.
|
|
5
|
+
*
|
|
6
|
+
* Read from the 2.1.329 binary (`strings`; ROADMAP "Research 2026-11-20"):
|
|
7
|
+
* - The Code tab is testing an offer of a lower auto-compact window. It
|
|
8
|
+
* passes the person's answer to Claude Code in its own (flag) settings,
|
|
9
|
+
* `autoCompactOfferAnswer: { model, choice: 'accept'|'keep'|'undo',
|
|
10
|
+
* tokens, at }` ("`tokens` is the window they chose or kept, and `at` is
|
|
11
|
+
* when they answered"), and Claude Code records it in `~/.claude.json`
|
|
12
|
+
* as `autoCompactOfferCodeTab[account][model] = { choice, tokens, at }`
|
|
13
|
+
* (the account lowercased, the model as its settings key). Claude Code
|
|
14
|
+
* reads that record back only to keep an older answer from replacing a
|
|
15
|
+
* newer one: nothing in the binary sets a window from it. Whether
|
|
16
|
+
* accepting changes the window Claude Code uses depends on what the app
|
|
17
|
+
* passes in its own settings, which are not on disk. So this says what
|
|
18
|
+
* the app offered and what the person chose, and assumes nothing about
|
|
19
|
+
* the window that followed.
|
|
20
|
+
* - `autoCompactRaisedForLoad` (also the app's own settings only): true
|
|
21
|
+
* "lets a conversation compact at twice what is still in each request
|
|
22
|
+
* after a summary (system prompt, tools, instruction files), where that is
|
|
23
|
+
* above its auto-compact threshold".
|
|
24
|
+
* - `autoCompactWindowsCache` in `~/.claude.json`: the per-model windows
|
|
25
|
+
* Anthropic's server sends with the account (`auto_compact_windows`, on
|
|
26
|
+
* the Anthropic API only). Claude Code uses one for its model when no
|
|
27
|
+
* environment variable or settings file sets a window (its "server"
|
|
28
|
+
* source), so this one is a window in effect.
|
|
29
|
+
*/
|
|
30
|
+
import { readFileSync } from "node:fs";
|
|
31
|
+
import { claudeJsonPath, tilde } from "./claudedir.js";
|
|
32
|
+
import { settingsSources } from "./effective.js";
|
|
33
|
+
import { modelName } from "./subagentmodel.js";
|
|
34
|
+
const CHOICES = new Set(["accept", "keep", "undo"]);
|
|
35
|
+
function answerOf(v, model, where) {
|
|
36
|
+
if (!v || typeof v !== "object")
|
|
37
|
+
return undefined;
|
|
38
|
+
const m = typeof model === "string" && model ? model : typeof v.model === "string" ? v.model : undefined;
|
|
39
|
+
if (!m || !CHOICES.has(v.choice))
|
|
40
|
+
return undefined;
|
|
41
|
+
if (!(typeof v.tokens === "number" && Number.isInteger(v.tokens) && v.tokens > 0))
|
|
42
|
+
return undefined;
|
|
43
|
+
// A time a Date can hold (its range is ±8.64e15 ms): the lines print it as a day, which throws past it.
|
|
44
|
+
if (!(typeof v.at === "number" && Number.isFinite(v.at) && v.at > 0 && v.at <= 8.64e15))
|
|
45
|
+
return undefined;
|
|
46
|
+
return { model: m, choice: v.choice, tokens: v.tokens, at: v.at, where };
|
|
47
|
+
}
|
|
48
|
+
/** Read-only: ~/.claude.json and the settings files. Nothing found: empty lists. */
|
|
49
|
+
export function readAppWindows(opts = {}) {
|
|
50
|
+
const env = opts.env ?? process.env;
|
|
51
|
+
const out = { answers: [], served: [] };
|
|
52
|
+
const byModel = new Map();
|
|
53
|
+
const keep = (a) => {
|
|
54
|
+
if (!a)
|
|
55
|
+
return;
|
|
56
|
+
const k = modelKey(a.model);
|
|
57
|
+
const had = byModel.get(k);
|
|
58
|
+
if (!had || a.at > had.at)
|
|
59
|
+
byModel.set(k, a);
|
|
60
|
+
};
|
|
61
|
+
const path = claudeJsonPath(opts.home, env);
|
|
62
|
+
let j;
|
|
63
|
+
try {
|
|
64
|
+
j = JSON.parse(readFileSync(path, "utf8"));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
j = undefined;
|
|
68
|
+
}
|
|
69
|
+
if (j && typeof j === "object") {
|
|
70
|
+
// Every account's answers on this machine: the Code tab's account need not be the terminal's login.
|
|
71
|
+
const tab = j.autoCompactOfferCodeTab;
|
|
72
|
+
if (tab && typeof tab === "object") {
|
|
73
|
+
for (const models of Object.values(tab)) {
|
|
74
|
+
if (!models || typeof models !== "object")
|
|
75
|
+
continue;
|
|
76
|
+
for (const [model, v] of Object.entries(models))
|
|
77
|
+
keep(answerOf(v, model, tilde(path)));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const cache = j.autoCompactWindowsCache;
|
|
81
|
+
if (cache && typeof cache === "object" && !Array.isArray(cache)) {
|
|
82
|
+
for (const [model, w] of Object.entries(cache))
|
|
83
|
+
if (typeof w === "number" && Number.isInteger(w) && w > 0)
|
|
84
|
+
out.served.push({ model, window: w });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const s of settingsSources({ home: opts.home, cwd: opts.cwd, env })) {
|
|
88
|
+
keep(answerOf(s.settings.autoCompactOfferAnswer, undefined, tilde(s.path)));
|
|
89
|
+
if (s.settings.autoCompactRaisedForLoad === true && !out.raisedForLoad)
|
|
90
|
+
out.raisedForLoad = tilde(s.path);
|
|
91
|
+
}
|
|
92
|
+
out.answers = [...byModel.values()].sort((a, b) => a.at - b.at);
|
|
93
|
+
out.served.sort((a, b) => a.model.localeCompare(b.model));
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/** Anything to say: an answer, a served window, or the raised-for-load switch. */
|
|
97
|
+
export const hasAppWindows = (a) => !!a && (a.answers.length > 0 || a.served.length > 0 || !!a.raisedForLoad);
|
|
98
|
+
/** A model id as a settings key: lowercase, no "[1m]", no date suffix, no Bedrock or Vertex wrapping. */
|
|
99
|
+
export function modelKey(model) {
|
|
100
|
+
return model.trim().toLowerCase()
|
|
101
|
+
.replace(/\[1m\]$/, "")
|
|
102
|
+
.replace(/^(?:[a-z]{2,4}\.)?anthropic\./, "")
|
|
103
|
+
.replace(/-v\d+(?::\d+)?$/, "")
|
|
104
|
+
.replace(/@\d{8}$/, "")
|
|
105
|
+
.replace(/-\d{8}$/, "");
|
|
106
|
+
}
|
|
107
|
+
/** Whether a transcript's model is the one an answer names ("opus" and the like match their family). */
|
|
108
|
+
export function sameModel(answer, model) {
|
|
109
|
+
const a = modelKey(answer);
|
|
110
|
+
const m = modelKey(model);
|
|
111
|
+
if (/^(opus|sonnet|haiku|fable|mythos)$/.test(a))
|
|
112
|
+
return m.includes(a);
|
|
113
|
+
return a === m;
|
|
114
|
+
}
|
|
115
|
+
const k = (n) => `${Math.round(n / 1000)}k`;
|
|
116
|
+
const day = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
117
|
+
const nameOf = (m) => modelName(m) === m ? m : modelName(m);
|
|
118
|
+
/**
|
|
119
|
+
* The lines `compact-window` and `fix` say about it (none when nothing is on
|
|
120
|
+
* file). `left`: the sessions the replay left as they ran, when known.
|
|
121
|
+
*/
|
|
122
|
+
export function appWindowLines(a, left) {
|
|
123
|
+
const lines = [];
|
|
124
|
+
for (const x of a.answers) {
|
|
125
|
+
const who = `The Desktop app, ${nameOf(x.model)}`;
|
|
126
|
+
if (x.choice === "accept")
|
|
127
|
+
lines.push(`${who}: on ${day(x.at)} it offered a ${k(x.tokens)} auto-compact window and you accepted it.`);
|
|
128
|
+
else if (x.choice === "keep")
|
|
129
|
+
lines.push(`${who}: on ${day(x.at)} it offered a lower auto-compact window and you kept yours (${k(x.tokens)}).`);
|
|
130
|
+
else
|
|
131
|
+
lines.push(`${who}: on ${day(x.at)} you undid the lower auto-compact window it had set (on record: ${k(x.tokens)}).`);
|
|
132
|
+
}
|
|
133
|
+
if (a.answers.length) {
|
|
134
|
+
const models = a.answers.map((x) => nameOf(x.model)).join(", ");
|
|
135
|
+
lines.push(`Whether that answer changes the window Claude Code uses is not recorded on this computer`);
|
|
136
|
+
lines.push(`(the app passes it in its own settings), so nothing here assumes it does: sessions`);
|
|
137
|
+
const n = left === undefined ? "" : left === 0 ? " (none here)" : left === 1 ? " (1 here)" : ` (${left} here)`;
|
|
138
|
+
lines.push(`mostly on ${models}${n} are left as they ran, and only the rest are replayed.`);
|
|
139
|
+
}
|
|
140
|
+
if (a.served.length) {
|
|
141
|
+
lines.push(`Anthropic's server sets an auto-compact window on your account: ${a.served.map((s) => `${k(s.window)} for ${nameOf(s.model)}`).join(", ")}`);
|
|
142
|
+
lines.push(`(Claude Code uses it where no autoCompactWindow is set).`);
|
|
143
|
+
}
|
|
144
|
+
if (a.raisedForLoad)
|
|
145
|
+
lines.push(`autoCompactRaisedForLoad in ${a.raisedForLoad} does nothing: Claude Code reads it from the app's settings only.`);
|
|
146
|
+
return lines;
|
|
147
|
+
}
|
package/dist/ccost.js
CHANGED
|
@@ -343,11 +343,12 @@ export function gapText(sessions) {
|
|
|
343
343
|
nUns ? `the output of ${nUns.toLocaleString("en-US")} subagent repl${nUns === 1 ? "y" : "ies"} whose rows never settled it (${usd(uns)})` : "",
|
|
344
344
|
].filter(Boolean);
|
|
345
345
|
const compText = ests.length ? `${ests.length > 1 ? `${ests.slice(0, -1).join(", ")} and ${ests[ests.length - 1]}` : ests[0]}, which we estimate` : "";
|
|
346
|
-
|
|
347
|
-
const
|
|
346
|
+
// Plain words first, the method in brackets: the owner read the old run-on sentence as noise.
|
|
347
|
+
const sugText = nSug ? `; about ${nSug.toLocaleString("en-US")} of them prompt suggestions (the next message Claude Code offers after a turn; counted by the ${SUGGESTION_PROMPT_TOKENS} input tokens each adds), about ${usd(sug)}` : "";
|
|
348
|
+
const hung = stalled ? `; ${stalled.toLocaleString("en-US")} request${stalled === 1 ? "" : "s"} hung and ${stalled === 1 ? "was" : "were"} sent again (most while the network was down): Claude Code bills one if the API had begun it, and no file says which` : "";
|
|
348
349
|
if (Math.abs(p.tokensUsd) >= 0.005) {
|
|
349
350
|
parts.push([p.tokensUsd, p.tokensUsd > 0
|
|
350
|
-
? `Claude Code counts ${more(p.tokensUsd)}
|
|
351
|
+
? `Claude Code counts ${more(p.tokensUsd)} for requests no transcript records${compText ? ` (beyond our ${compText})` : ""}${sugText}${hung}`
|
|
351
352
|
: `Claude Code counts ${more(p.tokensUsd)} in tokens on the same models, at our prices: ${compText ? `our ${compText}, are above what it counted` : "requests we count that it does not"}`]);
|
|
352
353
|
}
|
|
353
354
|
if (Math.abs(p.priceUsd) >= 0.005)
|
|
@@ -396,5 +397,8 @@ export function comparisonCheck(sessions, days) {
|
|
|
396
397
|
const head = `${usd(ours)} against Claude Code's ${usd(cc)} (${pct(gap)}) on ${worth.length} session${worth.length === 1 ? "" : "s"} of the last ${days} days (its cost-state records); ${within} within ${CC_GAP_TARGET * 100}%`;
|
|
397
398
|
if (Math.abs(gap) <= CC_GAP_TARGET)
|
|
398
399
|
return { label, status: "ok", detail: head };
|
|
399
|
-
|
|
400
|
+
// The biggest part only, and where the rest is: every part on one doctor line was a paragraph nobody could act on.
|
|
401
|
+
const parts = gapText(worth);
|
|
402
|
+
const rest = parts.length > 1 ? ` context-doctor spend lists the other ${parts.length - 1} part${parts.length === 2 ? "" : "s"}.` : "";
|
|
403
|
+
return { label, status: "warn", detail: `${head}. Most of the gap: ${parts[0] ?? "not taken apart"}.${rest}` };
|
|
400
404
|
}
|
package/dist/claudedir.d.ts
CHANGED
|
@@ -21,5 +21,20 @@ export declare function claudeJsonPath(home?: string, env?: NodeJS.ProcessEnv):
|
|
|
21
21
|
* made `install` wire a Claude Code that is not there.
|
|
22
22
|
*/
|
|
23
23
|
export declare function claudeCodePresent(home?: string, env?: NodeJS.ProcessEnv): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the signed-in account pays past its plan's limit from usage
|
|
26
|
+
* credits ("extra usage"), as Claude Code last cached it in `~/.claude.json`:
|
|
27
|
+
* `oauthAccount.hasExtraUsageEnabled` (from the account's profile) and the
|
|
28
|
+
* top-level `cachedExtraUsageDisabledReason` (the last reply's
|
|
29
|
+
* `anthropic-ratelimit-unified-overage-disabled-reason`, null when it had
|
|
30
|
+
* none: read from the 2.1.311 binary). Undefined when the file has neither
|
|
31
|
+
* (an API key, Bedrock, Vertex, never signed in) or cannot be read.
|
|
32
|
+
*/
|
|
33
|
+
export interface ExtraUsage {
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
/** Why the last reply said credits are off ("out_of_credits", "org_level_disabled"...); null: it said nothing against them. */
|
|
36
|
+
disabledReason?: string | null;
|
|
37
|
+
}
|
|
38
|
+
export declare function readExtraUsage(home?: string, env?: NodeJS.ProcessEnv): ExtraUsage | undefined;
|
|
24
39
|
/** A path for messages: the home folder as `~`. */
|
|
25
40
|
export declare function tilde(p: string): string;
|
package/dist/claudedir.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* (tests, a throwaway home) gets that home's folders: the variable describes
|
|
10
10
|
* the real user's setup, not someone else's.
|
|
11
11
|
*/
|
|
12
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
12
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { join, resolve } from "node:path";
|
|
15
15
|
function configDirEnv(home, env) {
|
|
@@ -44,6 +44,24 @@ export function claudeCodePresent(home, env = process.env) {
|
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
export function readExtraUsage(home, env = process.env) {
|
|
48
|
+
try {
|
|
49
|
+
const j = JSON.parse(readFileSync(claudeJsonPath(home, env), "utf8"));
|
|
50
|
+
if (!j || typeof j !== "object")
|
|
51
|
+
return undefined;
|
|
52
|
+
const out = {};
|
|
53
|
+
const en = j.oauthAccount?.hasExtraUsageEnabled;
|
|
54
|
+
if (typeof en === "boolean")
|
|
55
|
+
out.enabled = en;
|
|
56
|
+
const r = j.cachedExtraUsageDisabledReason;
|
|
57
|
+
if (r === null || (typeof r === "string" && /^[a-z_]{1,60}$/.test(r)))
|
|
58
|
+
out.disabledReason = r;
|
|
59
|
+
return Object.keys(out).length ? out : undefined;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
47
65
|
/** A path for messages: the home folder as `~`. */
|
|
48
66
|
export function tilde(p) {
|
|
49
67
|
const h = homedir();
|