Skip to content
MCP server
Registry

context-doctor MCP Server

Cut LLM agent token use in Claude Code, Cursor, Codex, Gemini CLI. Local, no API key. gAI Ventures.

context-doctor scores 70 (Good), licensed MIT and written in TypeScript. It installs as a local process. It does not declare tools yet. Filed under AI and memory. GitHub shows 3 stars. Package registries report about 1,284 downloads a week. Install configs are generated for 12 clients. Being listed in the registry is not the same as being vendor-official.

by kushalp1MITTypeScript3 stars
Trust score
70Good
Trust score 70 of 100, Good

Good trust

70 of 100 from six public signals. Nobody can buy a point.

  • Listed in the official MCP registry.
  • OSI-style license: mit.
How we score trust
Scorecard

License, quality and maintenance

How grades work
Trust breakdown

Where the 70 comes from

22 + 20 + 7 + 10 + 4 + 7 = 70. Each factor is capped, so no single signal can carry a listing.

Registry22 / 30

Active in the official MCP registry, plus a known vendor namespace.

Registry: 22 of 30 points.
Maintenance20 / 20

How recently the repository saw a commit or release.

Maintenance: 20 of 20 points.
Popularity7 / 20

GitHub stars and weekly downloads, on a log scale.

Popularity: 7 of 20 points.
License10 / 10

A clear, OSI-style open-source license.

License: 10 of 10 points.
Security4 / 10

Not archived, a secure install path, a pinned version.

Security: 4 of 10 points.
Docs7 / 10

A real summary, a README with depth, listed tools.

Docs: 7 of 10 points.

Install

Pick your client, copy the config, paste it in.

Needs Cursor or VS Code installed on this device. The button opens the app and asks you to confirm before it adds the server.

~/Library/Application Support/Claude/claude_desktop_config.json
{  "mcpServers": {    "kushalp1-context-doctor": {      "command": "npx",      "args": [        "-y",        "context-doctor@0.55.0"      ]    }  }}

Environment variables

This server does not declare environment variables.

Tools show up when the registry metadata or the repository README lists them. Public READMEs are read directly. A GitHub token is used only when one is already configured.

About

context-doctor 🩺

CI npm npm downloads MCP Registry AgentHub 已收录:context-doctor license: MIT macOS | Linux | Windows

See where your AI agent's tokens go, and stop paying for the ones that do nothing.

AI agents re-send their whole context on every message: old tool output, pasted files, long instructions. A 500k-token session pays for all of it again each time, and at full price after a coffee break, when the prompt cache has expired. context-doctor measures that waste on your own sessions, in dollars, and removes it at the moments it pays: before it enters the context, while it sits there, and on every request. It runs on your machine, needs no API key, sends no telemetry, and works with Claude Code (terminal, IDE, desktop app), Claude Desktop, ChatGPT, Codex, Cursor, Gemini CLI, GitHub Copilot, any app on the Anthropic, OpenAI or Gemini API, and CI. MIT licensed, Node 20+, macOS, Linux and Windows.

npx context-doctor savings

What your recent Claude Code sessions cost, and what each fix would have saved: replayed request by request against what you were billed, never modelled, and with nothing to measure it says so. Nothing to measure yet? npx context-doctor savings --sample runs the same report on generated example sessions, labelled SAMPLE.

Measured on the author's own sessions, priced the way the prompt cache billed them; savings replays yours the same way and, with nothing to measure, says so.

Tried it? Tell us what it found on your sessions, or what didn't make sense: the two-minute feedback form (totals only, never transcripts). If it saved you money, a ⭐ helps other people find it.

Which context-doctor is this? Several projects share the name. This one is context-doctor on npm and io.github.KushalP1/context-doctor in the official MCP Registry (see the entry). The registry is a service, not a list in a GitHub repo: the modelcontextprotocol/servers repository holds only reference servers and points to the registry for the rest. Built and maintained by gAI Ventures.

Quick start

