context-mode 0.5.20 → 0.5.23
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +63 -95
- package/build/server.js +1 -1
- package/build/store.js +13 -1
- package/package.json +4 -1
- package/server.bundle.mjs +261 -0
- package/skills/context-mode/SKILL.md +13 -7
- package/start.sh +8 -0
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"name": "context-mode",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "Claude Code MCP plugin that saves 98% of your context window. Sandboxed code execution in 10 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
16
|
-
"version": "0.5.
|
|
16
|
+
"version": "0.5.23",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Mert Koseoğlu"
|
|
19
19
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.23",
|
|
4
4
|
"description": "Claude Code MCP plugin that saves 98% of your context window. Sandboxed code execution in 10 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mert Koseoğlu",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"hooks": [
|
|
34
34
|
{
|
|
35
35
|
"type": "prompt",
|
|
36
|
-
"prompt": "
|
|
36
|
+
"prompt": "STOP. Default to mcp__context-mode__execute for ALL Bash commands. ONLY use Bash for these guaranteed-small-output operations: file mutations (mkdir, mv, cp, rm, touch, chmod), git writes (git add, git commit, git push, git checkout, git branch, git merge), navigation (cd, pwd, which), process control (kill, pkill), package management (npm install/publish, pip install), and simple echo/printf. Everything else — any command that reads, queries, fetches, lists, logs, tests, builds, diffs, inspects, or calls an external service — MUST use mcp__context-mode__execute instead. When uncertain, use context-mode."
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
}
|
package/README.md
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
# Context Mode
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**The other half of the context problem.**
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/context-mode) [](LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/context-mode) [](https://github.com/mksglu/claude-context-mode) [](LICENSE)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Every MCP tool call in Claude Code dumps raw data into your 200K context window. A Playwright snapshot costs 56 KB. Twenty GitHub issues cost 59 KB. One access log — 45 KB. After 30 minutes, 40% of your context is gone.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Playwright snapshot → 56 KB into context → 299 B summary
|
|
13
|
-
GitHub issues (20) → 59 KB into context → 1.1 KB summary
|
|
14
|
-
Access log (500) → 45 KB into context → 155 B summary
|
|
15
|
-
Context7 docs → 6 KB into context → 261 B summary
|
|
16
|
-
|
|
17
|
-
Total: 166 KB = 42K tokens gone Total: 1.8 KB = ~450 tokens
|
|
18
|
-
```
|
|
9
|
+
Inspired by Cloudflare's [Code Mode](https://blog.cloudflare.com/code-mode-mcp/) — which compresses tool definitions from millions of tokens into ~1,000 — we asked: what about the other direction?
|
|
10
|
+
|
|
11
|
+
Context Mode is an MCP server that sits between Claude Code and these outputs. **315 KB becomes 5.4 KB. 98% reduction.**
|
|
19
12
|
|
|
20
13
|
## Install
|
|
21
14
|
|
|
@@ -23,7 +16,7 @@ Total: 166 KB = 42K tokens gone Total: 1.8 KB = ~450 tokens
|
|
|
23
16
|
claude mcp add context-mode -- npx -y context-mode
|
|
24
17
|
```
|
|
25
18
|
|
|
26
|
-
Restart Claude Code. Done.
|
|
19
|
+
Restart Claude Code. Done.
|
|
27
20
|
|
|
28
21
|
<details>
|
|
29
22
|
<summary><strong>Plugin install</strong> (includes auto-routing skill)</summary>
|
|
@@ -33,7 +26,7 @@ Restart Claude Code. Done. You now have 5 tools that intercept large outputs and
|
|
|
33
26
|
/plugin install context-mode@claude-context-mode
|
|
34
27
|
```
|
|
35
28
|
|
|
36
|
-
Installs the MCP server + a skill that automatically
|
|
29
|
+
Installs the MCP server + a skill that automatically routes large outputs through Context Mode. No prompting needed.
|
|
37
30
|
|
|
38
31
|
</details>
|
|
39
32
|
|
|
@@ -46,116 +39,91 @@ claude --plugin-dir ./path/to/context-mode
|
|
|
46
39
|
|
|
47
40
|
</details>
|
|
48
41
|
|
|
49
|
-
##
|
|
42
|
+
## The Problem
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
MCP has become the standard way for AI agents to use external tools. But there is a tension at its core: every tool interaction fills the context window from both sides — definitions on the way in, raw output on the way out.
|
|
52
45
|
|
|
53
|
-
|
|
46
|
+
With [81+ tools active, 143K tokens (72%) get consumed before your first message](https://scottspence.com/posts/optimising-mcp-server-context-usage-in-claude-code). And then the tools start returning data. A single Playwright snapshot burns 56 KB. A `gh issue list` dumps 59 KB. Run a test suite, read a log file, fetch documentation — each response eats into what remains.
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
|---|---|---|
|
|
57
|
-
| Context consumed per session | 315 KB | 5.4 KB |
|
|
58
|
-
| Time before slowdown | ~30 min | ~3 hours |
|
|
59
|
-
| Context remaining after 45 min | 60% | 99% |
|
|
48
|
+
Code Mode showed that tool definitions can be compressed by 99.9%. Context Mode applies the same principle to tool outputs — processing them in sandboxes so only summaries reach the model.
|
|
60
49
|
|
|
61
50
|
## Tools
|
|
62
51
|
|
|
63
|
-
|
|
52
|
+
| Tool | What it does | Context saved |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `execute` | Run code in 10 languages. Only stdout enters context. | 56 KB → 299 B |
|
|
55
|
+
| `execute_file` | Process files in sandbox. Raw content never leaves. | 45 KB → 155 B |
|
|
56
|
+
| `index` | Chunk markdown into FTS5 with BM25 ranking. | 60 KB → 40 B |
|
|
57
|
+
| `search` | Query indexed content. Returns exact code blocks. | On-demand retrieval |
|
|
58
|
+
| `fetch_and_index` | Fetch URL, convert to markdown, index. | 60 KB → 40 B |
|
|
64
59
|
|
|
65
|
-
|
|
60
|
+
## How the Sandbox Works
|
|
66
61
|
|
|
67
|
-
|
|
68
|
-
execute({ language: "shell", code: "gh pr list --json title,state | jq length" })
|
|
69
|
-
→ "3" ← 2 bytes instead of 8KB
|
|
70
|
-
```
|
|
62
|
+
Each `execute` call spawns an isolated subprocess with its own process boundary. Scripts can't access each other's memory or state. The subprocess runs your code, captures stdout, and only that stdout enters the conversation context. The raw data — log files, API responses, snapshots — never leaves the sandbox.
|
|
71
63
|
|
|
72
|
-
|
|
64
|
+
Ten language runtimes are available: JavaScript, TypeScript, Python, Shell, Ruby, Go, Rust, PHP, Perl, R. Bun is auto-detected for 3-5x faster JS/TS execution.
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
execute({ language: "shell", code: "cat app.log", intent: "database connection error" })
|
|
76
|
-
→ matching sections + searchable terms ← 500B instead of 100KB
|
|
77
|
-
```
|
|
66
|
+
Authenticated CLIs work through credential passthrough — `gh`, `aws`, `gcloud`, `kubectl`, `docker` inherit environment variables and config paths without exposing them to the conversation.
|
|
78
67
|
|
|
79
|
-
|
|
68
|
+
When output exceeds 5 KB and an `intent` is provided, Context Mode switches to intent-driven filtering: it indexes the full output into the knowledge base, searches for sections matching your intent, and returns only the relevant matches with a vocabulary of searchable terms for follow-up queries.
|
|
80
69
|
|
|
81
|
-
|
|
70
|
+
## How the Knowledge Base Works
|
|
82
71
|
|
|
83
|
-
|
|
72
|
+
The `index` tool chunks markdown content by headings while keeping code blocks intact, then stores them in a **SQLite FTS5** (Full-Text Search 5) virtual table. Search uses **BM25 ranking** — a probabilistic relevance algorithm that scores documents based on term frequency, inverse document frequency, and document length normalization. **Porter stemming** is applied at index time so "running", "runs", and "ran" match the same stem.
|
|
84
73
|
|
|
85
|
-
|
|
86
|
-
execute_file({ path: "access.log", language: "python", code: "..." })
|
|
87
|
-
→ "200: 312 | 404: 89 | 500: 14" ← 30 bytes instead of 45KB
|
|
88
|
-
```
|
|
74
|
+
When you call `search`, it returns exact code blocks with their heading hierarchy — not summaries, not approximations, the actual indexed content. `fetch_and_index` extends this to URLs: fetch, convert HTML to markdown, chunk, index. The raw page never enters context.
|
|
89
75
|
|
|
90
|
-
|
|
76
|
+
## The Numbers
|
|
91
77
|
|
|
92
|
-
|
|
78
|
+
Measured across 11 real-world scenarios. Every operation under 1 KB output.
|
|
93
79
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
→
|
|
80
|
+
**Playwright snapshot** — 56.2 KB raw → 299 B context (99% saved)
|
|
81
|
+
**GitHub Issues (20)** — 58.9 KB raw → 1.1 KB context (98% saved)
|
|
82
|
+
**Access log (500 requests)** — 45.1 KB raw → 155 B context (100% saved)
|
|
83
|
+
**Context7 React docs** — 5.9 KB raw → 261 B context (96% saved)
|
|
84
|
+
**Analytics CSV (500 rows)** — 85.5 KB raw → 222 B context (100% saved)
|
|
85
|
+
**Git log (153 commits)** — 11.6 KB raw → 107 B context (99% saved)
|
|
86
|
+
**Test output (30 suites)** — 6.0 KB raw → 337 B context (95% saved)
|
|
97
87
|
|
|
98
|
-
|
|
99
|
-
→ exact code example with heading context ← 500 bytes instead of 60KB
|
|
100
|
-
```
|
|
88
|
+
Over a full session: 315 KB of raw output becomes 5.4 KB. Session time before slowdown goes from ~30 minutes to ~3 hours. Context remaining after 45 minutes: 99% instead of 60%.
|
|
101
89
|
|
|
102
|
-
|
|
90
|
+
[Full benchmark data with 21 scenarios →](BENCHMARK.md)
|
|
91
|
+
|
|
92
|
+
## Try It
|
|
103
93
|
|
|
104
|
-
|
|
94
|
+
These prompts work out of the box. Claude routes through Context Mode automatically.
|
|
105
95
|
|
|
96
|
+
**Git history analysis**
|
|
106
97
|
```
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
Clone https://github.com/modelcontextprotocol/servers and analyze its git history:
|
|
99
|
+
top contributors, commit types (feat/fix/docs/chore), and busiest weeks.
|
|
109
100
|
```
|
|
110
101
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Just ask naturally — Claude routes through Context Mode automatically when it saves tokens.
|
|
114
|
-
|
|
102
|
+
**Web page extraction**
|
|
115
103
|
```
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"Run the test suite and give me a pass/fail summary"
|
|
119
|
-
"Fetch the React useEffect docs and find the cleanup pattern"
|
|
120
|
-
"List all Docker containers with their memory usage"
|
|
121
|
-
"Find all TODO comments across the codebase"
|
|
122
|
-
"Analyze package-lock.json and find the 10 largest dependencies"
|
|
123
|
-
"Show running Kubernetes pods and their restart counts"
|
|
104
|
+
Fetch the Hacker News front page and extract: top 15 posts with titles, scores,
|
|
105
|
+
comment counts, and domains. Group them by domain.
|
|
124
106
|
```
|
|
125
107
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
| Playwright `browser_snapshot` | 56.2 KB | 299 B | **99%** |
|
|
131
|
-
| GitHub Issues (20) | 58.9 KB | 1.1 KB | **98%** |
|
|
132
|
-
| Access log (500 requests) | 45.1 KB | 155 B | **100%** |
|
|
133
|
-
| Context7 React docs | 5.9 KB | 261 B | **96%** |
|
|
134
|
-
| Analytics CSV (500 rows) | 85.5 KB | 222 B | **100%** |
|
|
135
|
-
| Git log (153 commits) | 11.6 KB | 107 B | **99%** |
|
|
136
|
-
| Test output (30 suites) | 6.0 KB | 337 B | **95%** |
|
|
137
|
-
|
|
138
|
-
[Full benchmark data with 21 scenarios →](BENCHMARK.md)
|
|
139
|
-
|
|
140
|
-
## How It Works
|
|
108
|
+
**Documentation lookup**
|
|
109
|
+
```
|
|
110
|
+
Fetch the React useEffect docs and find the cleanup pattern.
|
|
111
|
+
```
|
|
141
112
|
|
|
113
|
+
**Monorepo dependency audit**
|
|
142
114
|
```
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
│ │ tool calls/results │ │
|
|
146
|
-
└─────────────┘ │ Sandboxed subprocesses │
|
|
147
|
-
│ • 10 language runtimes │
|
|
148
|
-
│ • Auth passthrough (gh, aws…) │
|
|
149
|
-
│ • Intent-driven search │
|
|
150
|
-
│ │
|
|
151
|
-
│ SQLite FTS5 knowledge base │
|
|
152
|
-
│ • BM25 ranking │
|
|
153
|
-
│ • Porter stemming │
|
|
154
|
-
│ • Heading-aware chunking │
|
|
155
|
-
└─────────────────────────────────┘
|
|
115
|
+
Analyze package-lock.json: find the 10 largest dependencies,
|
|
116
|
+
which packages share the most common deps, and the heaviest package by count.
|
|
156
117
|
```
|
|
157
118
|
|
|
158
|
-
|
|
119
|
+
**Parallel browser + docs analysis**
|
|
120
|
+
```
|
|
121
|
+
Run 3 parallel tasks:
|
|
122
|
+
1. Navigate to news.ycombinator.com, take a snapshot, count all links and interactive elements
|
|
123
|
+
2. Navigate to jsonplaceholder.typicode.com, extract all API endpoint paths and HTTP methods
|
|
124
|
+
3. Fetch the Anthropic prompt caching docs, search for cache TTL and token pricing
|
|
125
|
+
Present all findings in a comparison table.
|
|
126
|
+
```
|
|
159
127
|
|
|
160
128
|
## Requirements
|
|
161
129
|
|
|
@@ -168,7 +136,7 @@ Each `execute` call spawns an isolated subprocess — scripts can't access each
|
|
|
168
136
|
```bash
|
|
169
137
|
git clone https://github.com/mksglu/claude-context-mode.git
|
|
170
138
|
cd claude-context-mode && npm install
|
|
171
|
-
npm test #
|
|
139
|
+
npm test # run tests
|
|
172
140
|
npm run test:all # full suite
|
|
173
141
|
```
|
|
174
142
|
|
package/build/server.js
CHANGED
|
@@ -5,7 +5,7 @@ import { z } from "zod";
|
|
|
5
5
|
import { PolyglotExecutor } from "./executor.js";
|
|
6
6
|
import { ContentStore } from "./store.js";
|
|
7
7
|
import { detectRuntimes, getRuntimeSummary, getAvailableLanguages, hasBunRuntime, } from "./runtime.js";
|
|
8
|
-
const VERSION = "0.5.
|
|
8
|
+
const VERSION = "0.5.23";
|
|
9
9
|
const runtimes = detectRuntimes();
|
|
10
10
|
const available = getAvailableLanguages(runtimes);
|
|
11
11
|
const server = new McpServer({
|
package/build/store.js
CHANGED
|
@@ -7,10 +7,21 @@
|
|
|
7
7
|
* Use for documentation, API references, and any content where
|
|
8
8
|
* you need EXACT text later — not summaries.
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
11
|
import { readFileSync } from "node:fs";
|
|
12
12
|
import { tmpdir } from "node:os";
|
|
13
13
|
import { join } from "node:path";
|
|
14
|
+
// Lazy-load better-sqlite3 — only when ContentStore is first used.
|
|
15
|
+
// This lets the MCP server start instantly even if the native module
|
|
16
|
+
// isn't installed yet (marketplace first-run scenario).
|
|
17
|
+
let _Database = null;
|
|
18
|
+
function loadDatabase() {
|
|
19
|
+
if (!_Database) {
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
_Database = require("better-sqlite3");
|
|
22
|
+
}
|
|
23
|
+
return _Database;
|
|
24
|
+
}
|
|
14
25
|
// ─────────────────────────────────────────────────────────
|
|
15
26
|
// Constants
|
|
16
27
|
// ─────────────────────────────────────────────────────────
|
|
@@ -48,6 +59,7 @@ function sanitizeQuery(query) {
|
|
|
48
59
|
export class ContentStore {
|
|
49
60
|
#db;
|
|
50
61
|
constructor(dbPath) {
|
|
62
|
+
const Database = loadDatabase();
|
|
51
63
|
const path = dbPath ?? join(tmpdir(), `context-mode-${process.pid}.db`);
|
|
52
64
|
this.#db = new Database(path, { timeout: 5000 });
|
|
53
65
|
this.#db.pragma("journal_mode = WAL");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Claude Code MCP plugin that saves 98% of your context window. Sandboxed code execution, FTS5 knowledge base, and intent-driven search.",
|
|
6
6
|
"author": "Mert Koseoğlu",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"build",
|
|
30
|
+
"server.bundle.mjs",
|
|
30
31
|
"skills",
|
|
31
32
|
".claude-plugin",
|
|
32
33
|
".mcp.json",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
],
|
|
37
38
|
"scripts": {
|
|
38
39
|
"build": "tsc",
|
|
40
|
+
"bundle": "esbuild src/server.ts --bundle --platform=node --target=node18 --format=esm --outfile=server.bundle.mjs --external:better-sqlite3 --minify",
|
|
39
41
|
"prepublishOnly": "npm run build",
|
|
40
42
|
"dev": "npx tsx src/server.ts",
|
|
41
43
|
"setup": "npx tsx src/cli.ts setup",
|
|
@@ -59,6 +61,7 @@
|
|
|
59
61
|
"devDependencies": {
|
|
60
62
|
"@types/better-sqlite3": "^7.6.13",
|
|
61
63
|
"@types/node": "^22.19.11",
|
|
64
|
+
"esbuild": "^0.27.3",
|
|
62
65
|
"tsx": "^4.21.0",
|
|
63
66
|
"typescript": "^5.7.0"
|
|
64
67
|
}
|