context-mode 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/hooks/hooks.json +11 -2
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +63 -23
- package/hooks/hooks.json +25 -0
- package/hooks/pretooluse.sh +73 -0
- package/package.json +2 -1
- package/server.bundle.mjs +286 -0
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "Context-mode
|
|
2
|
+
"description": "Context-mode PreToolUse — intercepts Bash data-fetching and injects subagent routing",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"PreToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "Bash",
|
|
7
|
+
"hooks": [
|
|
8
|
+
{
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
5
14
|
{
|
|
6
15
|
"matcher": "Task",
|
|
7
16
|
"hooks": [
|
|
8
17
|
{
|
|
9
18
|
"type": "command",
|
|
10
|
-
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/
|
|
19
|
+
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
|
|
11
20
|
}
|
|
12
21
|
]
|
|
13
22
|
}
|
|
@@ -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.
|
|
16
|
+
"version": "0.6.1",
|
|
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.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ Inspired by Cloudflare's [Code Mode](https://blog.cloudflare.com/code-mode-mcp/)
|
|
|
10
10
|
|
|
11
11
|
Context Mode is an MCP server that sits between Claude Code and these outputs. **315 KB becomes 5.4 KB. 98% reduction.**
|
|
12
12
|
|
|
13
|
+
https://github.com/user-attachments/assets/07013dbf-07c0-4ef1-974a-33ea1207637b
|
|
14
|
+
|
|
13
15
|
## Install
|
|
14
16
|
|
|
15
17
|
```bash
|
|
@@ -19,14 +21,14 @@ claude mcp add context-mode -- npx -y context-mode
|
|
|
19
21
|
Restart Claude Code. Done.
|
|
20
22
|
|
|
21
23
|
<details>
|
|
22
|
-
<summary><strong>Plugin install</strong> (includes auto-routing skill)</summary>
|
|
24
|
+
<summary><strong>Plugin install</strong> (includes auto-routing skill + subagent hook)</summary>
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
27
|
/plugin marketplace add mksglu/claude-context-mode
|
|
26
28
|
/plugin install context-mode@claude-context-mode
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
Installs the MCP server + a skill that automatically routes large outputs through Context Mode. No prompting needed.
|
|
31
|
+
Installs the MCP server + a skill that automatically routes large outputs through Context Mode + a PreToolUse hook that injects context-mode routing into subagent prompts. No prompting needed.
|
|
30
32
|
|
|
31
33
|
</details>
|
|
32
34
|
|
|
@@ -51,11 +53,13 @@ Code Mode showed that tool definitions can be compressed by 99.9%. Context Mode
|
|
|
51
53
|
|
|
52
54
|
| Tool | What it does | Context saved |
|
|
53
55
|
|---|---|---|
|
|
56
|
+
| `batch_execute` | Run multiple commands + search multiple queries in ONE call. | 986 KB → 62 KB |
|
|
54
57
|
| `execute` | Run code in 10 languages. Only stdout enters context. | 56 KB → 299 B |
|
|
55
58
|
| `execute_file` | Process files in sandbox. Raw content never leaves. | 45 KB → 155 B |
|
|
56
59
|
| `index` | Chunk markdown into FTS5 with BM25 ranking. | 60 KB → 40 B |
|
|
57
|
-
| `search` | Query indexed content
|
|
60
|
+
| `search` | Query indexed content with multiple queries in one call. | On-demand retrieval |
|
|
58
61
|
| `fetch_and_index` | Fetch URL, convert to markdown, index. | 60 KB → 40 B |
|
|
62
|
+
| `stats` | Session token tracking with per-tool breakdown. | — |
|
|
59
63
|
|
|
60
64
|
## How the Sandbox Works
|
|
61
65
|
|
|
@@ -71,11 +75,46 @@ When output exceeds 5 KB and an `intent` is provided, Context Mode switches to i
|
|
|
71
75
|
|
|
72
76
|
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.
|
|
73
77
|
|
|
74
|
-
When you call `search`, it returns
|
|
78
|
+
When you call `search`, it returns relevant content snippets focused around matching query terms — not full documents, not approximations, the actual indexed content with smart extraction around what you're looking for. `fetch_and_index` extends this to URLs: fetch, convert HTML to markdown, chunk, index. The raw page never enters context.
|
|
79
|
+
|
|
80
|
+
## Smart Snippets
|
|
81
|
+
|
|
82
|
+
Search results use intelligent extraction instead of truncation. Instead of returning the first N characters (which might miss the important part), Context Mode finds where your query terms appear in the content and returns windows around those matches. If your query is "authentication JWT token", you get the paragraphs where those terms actually appear — not an arbitrary prefix.
|
|
83
|
+
|
|
84
|
+
## Progressive Search Throttling
|
|
85
|
+
|
|
86
|
+
The `search` tool includes progressive throttling to prevent context flooding from excessive individual calls:
|
|
87
|
+
|
|
88
|
+
- **Calls 1-3:** Normal results (2 per query)
|
|
89
|
+
- **Calls 4-8:** Reduced results (1 per query) + warning
|
|
90
|
+
- **Calls 9+:** Blocked — redirects to `batch_execute`
|
|
91
|
+
|
|
92
|
+
This encourages batching queries via `search(queries: ["q1", "q2", "q3"])` or `batch_execute` instead of making dozens of individual calls.
|
|
93
|
+
|
|
94
|
+
## Session Stats
|
|
95
|
+
|
|
96
|
+
The `stats` tool tracks context consumption in real-time. Useful for debugging context usage during long sessions.
|
|
97
|
+
|
|
98
|
+
| Metric | Value |
|
|
99
|
+
|---|---|
|
|
100
|
+
| Session uptime | 2.6 min |
|
|
101
|
+
| Tool calls | 5 |
|
|
102
|
+
| Bytes returned to context | 62.0 KB (~15.9k tokens) |
|
|
103
|
+
| Bytes indexed (stayed in sandbox) | 140.5 KB |
|
|
104
|
+
| Context savings ratio | 2.3x (56% reduction) |
|
|
105
|
+
|
|
106
|
+
| Tool | Calls | Context used |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| batch_execute | 4 | 58.2 KB |
|
|
109
|
+
| search | 1 | 3.8 KB |
|
|
110
|
+
|
|
111
|
+
## Subagent Routing
|
|
112
|
+
|
|
113
|
+
When installed as a plugin, Context Mode includes a PreToolUse hook that automatically injects routing instructions into subagent (Task tool) prompts. Subagents learn to use `batch_execute` as their primary tool and `search(queries: [...])` for follow-ups — without any manual configuration.
|
|
75
114
|
|
|
76
115
|
## The Numbers
|
|
77
116
|
|
|
78
|
-
Measured across
|
|
117
|
+
Measured across real-world scenarios:
|
|
79
118
|
|
|
80
119
|
**Playwright snapshot** — 56.2 KB raw → 299 B context (99% saved)
|
|
81
120
|
**GitHub Issues (20)** — 58.9 KB raw → 1.1 KB context (98% saved)
|
|
@@ -84,6 +123,7 @@ Measured across 11 real-world scenarios. Every operation under 1 KB output.
|
|
|
84
123
|
**Analytics CSV (500 rows)** — 85.5 KB raw → 222 B context (100% saved)
|
|
85
124
|
**Git log (153 commits)** — 11.6 KB raw → 107 B context (99% saved)
|
|
86
125
|
**Test output (30 suites)** — 6.0 KB raw → 337 B context (95% saved)
|
|
126
|
+
**Repo research (subagent)** — 986 KB raw → 62 KB context (94% saved, 5 calls vs 37)
|
|
87
127
|
|
|
88
128
|
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%.
|
|
89
129
|
|
|
@@ -91,38 +131,38 @@ Over a full session: 315 KB of raw output becomes 5.4 KB. Session time before sl
|
|
|
91
131
|
|
|
92
132
|
## Try It
|
|
93
133
|
|
|
94
|
-
These prompts work out of the box.
|
|
134
|
+
These prompts work out of the box. Run `/context-mode stats` after each to see the savings.
|
|
95
135
|
|
|
96
|
-
**
|
|
136
|
+
**Deep repo research** — 5 calls, 62 KB context (raw: 986 KB, 94% saved)
|
|
97
137
|
```
|
|
98
|
-
|
|
99
|
-
top contributors,
|
|
138
|
+
Research https://github.com/modelcontextprotocol/servers — architecture, tech stack,
|
|
139
|
+
top contributors, open issues, and recent activity. Then run /context-mode stats.
|
|
100
140
|
```
|
|
101
141
|
|
|
102
|
-
**
|
|
142
|
+
**Git history analysis** — 1 call, 5.6 KB context
|
|
103
143
|
```
|
|
104
|
-
|
|
105
|
-
|
|
144
|
+
Clone https://github.com/facebook/react and analyze the last 500 commits:
|
|
145
|
+
top contributors, commit frequency by month, and most changed files.
|
|
146
|
+
Then run /context-mode stats.
|
|
106
147
|
```
|
|
107
148
|
|
|
108
|
-
**
|
|
149
|
+
**Web scraping** — 1 call, 3.2 KB context
|
|
109
150
|
```
|
|
110
|
-
Fetch the
|
|
151
|
+
Fetch the Hacker News front page, extract all posts with titles, scores,
|
|
152
|
+
and domains. Group by domain. Then run /context-mode stats.
|
|
111
153
|
```
|
|
112
154
|
|
|
113
|
-
**
|
|
155
|
+
**Large JSON API** — 7.5 MB raw → 0.9 KB context (99% saved)
|
|
114
156
|
```
|
|
115
|
-
|
|
116
|
-
|
|
157
|
+
Create a local server that returns a 7.5 MB JSON with 20,000 records and a secret
|
|
158
|
+
hidden at index 13000. Fetch the endpoint, find the hidden record, and show me
|
|
159
|
+
exactly what's in it. Then run /context-mode stats.
|
|
117
160
|
```
|
|
118
161
|
|
|
119
|
-
**
|
|
162
|
+
**Documentation search** — 2 calls, 1.8 KB context
|
|
120
163
|
```
|
|
121
|
-
|
|
122
|
-
|
|
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.
|
|
164
|
+
Fetch the React useEffect docs, index them, and find the cleanup pattern
|
|
165
|
+
with code examples. Then run /context-mode stats.
|
|
126
166
|
```
|
|
127
167
|
|
|
128
168
|
## Requirements
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Context-mode PreToolUse — intercepts Bash data-fetching and injects subagent routing",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PreToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "Bash",
|
|
7
|
+
"hooks": [
|
|
8
|
+
{
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"matcher": "Task",
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Unified PreToolUse hook for context-mode
|
|
3
|
+
# - Bash: blocks data-fetching commands (curl, wget, inline fetch)
|
|
4
|
+
# - Task: injects context-mode routing into subagent prompts
|
|
5
|
+
|
|
6
|
+
INPUT=$(cat /dev/stdin)
|
|
7
|
+
TOOL=$(echo "$INPUT" | jq -r '.tool_name // ""')
|
|
8
|
+
|
|
9
|
+
# ─── Bash: block data-fetching commands ───
|
|
10
|
+
if [ "$TOOL" = "Bash" ]; then
|
|
11
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // ""')
|
|
12
|
+
|
|
13
|
+
# curl/wget
|
|
14
|
+
if echo "$COMMAND" | grep -qiE '(^|\s|&&|\||\;)(curl|wget)\s'; then
|
|
15
|
+
cat <<'EOF'
|
|
16
|
+
{
|
|
17
|
+
"decision": "block",
|
|
18
|
+
"reason": "BLOCKED: curl/wget floods context window. Use context-mode execute instead.\n\nExample:\nmcp__context-mode__execute(language: \"javascript\", code: \"const resp = await fetch('http://...'); const data = await resp.json(); console.log(JSON.stringify(data, null, 2));\")\n\nThis runs in sandbox — only stdout enters context."
|
|
19
|
+
}
|
|
20
|
+
EOF
|
|
21
|
+
exit 0
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
# inline fetch (node -e, python -c, etc.)
|
|
25
|
+
if echo "$COMMAND" | grep -qiE 'fetch\s*\(\s*['"'"'"](https?://|http)' || \
|
|
26
|
+
echo "$COMMAND" | grep -qiE 'requests\.(get|post|put)\s*\(' || \
|
|
27
|
+
echo "$COMMAND" | grep -qiE 'http\.(get|request)\s*\('; then
|
|
28
|
+
cat <<'EOF'
|
|
29
|
+
{
|
|
30
|
+
"decision": "block",
|
|
31
|
+
"reason": "BLOCKED: Inline HTTP fetch via Bash floods context window. Use context-mode execute instead.\n\nExample:\nmcp__context-mode__execute(language: \"javascript\", code: \"const resp = await fetch('http://...'); const data = await resp.json(); console.log(JSON.stringify(data, null, 2));\")\n\nThis runs in sandbox — only stdout enters context."
|
|
32
|
+
}
|
|
33
|
+
EOF
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
# allow all other Bash commands
|
|
38
|
+
exit 0
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# ─── Task: inject context-mode routing into subagent prompts ───
|
|
42
|
+
if [ "$TOOL" = "Task" ]; then
|
|
43
|
+
ROUTING_BLOCK='
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
CONTEXT WINDOW PROTECTION — USE CONTEXT-MODE MCP TOOLS
|
|
47
|
+
|
|
48
|
+
Raw Bash/Read/WebFetch output floods your context. You have context-mode tools that keep data in sandbox.
|
|
49
|
+
|
|
50
|
+
STEP 1 — GATHER: mcp__context-mode__batch_execute(commands, queries)
|
|
51
|
+
commands: [{label: "Name", command: "shell cmd"}, ...]
|
|
52
|
+
queries: ["query1", "query2", ...] — put 5-8 queries covering everything you need.
|
|
53
|
+
Runs all commands, indexes output, returns search results. ONE call, no follow-ups.
|
|
54
|
+
|
|
55
|
+
STEP 2 — FOLLOW-UP: mcp__context-mode__search(queries: ["q1", "q2", "q3", ...])
|
|
56
|
+
Pass ALL follow-up questions as queries array. ONE call, not separate calls.
|
|
57
|
+
|
|
58
|
+
OTHER: execute(language, code) | execute_file(path, language, code) | fetch_and_index(url) + search
|
|
59
|
+
|
|
60
|
+
FORBIDDEN: Bash for output, Read for files, WebFetch. Bash is ONLY for git/mkdir/rm/mv.
|
|
61
|
+
---'
|
|
62
|
+
|
|
63
|
+
echo "$INPUT" | jq --arg routing "$ROUTING_BLOCK" '{
|
|
64
|
+
"hookSpecificOutput": {
|
|
65
|
+
"hookEventName": "PreToolUse",
|
|
66
|
+
"updatedInput": (.tool_input + { "prompt": (.tool_input.prompt + $routing) })
|
|
67
|
+
}
|
|
68
|
+
}'
|
|
69
|
+
exit 0
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
# Unknown tool — pass through
|
|
73
|
+
exit 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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
|
+
"hooks",
|
|
30
31
|
"server.bundle.mjs",
|
|
31
32
|
"skills",
|
|
32
33
|
".claude-plugin",
|