See it first, nothing installed: in a terminal, npx context-doctor reads your last 30 days of Claude Code sessions on this machine and shows what the fixes with no quality cost would have saved, as one total, then asks once: y applies them all, npx context-doctor fix undo puts them back. The fixes that trade something (compacting earlier, the subagents' model) are listed with their dollars and the command for each.

Claude Code (terminal, IDE, desktop app): inside Claude Code, /plugin marketplace add KushalP1/context-doctor, then /plugin install context-doctor@context-doctor. You get the every-prompt check, the compaction hook, the MCP tools and /context-doctor:fix, :spend, :savings, :checkup, :overhead, :pack, :autopilot, :compact-window.

Everything on this machine at once: npm install -g context-doctor && context-doctor install wires Claude Code, Claude Desktop, Cursor, Codex, Gemini CLI, Google Antigravity and GitHub Copilot: MCP server, skill and hooks (what it writes). context-doctor doctor checks it; context-doctor uninstall removes it. Then, for Claude Code in a terminal or IDE, context-doctor autopilot on.

Each takes about a minute and is fully reversible. Work somewhere else? Same idea, other surfaces:

You useDo this
Claude Desktop, Cursor or any MCP clientAdd the server to the client's MCP config (or install the one-click .mcpb from the latest release in Claude Desktop):{"mcpServers": {"context-doctor": {"command": "npx", "args": ["-y", "context-doctor", "mcp"]}}}
claude.ai, ChatGPT, phone appsnpx 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)
Your own app on an LLM APIRun 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). No proxy possible? Wrap the SDK client: withContextDoctor(new Anthropic()) (library)
Python / RAG pipelinespip 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
GitHub pull requestsuses: KushalP1/context-doctor@v0.55.0 comments how much a PR grows CLAUDE.md, AGENTS.md and rules, and can fail over a budget (setup)

What it does

Measure, in dollars, on your own history (profiling)

  • 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).
  • 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.
  • overhead: what every request re-reads before your message (system prompt, tools, MCP servers, CLAUDE.md, rules, memory), each file priced per month.
  • 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.
  • cache-misses: requests that re-wrote the prompt cache while it should still have been warm, priced, by model and context size, with Claude Code's own cause where it logged one and the transcript's otherwise. 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).
  • limits: your plan's weekly and 5-hour windows (Claude Pro, Max and Ultra, which has no 5-hour window; recorded by the plugin's mod, the status line or the proxy) and Codex's, the pace and when each runs out, what 1M tokens of each kind cost in % of the limit, and for each weekly window the API-equivalent dollars and tokens per 1%, by entrypoint and model, with every move in that figure dated and checked against the model mix (a week moved to a model that uses the limit faster per dollar is said to be the mix, not the limit draining faster), what a full 5-hour window costs of the weekly limit and whether that moved (both windows count the same requests, so the model mix cannot explain a move in it), where a weekly window that went unread got to (from the 5-hour window's rise), and, when a limit ran out and Claude Code kept going on usage credits, when and about how much (or, with extra usage on and the weekly limit on pace to run out early, about how much the hours until the reset would cost; once it reads 100%, about how much the rest of the window costs at your pace, as a range, and that budget caps it). limits --report prints it as a block to paste into a bug report, with no prompts, paths or ids.
  • cache-plan <request.json>: where an Anthropic API request should carry cache_control, and what it saves over N calls.
  • session, watch, analyze, report, dashboard: token breakdown and wasted-context findings for any session, conversation file or agent trace.

Keep waste out of the context (pack and overhead)

  • pack (and the pack_context MCP tool): only the chunks of a big document, PDF, log or codebase that a question needs, within a token budget, instead of the whole thing.
  • recall (and the recall MCP tool): the few lines of this session's own transcript a question needs, including turns a compaction summarised away and tool output autopilot cleared, with their time and position; secrets masked.
  • overhead split: turns a heavy CLAUDE.md or memory file into a lean one plus a reference file the agent opens when needed, word for word, nothing lost.
  • ci and the GitHub Action: review memory-file growth like any other cost.

