context-mode 0.6.1 → 0.7.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "description": "Context-mode PreToolUse — intercepts Bash data-fetching and injects subagent routing",
2
+ "description": "Context-mode PreToolUse — intercepts data-fetching tools, nudges toward sandbox execution",
3
3
  "hooks": {
4
4
  "PreToolUse": [
5
5
  {
@@ -11,6 +11,33 @@
11
11
  }
12
12
  ]
13
13
  },
14
+ {
15
+ "matcher": "WebFetch",
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "matcher": "Read",
25
+ "hooks": [
26
+ {
27
+ "type": "command",
28
+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "matcher": "Grep",
34
+ "hooks": [
35
+ {
36
+ "type": "command",
37
+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.sh"
38
+ }
39
+ ]
40
+ },
14
41
  {
15
42
  "matcher": "Task",
16
43
  "hooks": [
@@ -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.6.1",
16
+ "version": "0.7.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.1",
3
+ "version": "0.7.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
@@ -2,7 +2,7 @@
2
2
 
3
3
  **The other half of the context problem.**
4
4
 
5
- [![npm](https://img.shields.io/npm/v/context-mode)](https://www.npmjs.com/package/context-mode) [![marketplace](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fmksglu%2Fclaude-context-mode%2Fmain%2F.claude-plugin%2Fmarketplace.json&query=%24.plugins%5B0%5D.version&label=marketplace&color=brightgreen)](https://github.com/mksglu/claude-context-mode) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+ [![users](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fmksglu%2Fclaude-context-mode%40main%2Fstats.json&query=%24.message&label=users&color=brightgreen)](https://www.npmjs.com/package/context-mode) [![npm](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fmksglu%2Fclaude-context-mode%40main%2Fstats.json&query=%24.npm&label=npm&color=blue)](https://www.npmjs.com/package/context-mode) [![marketplace](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fmksglu%2Fclaude-context-mode%40main%2Fstats.json&query=%24.marketplace&label=marketplace&color=blue)](https://github.com/mksglu/claude-context-mode) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](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
 
@@ -59,7 +59,6 @@ Code Mode showed that tool definitions can be compressed by 99.9%. Context Mode
59
59
  | `index` | Chunk markdown into FTS5 with BM25 ranking. | 60 KB → 40 B |
60
60
  | `search` | Query indexed content with multiple queries in one call. | On-demand retrieval |
61
61
  | `fetch_and_index` | Fetch URL, convert to markdown, index. | 60 KB → 40 B |
62
- | `stats` | Session token tracking with per-tool breakdown. | — |
63
62
 
64
63
  ## How the Sandbox Works
65
64
 
@@ -77,6 +76,16 @@ The `index` tool chunks markdown content by headings while keeping code blocks i
77
76
 
78
77
  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
78
 
79
+ ## Fuzzy Search
80
+
81
+ Search uses a three-layer fallback to handle typos, partial terms, and substring matches:
82
+
83
+ - **Layer 1 — Porter stemming**: Standard FTS5 MATCH with porter tokenizer. "caching" matches "cached", "caches", "cach".
84
+ - **Layer 2 — Trigram substring**: FTS5 trigram tokenizer matches partial strings. "useEff" finds "useEffect", "authenticat" finds "authentication".
85
+ - **Layer 3 — Fuzzy correction**: Levenshtein distance corrects typos before re-searching. "kuberntes" → "kubernetes", "autentication" → "authentication".
86
+
87
+ The `searchWithFallback` method cascades through all three layers and annotates results with `matchLayer` so you know which layer resolved the query.
88
+
80
89
  ## Smart Snippets
81
90
 
82
91
  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.
@@ -93,25 +102,31 @@ This encourages batching queries via `search(queries: ["q1", "q2", "q3"])` or `b
93
102
 
94
103
  ## Session Stats
95
104
 
96
- The `stats` tool tracks context consumption in real-time. Useful for debugging context usage during long sessions.
105
+ The `stats` tool tracks context consumption in real-time. Network I/O inside the sandbox is automatically tracked for JS/TS executions.
97
106
 
98
107
  | Metric | Value |
99
108
  |---|---|
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) |
109
+ | Session | 1.4 min |
110
+ | Tool calls | 1 |
111
+ | Total data processed | **9.6MB** |
112
+ | Kept in sandbox | **9.6MB** |
113
+ | Entered context | 0.3KB |
114
+ | Tokens consumed | ~82 |
115
+ | **Context savings** | **24,576.0x (99% reduction)** |
105
116
 
106
- | Tool | Calls | Context used |
107
- |---|---|---|
108
- | batch_execute | 4 | 58.2 KB |
109
- | search | 1 | 3.8 KB |
117
+ | Tool | Calls | Context | Tokens |
118
+ |---|---|---|---|
119
+ | execute | 1 | 0.3KB | ~82 |
120
+ | **Total** | **1** | **0.3KB** | **~82** |
121
+
122
+ > Without context-mode, **9.6MB** of raw tool output would flood your context window. Instead, **9.6MB** (99%) stayed in sandbox — saving **~2,457,600 tokens** of context space.
110
123
 
111
124
  ## Subagent Routing
112
125
 
113
126
  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.
114
127
 
128
+ Bash subagents are automatically upgraded to `general-purpose` so they can access MCP tools. Without this, a `subagent_type: "Bash"` agent only has the Bash tool — it can't call `batch_execute` or `search`, and all raw output floods context.
129
+
115
130
  ## The Numbers
116
131
 
117
132
  Measured across real-world scenarios:
@@ -131,40 +146,50 @@ Over a full session: 315 KB of raw output becomes 5.4 KB. Session time before sl
131
146
 
132
147
  ## Try It
133
148
 
134
- These prompts work out of the box. Run `/context-mode stats` after each to see the savings.
149
+ These prompts work out of the box. Run `/context-mode:stats` after each to see the savings.
135
150
 
136
151
  **Deep repo research** — 5 calls, 62 KB context (raw: 986 KB, 94% saved)
137
152
  ```
138
153
  Research https://github.com/modelcontextprotocol/servers — architecture, tech stack,
139
- top contributors, open issues, and recent activity. Then run /context-mode stats.
154
+ top contributors, open issues, and recent activity. Then run /context-mode:stats.
140
155
  ```
141
156
 
142
157
  **Git history analysis** — 1 call, 5.6 KB context
143
158
  ```
144
159
  Clone https://github.com/facebook/react and analyze the last 500 commits:
145
160
  top contributors, commit frequency by month, and most changed files.
146
- Then run /context-mode stats.
161
+ Then run /context-mode:stats.
147
162
  ```
148
163
 
149
164
  **Web scraping** — 1 call, 3.2 KB context
150
165
  ```
151
166
  Fetch the Hacker News front page, extract all posts with titles, scores,
152
- and domains. Group by domain. Then run /context-mode stats.
167
+ and domains. Group by domain. Then run /context-mode:stats.
153
168
  ```
154
169
 
155
170
  **Large JSON API** — 7.5 MB raw → 0.9 KB context (99% saved)
156
171
  ```
157
172
  Create a local server that returns a 7.5 MB JSON with 20,000 records and a secret
158
173
  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.
174
+ exactly what's in it. Then run /context-mode:stats.
160
175
  ```
161
176
 
162
177
  **Documentation search** — 2 calls, 1.8 KB context
163
178
  ```
164
179
  Fetch the React useEffect docs, index them, and find the cleanup pattern
165
- with code examples. Then run /context-mode stats.
180
+ with code examples. Then run /context-mode:stats.
166
181
  ```
167
182
 
183
+ ## Slash Commands
184
+
185
+ Available when installed as a plugin:
186
+
187
+ | Command | What it does |
188
+ |---|---|
189
+ | `/context-mode:stats` | Show context savings for the current session — per-tool breakdown, tokens consumed, savings ratio. |
190
+ | `/context-mode:doctor` | Run diagnostics — checks runtimes, hooks, FTS5, plugin registration, npm and marketplace versions. |
191
+ | `/context-mode:upgrade` | Pull latest from GitHub, rebuild, reinstall plugin, update npm global, fix hooks. |
192
+
168
193
  ## Requirements
169
194
 
170
195
  - **Node.js 18+**
package/build/cli.d.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  * Usage:
6
6
  * context-mode → Start MCP server (stdio)
7
7
  * context-mode setup → Interactive setup (detect runtimes, install Bun)
8
- * context-mode doctor → Diagnose runtime issues
8
+ * context-mode doctor → Diagnose runtime issues, hooks, FTS5, version
9
+ * context-mode upgrade → Fix hooks, permissions, and settings
10
+ * context-mode stats → (skill only — /context-mode:stats)
9
11
  */
10
12
  export {};