context-doctor 0.3.1 → 0.3.2
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 +34 -3
- package/dist/mcp.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,30 @@ Restart your apps, then just ask Claude: *"what's eating my context?"* (`npx con
|
|
|
42
42
|
|
|
43
43
|
**No API keys, ever.** Everything is deterministic local code; when an LLM is needed (summarizing pruned history), the model already running in your app does it. The proxy forwards *your app's* credentials untouched — context-doctor itself holds nothing.
|
|
44
44
|
|
|
45
|
+
## What `install` actually does — and what happens in every session after
|
|
46
|
+
|
|
47
|
+
One run of `npx context-doctor install` writes five things (each config edit makes a `.backup` first; `uninstall` reverses all of it):
|
|
48
|
+
|
|
49
|
+
1. **Claude Desktop config** (`claude_desktop_config.json`) — registers the MCP server
|
|
50
|
+
2. **Claude Code config** (`~/.claude.json`) — registers the MCP server
|
|
51
|
+
3. **Cursor config** (`~/.cursor/mcp.json`) — registers the MCP server
|
|
52
|
+
4. **Agent Skill** → `~/.claude/skills/context-doctor/` — context-hygiene playbook for Claude Code
|
|
53
|
+
5. **Every-prompt hook** → `~/.claude/settings.json` — the per-query context check for Claude Code
|
|
54
|
+
|
|
55
|
+
**In every chat afterward (Claude Desktop, Cursor):** when the conversation starts, the app launches the MCP server, which hands the model standing instructions that stay in force for the whole chat:
|
|
56
|
+
|
|
57
|
+
- summarize large pastes and tool results instead of carrying them verbatim,
|
|
58
|
+
- reference earlier content instead of re-quoting it, never inline base64,
|
|
59
|
+
- once the chat passes ~30 turns or accumulates big pastes, *proactively offer to profile it*,
|
|
60
|
+
- answer any "what's eating my context / cost / latency" question by calling `profile_context`, not by guessing.
|
|
61
|
+
|
|
62
|
+
**In every Claude Code / Cowork session afterward:** all of the above via MCP, plus two more layers:
|
|
63
|
+
|
|
64
|
+
- the **skill** loads whenever context work is relevant, and
|
|
65
|
+
- the **hook runs on every single prompt you send**: it measures the session's real size in ~100ms. Under 80k tokens it stays completely silent. Above, it injects a note the model sees with your message — actual token count, cost per message, the single largest recoverable waste — with instructions to work leaner and offer you compaction. It re-fires only after ~40% further growth, and can never break a prompt (any failure exits silently).
|
|
66
|
+
|
|
67
|
+
**What it never does:** delete or rewrite your history without asking (pruning is consent-only, and the model writes the replacement summary so nothing is lost silently), send data anywhere (everything runs on your machine), or touch an API key.
|
|
68
|
+
|
|
45
69
|
## What "always-on" means, per surface
|
|
46
70
|
|
|
47
71
|
| Where you run LLMs | Mechanism | Guarantee |
|
|
@@ -115,7 +139,16 @@ Because prompt caching matches byte-identical prefixes, deterministic strategies
|
|
|
115
139
|
|
|
116
140
|
`context-doctor` ships an MCP server, so the AI itself can profile and slim context on demand.
|
|
117
141
|
|
|
118
|
-
**
|
|
142
|
+
**Do you need to configure anything by hand? Usually no:**
|
|
143
|
+
|
|
144
|
+
| App | Setup |
|
|
145
|
+
|---|---|
|
|
146
|
+
| Claude Desktop | `npx context-doctor install` writes the config — just restart the app |
|
|
147
|
+
| Claude Code | Same command — MCP + skill + every-prompt hook, all automatic |
|
|
148
|
+
| Cursor | Same command — writes `~/.cursor/mcp.json` |
|
|
149
|
+
| ChatGPT desktop | **Manual, one time** (ChatGPT's connectors live inside its own settings): Settings → Connectors → Developer mode → add local server, command `npx`, args `-y context-doctor-mcp` |
|
|
150
|
+
|
|
151
|
+
For any other MCP client, the server entry is:
|
|
119
152
|
|
|
120
153
|
```json
|
|
121
154
|
{
|
|
@@ -128,8 +161,6 @@ Because prompt caching matches byte-identical prefixes, deterministic strategies
|
|
|
128
161
|
}
|
|
129
162
|
```
|
|
130
163
|
|
|
131
|
-
**ChatGPT desktop** (developer mode), **Cursor**, **Claude Code** (`claude mcp add context-doctor -- npx -y context-doctor-mcp`), and any other MCP client: same command, their config syntax.
|
|
132
|
-
|
|
133
164
|
### How it works in Claude Desktop, step by step
|
|
134
165
|
|
|
135
166
|
1. Run `npx context-doctor install` (writes the config above for you) and restart Claude Desktop.
|
package/dist/mcp.js
CHANGED
|
@@ -31,7 +31,7 @@ const SERVER_INSTRUCTIONS = `context-doctor keeps this conversation's context wi
|
|
|
31
31
|
2. When the conversation has grown long (roughly 30+ turns) or contains several large pastes, proactively offer to profile it and call profile_context — do not wait to be asked.
|
|
32
32
|
3. When the user asks anything about token usage, cost, latency, or "what's eating my context", call profile_context immediately rather than estimating by eye.
|
|
33
33
|
4. When optimize_context returns a pruned-turns digest, YOU write the replacement summary (dense, factual, ≤150 tokens) as instructed in the result.`;
|
|
34
|
-
const server = new McpServer({ name: "context-doctor", version: "0.3.
|
|
34
|
+
const server = new McpServer({ name: "context-doctor", version: "0.3.2" }, { instructions: SERVER_INSTRUCTIONS });
|
|
35
35
|
const STRATEGY_IDS = ["dedupe", "trim-tool-results", "strip-base64", "prune-history"];
|
|
36
36
|
server.tool("profile_context", "Profile an LLM conversation or prompt: token breakdown by category, largest messages, and actionable findings about wasted context (duplicates, oversized tool results, base64 blobs, cache-unfriendly ordering). Accepts OpenAI/Anthropic conversation JSON or raw text. Call this immediately whenever the user asks about token usage, context size, LLM cost, or latency — and proactively offer it once a conversation grows long or accumulates large pasted content.", {
|
|
37
37
|
conversation: z.string().describe("Conversation JSON (OpenAI or Anthropic format, or bare message array) or raw prompt text"),
|
package/package.json
CHANGED