Remove waste automatically

  • A model-switch warning (PreModelSwitch, Claude Code 2.1.251+) shows what a /model switch costs before it happens: the whole context re-written into the new model's cache.
  • A subagent price (PreToolUse on the Agent tool) shows what a subagent costs before it starts, at your own median for that type (the author's: $3.99 for general-purpose, $1.43 for Explore, 422 runs in 30 days), with the Sonnet price where it would run on Opus or Fable, and a total when launches bunch up. It never blocks.
  • A compaction hook (PreCompact) tells each Claude Code compaction what the session cannot lose (files changed, open tasks, your instructions, failing tests), so compacting saves tokens without losing the thread.
  • An every-prompt hook (Claude Code, Codex, Gemini CLI; Cursor after each tool call) tells the model its real context size and the largest waste, and offers /compact when you return to a big session after the cache expired.
  • A session's own price: once a session passes $25, $100 and $500 (subagents included), the every-prompt hook tells you what it has cost and what each message now costs, and that /compact or a fresh session cuts it (docs).
  • budget 50/day (or /week): the every-prompt hook in Claude Code, Codex and Gemini CLI says when today's spend passes 50%, 80% and 100% of it, and with --block holds prompts over budget; the status line shows $12/$50 today.
  • compact-window: sets Claude Code's own auto-compact window, measured on your history first. Works in the desktop app too. From Claude Code 2.1.334, which compacts near 400k on most 1M models by itself, it says so and measures smaller sizes against that.
  • cache-ttl: replays your own pauses at a 5-minute and a 1-hour prompt cache and sets Claude Code's promptCacheTtl to the cheaper one (the author's: 7% less main-conversation input at 1 hour; 22% less than the 5-minute default an API key gets). Same content either way, so no quality cost (fixes).
  • Autopilot: a local proxy (or SDK wrapper) that clears stale tool output only when the prompt cache is cold, so a request never costs more.

What it saves

Measured, not modelled, on every Claude Code session on the author's machine (mostly Opus 5.5 and the Fable 5 models with the 1M window), priced the way the prompt cache bills it (cached reads at each model's read rate, 2.5-10% of input; writes 1.25x input for the 5-minute cache, 2x for the hour) at API list prices. Re-measured on 2026-11-24 with each request at its own model and current prices (Opus 5.5 is $4 per million input tokens with $0.20 reads). context-doctor savings runs the same measurement on yours.

1. Compacting when you come back (every Claude Code surface, desktop app included). 146 days, 729 returns to a session over 150k tokens after its prompt cache expired (65 idle minutes on the 1-hour cache, 10 on the 5-minute one that Claude Code 2.1.295 often writes); median context at the return, 497k tokens.

Net saving had you run /compact after the first reply$3,554 (about $740 a month)
Returns where it paid offabout 2 in 3
Worst single case−$1.79 (a session left a few messages later)

Each return counts only the messages up to the next return, and the compaction request is charged as a cost. Not counted: files the model may re-read after compacting, and what the summary leaves out. That is why this is advice with the numbers attached, not something done for you.

2. Autopilot (Claude Code in a terminal or IDE, API apps). 146 days, 108 sessions, replayed through the shipped autopilot code with real timestamps:

Without autopilotWith autopilotSaved
Input cost at API list price$14,318$12,561$1,757 (12.3%, about $365 a month)
Sessions made more expensive0 of 108

43 of 108 sessions save something, the best 41.6%: long sessions that go idle are where the money is. These sessions ran in the desktop app, which autopilot cannot reach, so for the author this is what the same sessions would have saved in a terminal; context-doctor savings separates the two for you. How it works →

3. Compacting earlier (automatic, every Claude Code surface, desktop app included). The offer in 1 is advice, and on the author's machine it was followed 1 time in 33. Claude Code has a native setting that needs nobody to follow anything: autoCompactWindow in ~/.claude/settings.json makes it compact as if the window were that size. context-doctor compact-window replays each session request by request at several sizes, priced as the cache bills (each simulated compaction pays its own request and a 20k-token summary at the output rate), and changes nothing until you pick one:

WindowInput cost, last 30 daysSavedCompactions a week
as now (not set)$1,6808.6
800k$1,532$149 (9%)8.6
600k$1,324$357 (21%)8.9
400k$1,053$628 (37%)11.9
300k$958$723 (43%)17.0
200k$881$799 (48%)30.6

41 sessions. The cost is real: each compaction replaces the session's history with a summary, so a smaller window trades detail for money. That is why the command shows the table first and sets a window only when you name one (context-doctor compact-window 400k; off undoes it, and a backup of settings.json is kept).

Claude Code 2.1.334 now does this by itself: with no window set, it compacts near 400k on most current 1M models (rolling out). Once your own sessions show it (a compaction near 400k on 2.1.334 or later, not one written ahead while you were away and not one after an idle gap), compact-window, fix, savings and doctor say "Claude Code compacts near 400k by itself now" with the date and size seen, and count its saving as Claude Code's, not as a lever: on the author's last 30 days, $774 that fix had ranked first. compact-window then measures 200k and 300k against Claude Code's 400k, not against the full window. "autoCompactWindow": "auto" reads as Claude Code's default.

Also measured:

  • pack: 9 of 10 questions about this repository answered from 0.6% of its tokens. How →
  • Counting Claude correctly: current Claude models pack 2.75 characters per token on prose (2.4 on code), not the 4 most tools assume: Claude counts about 40% more tokens than the usual 4-characters rule (~45% on prose, ~33% on code). context-doctor accuracy re-checks the ratio on your own sessions. Why →

On a Claude subscription you do not pay list price; the same tokens come out of your usage limit instead. Anthropic does not publish how limits weight cached tokens, so read the dollars as the size of the effect, not as your bill.

Where it works

Where you workAutomatic, every requestWhat you get on top
Claude Code in the terminal, VS Code or JetBrainsAutopilot 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 oneInstall via npm or as a plugin. Status bar context meter, /context-doctor:savings, session, watch, report, dashboard, MCP tools
Claude Code in the desktop app's Code tabHooks, 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 settingsSame as above, and the plugin's mod: /context-doctor-usage, the usage view the app dropped (context ring, how long the cache stays warm and what the next message costs now and after, 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+; fix and doctor first confirm from your own Desktop sessions that it reaches them, and fix prices it net of loading a tool again after each compaction) (Desktop)
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)
Codex (ChatGPT app's Codex tab, IDE extension, CLI)Every-prompt hook with the API's own token countsMCP 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). On an API key, autopilot too (autopilot on sets openai_base_url in ~/.codex/config.toml; Codex no longer reads OPENAI_BASE_URL)
Gemini CLIEvery-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
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 contextMCP tools (~/.copilot/mcp-config.json, which VS Code's Copilot sessions read too)
Your own apps on the Anthropic, OpenAI or Gemini APIAutopilot 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 clientExact usage and cache hit rates in /stats, prompt-cache placement advice (proxy)
Claude Desktop chatThe six standing rules below, sent to every chat (whether classic Chat shows them to the model is unverified, why); one cheap profile_context call the model makes once at ~30 turns and on any cost question; pack_context instead of reading a big local file whole; a handoff offered once a chat is long, since a chat's history cannot be cut and a new chat canOne-click .mcpb install, context_checkup, handoff and ask_file prompts, handoff://latest to attach in the next chat (handoff)
claude.ai, ChatGPT, the phone appsYour account's standing preferences, pasted once (Quick start)Profile an exported chat with analyze or session. ChatGPT developer mode: the MCP tools at a URL, uploads into pack_context (how)
CIanalyze --fail-over-budget fails a build whose prompts outgrow a budget; the GitHub Action gates memory-file growth.contextdoctorrc budgets and presets (CI)

Not claimed, because no process on your machine sends those requests: trimming inside Claude Desktop chat, claude.ai, ChatGPT, Cursor's own subscription models, or Codex signed in with ChatGPT. Those get the rules and the measurements above, not autopilot.

The MCP server hands these standing rules, verbatim, to every chat where it is enabled (Cursor and Claude Code put them in front of the model; for Claude Desktop's classic Chat that is unverified):

  1. When asked about tokens, cost, speed or limits, and once at ~30 turns or 3+ large pastes: call profile_context BEFORE answering; in a chat app pass a sketch. Act on its top finding. Do not estimate token counts yourself.
  2. When a chat grows long, offer a handoff once (save_handoff): only a new chat cuts its history.
  3. Summarize any paste or tool result over ~2k tokens into the points you need.
  4. Refer to earlier content by name; never re-quote it or inline base64.
  5. For a big file you won't edit, call pack_context with the question; don't read it whole.
  6. If optimize_context returns a pruned-turns digest, write its ≤150-token summary.

Rules 1-4 end exactly at character 512, the part ChatGPT's guide says must stand alone.

Commands

CommandWhat it does
context-doctor install / uninstallWire (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)
context-doctor fix [--apply ids|all] [--share] / fix undoEvery 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, prompt suggestions), 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; past a limit with extra usage on, the header says the levers save real dollars now (details)
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; one-off run folders, such as a batch of claude -p runs, folded into one row with their count, and a long name cut in the middle so its end shows), 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; a session Claude Code continued from another counted once (the total it carried over left out, and the line names the session it continued); 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 on the Anthropic API; the subagent's own model on Bedrock, Vertex or Foundry; its whole context with the small model overridden or through a proxy such as autopilot's on a Claude sign-in; a range where that cannot be told). 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), and one line names a model whose cache Claude Code cut to 5 minutes while another kept 1 hour (its own limit ran out: inferred) (docs)
context-doctor budget [<$>/day|<$>/week [--block]|off]A spend budget the every-prompt hook applies: a line at 50%, 80% and 100%, and with --block prompts over it are held until you raise it or turn it off; past your plan's limit, the line and budget say how much was paid from usage credits, and budget what running out before the weekly reset would cost on them, or, once a limit is used up, what the rest of it costs (docs)
context-doctor doctorSelf-check the whole installation — one pasteable ✓/✗ diagnosis with fixes, including which surfaces autopilot can reach and any other program on its port, whether extra usage (usage credits past a plan's limit) is on, which Claude Code versions sent requests the prompt cache never saw in the last 30 days and what they cost, what you answered the Desktop app's own auto-compact offer, when there is an answer on file, which MCP servers your newest Desktop session handed the mod (counted, the ones sent whole named, a claude.ai connector by its own name, and whether fix --apply desktop-tools-defer reaches them), whether the Claude Code plugin is a version behind this release (or a global context-doctor behind the plugin), and when Claude Code 2.1.332+ sessions sat idle where its own idle compaction should have run and none did, from the files on disk
context-doctor savings [--days n] [--share [--copy]] [--sample]What your recent Claude Code sessions cost, and what /compact at cold resumes (with the part Claude Code's own idle compaction takes from 2.1.332 said apart), autopilot (its tokens and dollars over the sessions it reaches, the desktop app's said apart) 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). With nothing of yours to replay it says so; --sample runs the same report on generated example sessions, labelled SAMPLE. --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
context-doctor autopilot on|off|pause|resume|statusEvery new Claude Code session started in a terminal or IDE goes through the local proxy, which clears stale tool output only when the prompt cache is cold: measured 12.3% less input cost, no session worse (details)
context-doctor proxy --autopilotLocal 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)
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). When your sessions show Claude Code 2.1.334+ compacting near 400k by itself with no window set, it says so (when, at what size, on which model) and measures each size against that 400k, not the full window (docs)
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)
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
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)
context-doctor mcp [--http]The MCP server as a subcommand, for clients and registries that launch npx -y context-doctor mcp
context-doctor-mcpThe 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)
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 (for a session continued from another, from where that one ended, its carried total left out). Also reads Codex rollouts, Gemini CLI chats and ChatGPT data exports (conversations.json); --list to browse
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
context-doctor cursor [--list]Profile a chat from Cursor's local history (both storage formats)
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
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)
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
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 as billed (the headline's one total is their sum), 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
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
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
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
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
context-doctor tasks [--days n]Cost per commit, per project: each session priced from its recorded usage against the commits it made
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
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)
context-doctor compactions [--days n]Do sessions work worse right after compacting? Re-reads, tool errors and your corrections, before vs after each compaction
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 Claude Code's own cause where the status line or the plugin's mod logged one (2.1.333+ in the Desktop app and VS Code) and the transcript's otherwise, said apart, 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), with the returns Claude Code's own idle compaction takes from 2.1.332 said apart; keeping warm for up to 1, 2, 4 and 8 hours priced with every ping a timer would send; #107157's re-added compacted segment with its re-write; and requests the cache never saw (no cache write, most of the prompt billed as new input, #111948) by Claude Code version, priced against a working cache; --json per model and version
context-doctor limits [--days n] [--report [--copy]]Your plan's limits in their own unit, every time in local time (--report, pasted for others, in UTC): 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 (for a weekly window with 2+ closed weeks in the readings, at whichever of the last day's and the window's average pace missed less on those weeks, replayed every 12 hours, named with both misses) (Claude's weekly and 5-hour windows, from the readings the plugin's mod, the status line or the proxy record; Ultra has no 5-hour window; Codex's from its rollouts), and % of the limit per 1M tokens of input, cache read, cache write and output, fitted on your readings with the fit's error; too-thin data is said to be thin, never quoted. Each weekly window, reset to reset: API-equivalent $ and tokens per 1%, split by entrypoint (cli, claude-desktop, sdk-cli) and model, and where that moved, by how much and on what date, checked against the model mix (a move the mix explains is said to be the mix, not the limit draining faster). One line says what a full 5-hour window costs of the weekly limit (the weekly rise over the 5-hour rise between the same readings, with its error), about how many fit in a week, and whether that moved, from what to what and at which weekly reset (both windows count the same requests, so the model mix cannot explain it); too-thin data is said to be thin, with no figure, and a plan with no 5-hour window gets no line. Codex's 5-hour and weekly windows the same way. When the weekly window stopped being read while the 5-hour one kept rising, one line says where it stopped and about where it got to, from that exchange (an estimate), and no pace is projected from the old reading. With extra usage on and the weekly limit on pace to run out before its reset, one line says about how many dollars the hours until the reset would go on usage credits (at the last 24 hours' pace, or the checked one with the range between the two, list prices, an estimate). A window at 100% says so instead of a pace; with extra usage on, one line says about how many dollars the rest of it goes on usage credits (the hours to the reset at the last 24 hours' and the window's average dollars, the checked pace first, an estimate) and that context-doctor budget <dollars>/day --block caps it. 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. When Claude Code (2.1.331+) cut one model's cache to 5 minutes while another kept 1 hour, which it does only on usage credits, one line says that model ran past its own limit (the Fable limit): when, how many requests and about how much (inferred, an estimate). The Fable limit's own % is shown when the proxy reads it. --report: the same as a block to paste into a GitHub issue (no prompts, paths, session or account ids)
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
context-doctor accuracyHow 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
context-doctor reportMachine-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
context-doctor dashboardLocal savings dashboard on 127.0.0.1: tokens saved per day, sessions by context in use vs recoverable, budget status
context-doctor ci [--base <ref>] [--max-tokens n] [--max-increase n] [--markdown]Memory files (CLAUDE.md, AGENTS.md, GEMINI.md, rules, their imports) at HEAD vs a base commit; exit 1 over budget. What the GitHub Action runs (details)
context-doctor init [preset]Write a .contextdoctorrc from a preset (chat, agent, batch) — a budget you can adopt in one command and tune later
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)
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)
context-doctor statuslineClaude 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)
context-doctor hookThe 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)
context-doctor --versionPrint the installed version. --help lists every flag

Privacy: everything runs on your machine. No API key is needed for anything core, nothing is sent anywhere, and no telemetry is collected; the proxy forwards your app's own credentials untouched and holds none of its own.

Speed: the history reports read each transcript once per run and keep what they took from it (token counts, times, ids, no message text) in ~/.cache/context-doctor, so a second fix or savings answers in under a second and later runs read only what was appended. CONTEXT_DOCTOR_NO_CACHE=1 keeps nothing; uninstall removes it (details).

What's new

  • 0.55 GPT-5.6 Sol's price after its promotion, and a feedback form: GPT-5.6 Sol and the gpt-5.6 alias are priced at OpenAI's $5 / $30 per million from December 1 ($10 / $45 for prompts over 272k), not at the $4 / $20 promotion that ended November 30; spend, budget and doctor say the price changed, and the weekly price check is green again. A two-minute feedback form on GitHub asks what it found and what was unclear, totals only, never transcripts (details).
  • 0.54 Usage credits the % never showed, a weekly meter that went silent, and Claude Code's own idle compaction: limits and spend find usage credits no limit reading showed, from Claude Code cutting one model's cache to 5 minutes, which it does only on credits (the author's: Nov 27, Fable 5.2, 366 requests, about $94 at list, an estimate), and the proxy records the Fable limit's own headers. When the weekly meter goes silent limits says so and estimates where it ended from the 5-hour meter, and the recorder keeps a reading that falls (usage given back) instead of dropping it. The run-out forecast uses whichever pace missed less on your own past weeks and gives credits as a range. fix, savings and cache-misses split cold returns into those Claude Code 2.1.332's idle compaction will take and yours (the author's: $167 of $219), and count the Desktop app's own idle-compaction notice. fix offers prompt suggestions off (about $30 a month here), and doctor says when the plugin and the command are on different versions (details).
  • 0.53 The 5-hour window's share of the week, warnings for the Claude Code you run, and a price check that checks prices: limits says what a full 5-hour window costs of your weekly limit (the author's: 16.1%, about 6 a week, unchanged since Nov 16), the one limit figure your model mix cannot move, and flags it with a date when it does; Codex's windows too. fix warns about an old Claude Code only where your sessions run: the Desktop app's own for the Desktop tools lever, and a terminal install no session used is said to be unused. The Desktop tools lever is priced net of re-loading tools after compactions (claude-code #111915; 22 of the author's 39 compactions). The weekly price check compares every figure on OpenAI's, Anthropic's and Google's price pages with ours, not only that a model has a price: it fixed GPT-6 Rosalind (we charged 1.5x), GPT-6 Astra for Law's missing long-prompt tier and four unpriced healthcare models, and an ending promotion is now its own step so it cannot hide a new red (details).
  • 0.52 An honest empty state, a sample report, and one command up front: with nothing of yours to replay, savings says so, offers savings --sample, the same report on generated example sessions, labelled SAMPLE, and says when to run it again; the measured report's footer says it too. doctor no longer says "All good" when nothing is protected: the verdict distinguishes no supported app, installed-but-not-wired ("not actively protecting any workflow") and wired. The README leads with one audience and one command, the savings figure captioned as measured on the author's own sessions, the other surfaces in a table. A new bug-report template asks for doctor output and limits --report, never transcripts; security reports go through private advisories (details).
  • 0.51 Limits that tell the model mix from the limit, proof before a lever, and the cache in the usage pane: limits no longer reads a switch to a hungrier model as the limit draining faster: it says when the move comes from your model mix, and claims a drain only when what is left is 1.5x or more. limits and budget say when the weekly limit would run out at your current pace and, with extra usage on, about what would go on usage credits before the reset; budget counts what credits already paid. The mod records which tools the Desktop app hands over, so fix and doctor confirm or withdraw desktop-tools-defer before you apply it. The /context-doctor-usage pane shows how long the cache stays warm and what your next message costs now and after it expires. cache-misses and doctor count requests the cache never saw (claude-code #111948). Progress summaries are priced in the form Claude Code really sends on your setup; overhead gives one total; doctor shows the Desktop app's auto-compact offer. Fixes: "1000k" for a 1M window, a flaky download-budget test, the ledger path doctor names (details).
  • 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).
  • 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).

Every release, with the details: docs/whats-new.md.

Documentation

  • What install does: every file it writes, what runs in each session after, and when you need MCP
  • Autopilot: how it clears stale tool output, and why it never costs more
  • Fixes: fix (one plan, applied with consent, undone in one step, re-measured), cache-ttl and the subagents' model
  • Spend and budget: one bill across every tool, and a budget the every-prompt hook applies
  • The proxy: autopilot and the optimizing mode for your API apps, /stats, cache advice, a public URL for Cursor
  • Chat apps: Claude Desktop, ChatGPT, claude.ai and the phone apps; what acts by itself and what only nudges; the MCP tools, prompts and resources
  • Handoff: continue a long chat in a new one from a ≤400-token brief
  • Profiling: sessions, prompt-cache economics, subagents, tasks, reads, compactions, cache-misses, limits, report
  • Pack and overhead: pack, recall, overhead, overhead split and overhead prune
  • Detectors and fixes: what the profiler finds and what each optimizer strategy changes
  • Library: profileConversation, optimizeConversation, packContext, withContextDoctor
  • Budgets and CI: the GitHub Action and .contextdoctorrc
  • Privacy and the directory submission: what the plugin reads, writes and sends; the package for Anthropic's plugin directory
  • Desktop app and VS Code: 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)
  • Editor and status line: the VS Code / Cursor extension, Claude Code's status bar and Codex's footer
  • Token counts: why counts are "~", how the Claude ratios were measured, exact counts
  • Performance: what context-doctor itself costs (its six MCP tool definitions: at most ~2,344 tokens)
  • Experiment and A/B suite: does a smaller context help, and does a lever cost quality? Measured on real tasks
  • What's new, Roadmap, Python package

Contributing

Used it? Send feedback: what it found, what was unclear, what you wanted. Issues and PRs welcome — see CONTRIBUTING.md for the rules that keep this tool trustworthy, how to run the checks, and how releases are made. What comes next is in ROADMAP.md: the research items and the steps waiting on the owner's accounts (PyPI, the editor extension's marketplaces, a signed Desktop bundle, the Glama listing).

License

MIT © gAI Ventures

Frequently asked questions

What is context-doctor MCP Server?

Cut LLM agent token use in Claude Code, Cursor, Codex, Gemini CLI. Local, no API key. gAI Ventures.

How do I install context-doctor MCP Server in Claude Desktop, Cursor, or VS Code?

Pick your client in the Install section on this page and copy the generated config into the client's config file. Step-by-step guides: Claude Desktop, Cursor, and VS Code. context-doctor MCP Server runs locally from the npm package context-doctor with the command npx -y context-doctor@0.55.0.

Is context-doctor MCP Server free and open source?

Yes. context-doctor MCP Server is released under the MIT license, an OSI-approved open-source license, so you can use, modify, and self-host it under those terms.

Does context-doctor MCP Server support remote (HTTP) connections?

No remote endpoint is listed for context-doctor MCP Server. It runs locally on your machine over stdio, started by your MCP client.

How is context-doctor MCP Server's trust score calculated?

context-doctor MCP Server scores 70 out of 100 (Good). The score adds six capped public signals: registry status, maintenance, popularity, license, documentation, and security. Nobody can pay for points. Read the methodology for the full formula.

Reviews

No reviews yet

—Be the first to review

5 star0 reviews at 5 stars
4 star0 reviews at 4 stars
3 star0 reviews at 3 stars
2 star0 reviews at 2 stars
1 star0 reviews at 1 stars

No published reviews yet. Used it? Tell the next person how it went.

Add badge to your README

Paste either snippet into the repository README. The image links to this listing.

Listed on MCPpedia

Top 5 MCP servers

Daily or weekly. Confirm by email, unsubscribe any time.

How often

Manage this listing

Claim this server