context-mode 1.0.42 → 1.0.44

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 CHANGED
@@ -26,266 +26,315 @@ https://github.com/user-attachments/assets/07013dbf-07c0-4ef1-974a-33ea1207637b
26
26
 
27
27
  ## Install
28
28
 
29
+ Platforms are grouped by install complexity. Hook-capable platforms get automatic routing enforcement. Non-hook platforms need a one-time routing file copy.
30
+
29
31
  <details open>
30
- <summary><strong>Claude Code</strong></summary>
32
+ <summary><strong>Claude Code</strong> — plugin marketplace, fully automatic</summary>
33
+
34
+ **Prerequisites:** Claude Code v1.0.33+ (`claude --version`). If `/plugin` is not recognized, update first: `brew upgrade claude-code` or `npm update -g @anthropic-ai/claude-code`.
31
35
 
32
- **Step 1 — Install the plugin:**
36
+ **Install:**
33
37
 
34
38
  ```bash
35
39
  /plugin marketplace add mksglu/context-mode
36
40
  /plugin install context-mode@context-mode
37
41
  ```
38
42
 
39
- **Step 2 Restart Claude Code.**
43
+ Restart Claude Code (or run `/reload-plugins`).
44
+
45
+ **Verify:**
46
+
47
+ ```
48
+ /context-mode:ctx-doctor
49
+ ```
50
+
51
+ All checks should show `[x]`. The doctor validates runtimes, hooks, FTS5, and plugin registration.
40
52
 
41
- That's it. The plugin installs everything automatically:
42
- - MCP server with 6 sandbox tools (`ctx_batch_execute`, `ctx_execute`, `ctx_execute_file`, `ctx_index`, `ctx_search`, `ctx_fetch_and_index`)
43
- - PreToolUse hooks that intercept Bash, Read, WebFetch, Grep, and Task calls — nudging them toward sandbox execution
44
- - PostToolUse, PreCompact, and SessionStart hooks for session tracking and context injection
45
- - Routing instructions injected automatically via SessionStart hook (no file written to your project)
46
- - Slash commands for diagnostics and upgrades (Claude Code only)
53
+ **Routing:** Automatic. The SessionStart hook injects routing instructions at runtime — no file is written to your project. The plugin registers all hooks (PreToolUse, PostToolUse, PreCompact, SessionStart) and 6 sandbox tools (`ctx_batch_execute`, `ctx_execute`, `ctx_execute_file`, `ctx_index`, `ctx_search`, `ctx_fetch_and_index`).
47
54
 
48
- | Command | What it does |
55
+ | Slash Command | What it does |
49
56
  |---|---|
50
57
  | `/context-mode:ctx-stats` | Context savings — per-tool breakdown, tokens consumed, savings ratio. |
51
58
  | `/context-mode:ctx-doctor` | Diagnostics — runtimes, hooks, FTS5, plugin registration, versions. |
52
59
  | `/context-mode:ctx-upgrade` | Pull latest, rebuild, migrate cache, fix hooks. |
53
60
 
54
- > **Note:** Slash commands are a Claude Code plugin feature. On other platforms, all three utility commands (`ctx stats`, `ctx doctor`, `ctx upgrade`) work as MCP tools just type the command name and the model will invoke it. See [Utility Commands](#utility-commands).
61
+ > **Note:** Slash commands are a Claude Code plugin feature. On other platforms, type `ctx stats`, `ctx doctor`, or `ctx upgrade` in the chat — the model calls the MCP tool automatically. See [Utility Commands](#utility-commands).
55
62
 
56
- **Alternative — MCP-only install** (no hooks or slash commands):
63
+ <details>
64
+ <summary>Alternative — MCP-only install (no hooks or slash commands)</summary>
57
65
 
58
66
  ```bash
59
67
  claude mcp add context-mode -- npx -y context-mode
60
68
  ```
61
69
 
62
- This gives you the 6 sandbox tools but without automatic routing. The model can still use them — it just won't be nudged to prefer them over raw Bash/Read/WebFetch. Good for trying it out before committing to the full plugin.
70
+ This gives you the 6 sandbox tools without automatic routing. The model can still use them — it just won't be nudged to prefer them over raw Bash/Read/WebFetch. Good for trying it out before committing to the full plugin.
71
+
72
+ </details>
63
73
 
64
74
  </details>
65
75
 
66
76
  <details>
67
- <summary><strong>Gemini CLI</strong></summary>
77
+ <summary><strong>Gemini CLI</strong> — one config file, hooks included</summary>
68
78
 
69
- **Step 1 Install globally:**
79
+ **Prerequisites:** Node.js 18+, Gemini CLI installed.
70
80
 
71
- ```bash
72
- npm install -g context-mode
73
- ```
81
+ **Install:**
74
82
 
75
- **Step 2 Register the MCP server.** Add to `~/.gemini/settings.json`:
83
+ 1. Install context-mode globally:
76
84
 
77
- ```json
78
- {
79
- "mcpServers": {
80
- "context-mode": {
81
- "command": "context-mode"
82
- }
83
- }
84
- }
85
- ```
85
+ ```bash
86
+ npm install -g context-mode
87
+ ```
86
88
 
87
- **Step 3 — Add hooks.** Without hooks, the model can ignore routing instructions and dump raw output into your context window. Hooks intercept every tool call and enforce sandbox routing programmatically — blocking `curl`, `wget`, and other data-heavy commands before they execute. Add to the same `~/.gemini/settings.json`:
89
+ 2. Add the following to `~/.gemini/settings.json`. This single file registers the MCP server and all four hooks:
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "context-mode": {
95
+ "command": "context-mode"
96
+ }
97
+ },
98
+ "hooks": {
99
+ "BeforeTool": [
100
+ {
101
+ "matcher": "run_shell_command|read_file|read_many_files|grep_search|search_file_content|web_fetch|activate_skill|mcp__plugin_context-mode",
102
+ "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli beforetool" }]
103
+ }
104
+ ],
105
+ "AfterTool": [
106
+ {
107
+ "matcher": "",
108
+ "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli aftertool" }]
109
+ }
110
+ ],
111
+ "PreCompress": [
112
+ {
113
+ "matcher": "",
114
+ "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli precompress" }]
115
+ }
116
+ ],
117
+ "SessionStart": [
118
+ {
119
+ "matcher": "",
120
+ "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli sessionstart" }]
121
+ }
122
+ ]
123
+ }
124
+ }
125
+ ```
126
+
127
+ 3. Restart Gemini CLI.
128
+
129
+ **Verify:**
88
130
 
89
- ```json
90
- {
91
- "hooks": {
92
- "BeforeTool": [
93
- {
94
- "matcher": "",
95
- "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli beforetool" }]
96
- }
97
- ],
98
- "AfterTool": [
99
- {
100
- "matcher": "",
101
- "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli aftertool" }]
102
- }
103
- ],
104
- "SessionStart": [
105
- {
106
- "matcher": "",
107
- "hooks": [{ "type": "command", "command": "context-mode hook gemini-cli sessionstart" }]
108
- }
109
- ]
110
- }
111
- }
112
131
  ```
132
+ /mcp list
133
+ ```
134
+
135
+ You should see `context-mode: ... - Connected`.
113
136
 
114
- **Step 4 Restart Gemini CLI.** Routing instructions are injected automatically via the SessionStart hook — no file is written to your project. Hooks handle all enforcement programmatically.
137
+ **Routing:** Automatic. The SessionStart hook injects routing instructions at runtime — no `GEMINI.md` file is written to your project. All four hooks (BeforeTool, AfterTool, PreCompress, SessionStart) handle enforcement programmatically.
115
138
 
116
- > **Why hooks matter:** Without hooks, context-mode relies on `GEMINI.md` instructions alone (~60% compliance). The model sometimes follows them, but regularly runs raw `curl`, reads large files directly, or dumps unprocessed output into context a single unrouted Playwright snapshot (56 KB) wipes out an entire session's savings. With hooks, every tool call is intercepted before execution dangerous commands are blocked, and routing guidance is injected in real-time. This is the difference between ~60% and ~98% context savings.
139
+ > **Why the BeforeTool matcher?** It targets only tools that produce large output (`run_shell_command`, `read_file`, `read_many_files`, `grep_search`, `search_file_content`, `web_fetch`, `activate_skill`) plus context-mode's own tools (`mcp__plugin_context-mode`). This avoids unnecessary hook overhead on lightweight tools while intercepting every tool that could flood your context window.
117
140
 
118
- Full hook config including PreCompress: [`configs/gemini-cli/settings.json`](configs/gemini-cli/settings.json)
141
+ Full config reference: [`configs/gemini-cli/settings.json`](configs/gemini-cli/settings.json)
119
142
 
120
143
  </details>
121
144
 
122
145
  <details>
123
- <summary><strong>VS Code Copilot</strong></summary>
146
+ <summary><strong>VS Code Copilot</strong> — hooks with SessionStart</summary>
124
147
 
125
- **Step 1 Install globally:**
148
+ **Prerequisites:** Node.js 18+, VS Code with Copilot Chat v0.32+.
126
149
 
127
- ```bash
128
- npm install -g context-mode
129
- ```
150
+ **Install:**
130
151
 
131
- **Step 2 — Register the MCP server.** Create `.vscode/mcp.json` in your project root:
152
+ 1. Install context-mode globally:
132
153
 
133
- ```json
134
- {
135
- "servers": {
136
- "context-mode": {
137
- "command": "context-mode"
138
- }
139
- }
140
- }
141
- ```
154
+ ```bash
155
+ npm install -g context-mode
156
+ ```
142
157
 
143
- **Step 3 — Add hooks.** Without hooks, the model can bypass routing and dump raw output into your context. Hooks intercept every tool call and enforce sandbox routing programmatically. Create `.github/hooks/context-mode.json`:
158
+ 2. Create `.vscode/mcp.json` in your project root:
144
159
 
145
- ```json
146
- {
147
- "hooks": {
148
- "PreToolUse": [
149
- { "type": "command", "command": "context-mode hook vscode-copilot pretooluse" }
150
- ],
151
- "PostToolUse": [
152
- { "type": "command", "command": "context-mode hook vscode-copilot posttooluse" }
153
- ],
154
- "SessionStart": [
155
- { "type": "command", "command": "context-mode hook vscode-copilot sessionstart" }
156
- ]
157
- }
158
- }
159
- ```
160
+ ```json
161
+ {
162
+ "servers": {
163
+ "context-mode": {
164
+ "command": "context-mode"
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ 3. Create `.github/hooks/context-mode.json`:
171
+
172
+ ```json
173
+ {
174
+ "hooks": {
175
+ "PreToolUse": [
176
+ { "type": "command", "command": "context-mode hook vscode-copilot pretooluse" }
177
+ ],
178
+ "PostToolUse": [
179
+ { "type": "command", "command": "context-mode hook vscode-copilot posttooluse" }
180
+ ],
181
+ "SessionStart": [
182
+ { "type": "command", "command": "context-mode hook vscode-copilot sessionstart" }
183
+ ]
184
+ }
185
+ }
186
+ ```
187
+
188
+ 4. Restart VS Code.
160
189
 
161
- **Step 4 Restart VS Code.** Routing instructions are injected automatically via the SessionStart hook — no file is written to your project. Hooks handle all enforcement programmatically.
190
+ **Verify:** Open Copilot Chat and type `ctx stats`. Context-mode tools should appear and respond.
162
191
 
163
- > **Why hooks matter:** Without hooks, `copilot-instructions.md` guides the model but can't block commands. A single unrouted Playwright snapshot (56 KB) or `gh issue list` (59 KB) wipes out minutes of context savings. With hooks, these calls are intercepted and redirected to the sandbox before they execute.
192
+ **Routing:** Automatic. The SessionStart hook injects routing instructions at runtime no `copilot-instructions.md` file is written to your project.
164
193
 
165
194
  Full hook config including PreCompact: [`configs/vscode-copilot/hooks.json`](configs/vscode-copilot/hooks.json)
166
195
 
167
196
  </details>
168
197
 
169
198
  <details>
170
- <summary><strong>Cursor</strong></summary>
199
+ <summary><strong>Cursor</strong> — hooks without SessionStart</summary>
171
200
 
172
- **Step 1 Install globally:**
201
+ **Prerequisites:** Node.js 18+, Cursor with agent mode.
173
202
 
174
- ```bash
175
- npm install -g context-mode
176
- ```
203
+ **Install:**
177
204
 
178
- **Step 2 — Register the MCP server.** Create `.cursor/mcp.json` in your project root or `~/.cursor/mcp.json` for a global install:
205
+ 1. Install context-mode globally:
179
206
 
180
- ```json
181
- {
182
- "mcpServers": {
183
- "context-mode": {
184
- "command": "context-mode"
185
- }
186
- }
187
- }
188
- ```
207
+ ```bash
208
+ npm install -g context-mode
209
+ ```
189
210
 
190
- **Step 3 — Add native Cursor hooks.** Cursor v1 support uses native `.cursor/hooks.json` or `~/.cursor/hooks.json` only. Create either path with:
211
+ 2. Create `.cursor/mcp.json` in your project root (or `~/.cursor/mcp.json` for global):
191
212
 
192
- ```json
193
- {
194
- "version": 1,
195
- "hooks": {
196
- "preToolUse": [
197
- {
198
- "command": "context-mode hook cursor pretooluse",
199
- "matcher": "Shell|Read|Grep|WebFetch|Task|MCP:ctx_execute|MCP:ctx_execute_file|MCP:ctx_batch_execute"
200
- }
201
- ],
202
- "postToolUse": [
203
- {
204
- "command": "context-mode hook cursor posttooluse"
205
- }
206
- ]
207
- }
208
- }
209
- ```
213
+ ```json
214
+ {
215
+ "mcpServers": {
216
+ "context-mode": {
217
+ "command": "context-mode"
218
+ }
219
+ }
220
+ }
221
+ ```
210
222
 
211
- Note: the `preToolUse` hook matcher is optional. If you don't provide it, the hook will fire on all tools.
223
+ 3. Create `.cursor/hooks.json` (or `~/.cursor/hooks.json` for global):
212
224
 
213
- **Step 4 — Restart Cursor or open a new agent session.** Routing is enforced via the `preToolUse` hook. Since Cursor lacks SessionStart support, you may want to manually add routing instructions — copy `configs/cursor/.cursorrules` to your project root as `.cursorrules`, or place it in `.cursor/rules/`.
225
+ ```json
226
+ {
227
+ "version": 1,
228
+ "hooks": {
229
+ "preToolUse": [
230
+ {
231
+ "command": "context-mode hook cursor pretooluse",
232
+ "matcher": "Shell|Read|Grep|WebFetch|Task|MCP:ctx_execute|MCP:ctx_execute_file|MCP:ctx_batch_execute"
233
+ }
234
+ ],
235
+ "postToolUse": [
236
+ {
237
+ "command": "context-mode hook cursor posttooluse"
238
+ }
239
+ ]
240
+ }
241
+ }
242
+ ```
214
243
 
215
- > **Native Cursor scope:** `preToolUse` and `postToolUse` are supported. `sessionStart` is documented by Cursor but currently rejected by their validator ([forum report](https://forum.cursor.com/t/unknown-hook-type-sessionstart/149566)).
216
- >
217
- > **Config precedence:** project `.cursor/hooks.json` overrides `~/.cursor/hooks.json`.
244
+ The `preToolUse` matcher is optional without it, the hook fires on all tools.
245
+
246
+ 4. Copy the routing rules file. Cursor lacks a SessionStart hook, so the model needs a rules file for routing awareness:
247
+
248
+ ```bash
249
+ mkdir -p .cursor/rules
250
+ cp node_modules/context-mode/configs/cursor/context-mode.mdc .cursor/rules/context-mode.mdc
251
+ ```
252
+
253
+ 5. Restart Cursor or open a new agent session.
254
+
255
+ **Verify:** Open Cursor Settings > MCP and confirm "context-mode" shows as connected. In agent chat, type `ctx stats`.
218
256
 
219
- Full native hook config: [`configs/cursor/hooks.json`](configs/cursor/hooks.json)
220
- Example MCP registration: [`configs/cursor/mcp.json`](configs/cursor/mcp.json)
257
+ **Routing:** Hooks enforce routing programmatically via `preToolUse`/`postToolUse`. The `.cursor/rules/context-mode.mdc` file provides routing instructions at session start since Cursor's `sessionStart` hook is currently rejected by their validator ([forum report](https://forum.cursor.com/t/unknown-hook-type-sessionstart/149566)). Project `.cursor/hooks.json` overrides `~/.cursor/hooks.json`.
258
+
259
+ Full configs: [`configs/cursor/hooks.json`](configs/cursor/hooks.json) | [`configs/cursor/mcp.json`](configs/cursor/mcp.json) | [`configs/cursor/context-mode.mdc`](configs/cursor/context-mode.mdc)
221
260
 
222
261
  </details>
223
262
 
224
263
  <details>
225
- <summary><strong>OpenCode</strong></summary>
264
+ <summary><strong>OpenCode</strong> — TypeScript plugin with hooks</summary>
226
265
 
227
- **Step 1 Install globally:**
266
+ **Prerequisites:** Node.js 18+, OpenCode installed.
228
267
 
229
- ```bash
230
- npm install -g context-mode
231
- ```
268
+ **Install:**
232
269
 
233
- **Step 2 — Register the MCP server and plugin.** OpenCode uses a TypeScript plugin paradigm instead of JSON hooks. Add both the MCP server and the plugin to `opencode.json` in your project root:
270
+ 1. Install context-mode globally:
234
271
 
235
- ```json
236
- {
237
- "$schema": "https://opencode.ai/config.json",
238
- "mcp": {
239
- "context-mode": {
240
- "type": "local",
241
- "command": ["context-mode"]
242
- }
243
- },
244
- "plugin": ["context-mode"]
245
- }
246
- ```
272
+ ```bash
273
+ npm install -g context-mode
274
+ ```
247
275
 
248
- The `mcp` entry gives you the 6 sandbox tools. The `plugin` entry enables hooks OpenCode calls the plugin's TypeScript functions directly before and after each tool execution, blocking dangerous commands (like raw `curl`) and enforcing sandbox routing.
276
+ 2. Add to `opencode.json` in your project root (or `~/.config/opencode/opencode.json` for global):
249
277
 
250
- **Step 3 — Restart OpenCode.** The plugin intercepts tool calls at runtime via `tool.execute.before` and `tool.execute.after`, enforcing sandbox routing programmatically. No routing file is written to your project.
278
+ ```json
279
+ {
280
+ "$schema": "https://opencode.ai/config.json",
281
+ "mcp": {
282
+ "context-mode": {
283
+ "type": "local",
284
+ "command": ["context-mode"]
285
+ }
286
+ },
287
+ "plugin": ["context-mode"]
288
+ }
289
+ ```
251
290
 
252
- > **Why the plugin matters:** Without the `plugin` entry, context-mode has no way to intercept tool calls. The model can run raw `curl`, read large files directly, or dump unprocessed output into context. With the plugin, `tool.execute.before` fires on every tool call and blocks or redirects data-heavy commands before they execute. The `experimental.session.compacting` hook builds and injects resume snapshots when the conversation compacts, preserving session state.
253
- >
254
- > Note: OpenCode's SessionStart hook is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume session restore is not supported. Compaction recovery works fully via the plugin.
291
+ The `mcp` entry registers the 6 sandbox tools. The `plugin` entry enables hooks OpenCode calls the plugin's TypeScript functions directly before and after each tool execution, blocking dangerous commands and enforcing sandbox routing.
292
+
293
+ 3. Restart OpenCode.
294
+
295
+ **Verify:** In the OpenCode session, type `ctx stats`. Context-mode tools should appear and respond.
296
+
297
+ **Routing:** Automatic. The plugin intercepts tool calls at runtime via `tool.execute.before` and `tool.execute.after`. No routing file is written to your project. The `experimental.session.compacting` hook builds resume snapshots when the conversation compacts.
298
+
299
+ > **Note:** OpenCode's SessionStart hook is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume session restore is not supported. Compaction recovery works fully via the plugin.
300
+
301
+ Full config: [`configs/opencode/opencode.json`](configs/opencode/opencode.json)
255
302
 
256
303
  </details>
257
304
 
258
305
  <details>
259
- <summary><strong>OpenClaw / Pi Agent</strong></summary>
306
+ <summary><strong>OpenClaw / Pi Agent</strong> — native gateway plugin</summary>
260
307
 
261
308
  **Prerequisites:** OpenClaw gateway running ([>2026.1.29](https://github.com/openclaw/openclaw/pull/9761)), Node.js 22+.
262
309
 
263
310
  context-mode runs as a native [OpenClaw](https://github.com/openclaw) gateway plugin, targeting **Pi Agent** sessions (Read/Write/Edit/Bash tools). Unlike other platforms, there's no separate MCP server — the plugin registers directly into the gateway runtime via OpenClaw's [plugin API](https://docs.openclaw.ai/tools/plugin).
264
311
 
265
- **Step 1 — Clone and install:**
312
+ **Install:**
266
313
 
267
- ```bash
268
- git clone https://github.com/mksglu/context-mode.git
269
- cd context-mode
270
- npm run install:openclaw
271
- ```
314
+ 1. Clone and install:
272
315
 
273
- The installer uses `$OPENCLAW_STATE_DIR` from your environment (default: `/openclaw`). To specify a custom path:
316
+ ```bash
317
+ git clone https://github.com/mksglu/context-mode.git
318
+ cd context-mode
319
+ npm run install:openclaw
320
+ ```
274
321
 
275
- ```bash
276
- npm run install:openclaw -- /path/to/openclaw-state
277
- ```
322
+ The installer uses `$OPENCLAW_STATE_DIR` from your environment (default: `/openclaw`). To specify a custom path:
278
323
 
279
- Common locations:
280
- - **Docker:** `/openclaw` (the default)
281
- - **Local:** `~/.openclaw` or wherever you set `OPENCLAW_STATE_DIR`
324
+ ```bash
325
+ npm run install:openclaw -- /path/to/openclaw-state
326
+ ```
282
327
 
283
- The installer handles everything: `npm install`, `npm run build`, `better-sqlite3` native rebuild, extension registration in `runtime.json`, and gateway restart via SIGUSR1.
328
+ Common locations: **Docker** `/openclaw` (the default). **Local** `~/.openclaw` or wherever you set `OPENCLAW_STATE_DIR`.
284
329
 
285
- **Step 2 — Verify.** Open a Pi Agent session. The plugin registers 8 hooks via [`api.on()`](https://docs.openclaw.ai/tools/plugin) (lifecycle) and [`api.registerHook()`](https://docs.openclaw.ai/tools/plugin) (commands). All tool interception, session tracking, and compaction recovery hooks activate automatically — no manual hook configuration or routing file needed.
330
+ The installer handles everything: `npm install`, `npm run build`, `better-sqlite3` native rebuild, extension registration in `runtime.json`, and gateway restart via SIGUSR1.
331
+
332
+ 2. Open a Pi Agent session.
333
+
334
+ **Verify:** The plugin registers 8 hooks via [`api.on()`](https://docs.openclaw.ai/tools/plugin) (lifecycle) and [`api.registerHook()`](https://docs.openclaw.ai/tools/plugin) (commands). Type `ctx stats` to confirm tools are loaded.
335
+
336
+ **Routing:** Automatic. All tool interception, session tracking, and compaction recovery hooks activate automatically — no manual hook configuration or routing file needed.
286
337
 
287
- > **Why native plugin?** OpenClaw doesn't support shell-based hooks like Claude Code or Gemini CLI. Instead, plugins register TypeScript functions directly into the gateway runtime. This gives full access to tool interception, argument mutation, and session context injection — equivalent to the hook-based approach on other platforms.
288
- >
289
338
  > **Minimum version:** OpenClaw >2026.1.29 — this includes the `api.on()` lifecycle fix from [PR #9761](https://github.com/openclaw/openclaw/pull/9761). On older versions, lifecycle hooks silently fail. The adapter falls back to DB snapshot reconstruction (less precise but preserves critical state).
290
339
 
291
340
  Full documentation: [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md)
@@ -293,191 +342,216 @@ Full documentation: [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md)
293
342
  </details>
294
343
 
295
344
  <details>
296
- <summary><strong>Codex CLI</strong></summary>
345
+ <summary><strong>Codex CLI</strong> — MCP-only, no hooks</summary>
297
346
 
298
- **Step 1 Install globally:**
347
+ **Prerequisites:** Node.js 18+, Codex CLI installed.
299
348
 
300
- ```bash
301
- npm install -g context-mode
302
- ```
349
+ **Install:**
303
350
 
304
- **Step 2 Register the MCP server.** Add to `~/.codex/config.toml`:
351
+ 1. Install context-mode globally:
305
352
 
306
- ```toml
307
- [mcp_servers.context-mode]
308
- command = "context-mode"
309
- ```
353
+ ```bash
354
+ npm install -g context-mode
355
+ ```
310
356
 
311
- **Step 3 — Copy routing instructions.** Codex CLI has no hook support, so you need to manually add the routing file:
357
+ 2. Add to `~/.codex/config.toml`:
312
358
 
313
- ```bash
314
- # Copy to project root
315
- cp node_modules/context-mode/configs/codex/AGENTS.md ./AGENTS.md
359
+ ```toml
360
+ [mcp_servers.context-mode]
361
+ command = "context-mode"
362
+ ```
316
363
 
317
- # Or for global use
318
- cp node_modules/context-mode/configs/codex/AGENTS.md ~/.codex/AGENTS.md
319
- ```
364
+ 3. Copy routing instructions (Codex CLI has no hook support):
320
365
 
321
- Global `~/.codex/AGENTS.md` applies to all projects. Project-level `./AGENTS.md` applies to the current project only. If both exist, Codex CLI merges them.
366
+ ```bash
367
+ cp node_modules/context-mode/configs/codex/AGENTS.md ./AGENTS.md
368
+ ```
322
369
 
323
- **Step 4 Restart Codex CLI.** Codex CLI reads `AGENTS.md` automatically and learns to prefer context-mode sandbox tools.
370
+ For global use: `cp node_modules/context-mode/configs/codex/AGENTS.md ~/.codex/AGENTS.md`. Global applies to all projects. If both exist, Codex CLI merges them.
324
371
 
325
- **About hooks:** Codex CLI does not support hooks — PRs [#2904](https://github.com/openai/codex/pull/2904) and [#9796](https://github.com/openai/codex/pull/9796) were closed without merge. The `AGENTS.md` routing instructions file is the only enforcement method (~60% compliance). The model receives the instructions at session start and sometimes follows them, but there is no programmatic interception — it can run raw `curl`, read large files, or bypass sandbox tools at any time.
372
+ 4. Restart Codex CLI.
373
+
374
+ **Verify:** Start a session and type `ctx stats`. Context-mode tools should appear and respond.
375
+
376
+ **Routing:** Manual. The `AGENTS.md` file is the only enforcement method (~60% compliance). There is no programmatic interception — the model can run raw `curl`, read large files, or bypass sandbox tools at any time. Hook support PRs [#2904](https://github.com/openai/codex/pull/2904) and [#9796](https://github.com/openai/codex/pull/9796) were closed without merge.
326
377
 
327
378
  </details>
328
379
 
329
380
  <details>
330
- <summary><strong>Antigravity</strong></summary>
381
+ <summary><strong>Antigravity</strong> — MCP-only, no hooks</summary>
331
382
 
332
- **Step 1 Install globally:**
383
+ **Prerequisites:** Node.js 18+, Antigravity installed.
333
384
 
334
- ```bash
335
- npm install -g context-mode
336
- ```
385
+ **Install:**
337
386
 
338
- **Step 2 Register the MCP server.** Add to `~/.gemini/antigravity/mcp_config.json`:
387
+ 1. Install context-mode globally:
339
388
 
340
- ```json
341
- {
342
- "mcpServers": {
343
- "context-mode": {
344
- "command": "context-mode"
345
- }
346
- }
347
- }
348
- ```
389
+ ```bash
390
+ npm install -g context-mode
391
+ ```
349
392
 
350
- **Step 3 — Copy routing instructions.** Antigravity has no hook support, so you need to manually add the routing file:
393
+ 2. Add to `~/.gemini/antigravity/mcp_config.json`:
351
394
 
352
- ```bash
353
- cp node_modules/context-mode/configs/antigravity/GEMINI.md ./GEMINI.md
354
- ```
395
+ ```json
396
+ {
397
+ "mcpServers": {
398
+ "context-mode": {
399
+ "command": "context-mode"
400
+ }
401
+ }
402
+ }
403
+ ```
404
+
405
+ 3. Copy routing instructions (Antigravity has no hook support):
355
406
 
356
- **Step 4 — Restart Antigravity.** Antigravity reads `GEMINI.md` automatically and learns to prefer context-mode sandbox tools.
407
+ ```bash
408
+ cp node_modules/context-mode/configs/antigravity/GEMINI.md ./GEMINI.md
409
+ ```
357
410
 
358
- **About hooks:** Antigravity does not support hooks — there is no public hook API. The `GEMINI.md` routing instructions file is the only enforcement method (~60% compliance). The model receives the instructions at session start and sometimes follows them, but there is no programmatic interception — it can run raw `run_command`, read large files via `view_file`, or bypass sandbox tools at any time.
411
+ 4. Restart Antigravity.
359
412
 
360
- **Auto-detection:** context-mode detects Antigravity automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
413
+ **Verify:** In an Antigravity session, type `ctx stats`. Context-mode tools should appear and respond.
361
414
 
362
- Example MCP config: [`configs/antigravity/mcp_config.json`](configs/antigravity/mcp_config.json)
363
- Routing rules: [`configs/antigravity/GEMINI.md`](configs/antigravity/GEMINI.md)
415
+ **Routing:** Manual. The `GEMINI.md` file is the only enforcement method (~60% compliance). There is no programmatic interception. Auto-detected via MCP protocol handshake (`clientInfo.name`) — no manual platform configuration needed.
416
+
417
+ Full configs: [`configs/antigravity/mcp_config.json`](configs/antigravity/mcp_config.json) | [`configs/antigravity/GEMINI.md`](configs/antigravity/GEMINI.md)
364
418
 
365
419
  </details>
366
420
 
367
421
  <details>
368
- <summary><strong>Kiro</strong></summary>
422
+ <summary><strong>Kiro</strong> — hooks with steering file</summary>
369
423
 
370
- **Step 1 Install globally:**
424
+ **Prerequisites:** Node.js 18+, Kiro with MCP enabled (Settings > search "MCP").
371
425
 
372
- ```bash
373
- npm install -g context-mode
374
- ```
426
+ **Install:**
375
427
 
376
- **Step 2 — Register the MCP server.** Add to `.kiro/settings/mcp.json` in your project root (or `~/.kiro/settings/mcp.json` for global):
428
+ 1. Install context-mode globally:
377
429
 
378
- ```json
379
- {
380
- "mcpServers": {
381
- "context-mode": {
382
- "command": "context-mode"
383
- }
384
- }
385
- }
386
- ```
430
+ ```bash
431
+ npm install -g context-mode
432
+ ```
387
433
 
388
- **Step 3 — Add hooks.** Without hooks, the model can bypass routing and dump raw output into your context. Hooks intercept every tool call and enforce sandbox routing programmatically. Create `.kiro/hooks/context-mode.json` (or copy from [`configs/kiro/agent.json`](configs/kiro/agent.json)):
434
+ 2. Add to `.kiro/settings/mcp.json` in your project (or `~/.kiro/settings/mcp.json` for global):
389
435
 
390
- ```json
391
- {
392
- "name": "context-mode",
393
- "description": "Context-mode hooks for context window protection",
394
- "hooks": {
395
- "preToolUse": [
396
- { "matcher": "*", "command": "context-mode hook kiro pretooluse" }
397
- ],
398
- "postToolUse": [
399
- { "matcher": "*", "command": "context-mode hook kiro posttooluse" }
400
- ]
401
- }
402
- }
403
- ```
436
+ ```json
437
+ {
438
+ "mcpServers": {
439
+ "context-mode": {
440
+ "command": "context-mode"
441
+ }
442
+ }
443
+ }
444
+ ```
404
445
 
405
- **Step 4 — Copy routing instructions.** Kiro's `preToolUse`/`postToolUse` hooks enforce sandbox routing, but since `agentSpawn` (SessionStart) is not yet implemented, you should manually add the routing file so the model gets instructions at session start:
446
+ 3. Create `.kiro/hooks/context-mode.json`:
406
447
 
407
- ```bash
408
- cp node_modules/context-mode/configs/kiro/KIRO.md ./KIRO.md
409
- ```
448
+ ```json
449
+ {
450
+ "name": "context-mode",
451
+ "description": "Context-mode hooks for context window protection",
452
+ "hooks": {
453
+ "preToolUse": [
454
+ { "matcher": "*", "command": "context-mode hook kiro pretooluse" }
455
+ ],
456
+ "postToolUse": [
457
+ { "matcher": "*", "command": "context-mode hook kiro posttooluse" }
458
+ ]
459
+ }
460
+ }
461
+ ```
462
+
463
+ 4. Copy routing instructions. Kiro's `agentSpawn` (SessionStart) is not yet implemented, so the model needs a routing file at session start:
464
+
465
+ ```bash
466
+ cp node_modules/context-mode/configs/kiro/KIRO.md ./KIRO.md
467
+ ```
468
+
469
+ 5. Restart Kiro.
410
470
 
411
- **Step 5 Restart Kiro.**
471
+ **Verify:** Open the Kiro panel > MCP Servers tab and confirm "context-mode" shows a green status indicator. In chat, type `ctx stats`.
412
472
 
413
- **Auto-detection:** context-mode detects Kiro automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
473
+ **Routing:** Hooks enforce routing programmatically via `preToolUse`/`postToolUse`. The `KIRO.md` file provides routing instructions since `agentSpawn` (SessionStart equivalent) is not yet wired. Tool names appear as `@context-mode/ctx_batch_execute`, `@context-mode/ctx_search`, etc. Auto-detected via MCP protocol handshake.
474
+
475
+ Full configs: [`configs/kiro/mcp.json`](configs/kiro/mcp.json) | [`configs/kiro/agent.json`](configs/kiro/agent.json) | [`configs/kiro/KIRO.md`](configs/kiro/KIRO.md)
414
476
 
415
477
  </details>
416
478
 
417
479
  <details>
418
- <summary><strong>Zed</strong></summary>
480
+ <summary><strong>Zed</strong> — MCP-only, no hooks</summary>
419
481
 
420
- **Step 1 Install globally:**
482
+ **Prerequisites:** Node.js 18+, Zed installed.
421
483
 
422
- ```bash
423
- npm install -g context-mode
424
- ```
484
+ **Install:**
425
485
 
426
- **Step 2 Add to Zed settings** (`~/.config/zed/settings.json`):
486
+ 1. Install context-mode globally:
427
487
 
428
- ```json
429
- {
430
- "context_servers": {
431
- "context-mode": {
432
- "command": {
433
- "path": "context-mode"
434
- }
435
- }
436
- }
437
- }
438
- ```
488
+ ```bash
489
+ npm install -g context-mode
490
+ ```
439
491
 
440
- **Step 3 Copy routing instructions.** Zed has no hook support, so you need to manually add the routing file:
492
+ 2. Add to `~/.config/zed/settings.json` (Windows: `%APPDATA%\Zed\settings.json`):
441
493
 
442
- ```bash
443
- cp node_modules/context-mode/configs/zed/AGENTS.md ./AGENTS.md
444
- ```
494
+ ```json
495
+ {
496
+ "context_servers": {
497
+ "context-mode": {
498
+ "command": {
499
+ "path": "context-mode"
500
+ }
501
+ }
502
+ }
503
+ }
504
+ ```
505
+
506
+ Note: Zed uses `"context_servers"` and `"command": { "path": "..." }` syntax, not `"mcpServers"` or `"command": "..."` like other platforms.
507
+
508
+ 3. Copy routing instructions (Zed has no hook support):
445
509
 
446
- **Step 4 — Restart Zed.** Zed reads the MCP tools and the model learns to prefer context-mode sandbox tools.
510
+ ```bash
511
+ cp node_modules/context-mode/configs/zed/AGENTS.md ./AGENTS.md
512
+ ```
447
513
 
448
- **About hooks:** Zed does not support hooks — there is no public hook or extension API for tool-use lifecycle events. The `AGENTS.md` routing instructions file is the only enforcement method (~60% compliance). The model receives the instructions at session start and sometimes follows them, but there is no programmatic interception.
514
+ 4. Restart Zed (or save `settings.json` Zed auto-restarts context servers on config change).
449
515
 
450
- **Auto-detection:** context-mode detects Zed automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
516
+ **Verify:** Open the Agent Panel (`Cmd+Shift+A`), go to settings, and check the indicator dot next to "context-mode" — green means active. Type `ctx stats` in the agent chat.
517
+
518
+ **Routing:** Manual. The `AGENTS.md` file is the only enforcement method (~60% compliance). There is no programmatic interception. Tool names appear as `mcp:context-mode:ctx_batch_execute`, `mcp:context-mode:ctx_search`, etc. Auto-detected via MCP protocol handshake.
451
519
 
452
520
  </details>
453
521
 
454
522
  <details>
455
- <summary><strong>Pi Coding Agent</strong></summary>
523
+ <summary><strong>Pi Coding Agent</strong> — extension with full hook support</summary>
456
524
 
457
- **Step 1 Install the extension:**
525
+ **Prerequisites:** Node.js 18+, Pi Coding Agent installed.
458
526
 
459
- ```bash
460
- git clone https://github.com/mksglu/context-mode.git ~/.pi/extensions/context-mode
461
- cd ~/.pi/extensions/context-mode
462
- npm install
463
- ```
527
+ **Install:**
464
528
 
465
- **Step 2 Add MCP server** to `~/.pi/settings/mcp.json` or `.pi/settings/mcp.json`:
529
+ 1. Clone the extension:
466
530
 
467
- ```json
468
- {
469
- "mcpServers": {
470
- "context-mode": {
471
- "command": "node",
472
- "args": ["~/.pi/extensions/context-mode/node_modules/context-mode/start.mjs"]
473
- }
474
- }
475
- }
476
- ```
531
+ ```bash
532
+ git clone https://github.com/mksglu/context-mode.git ~/.pi/extensions/context-mode
533
+ cd ~/.pi/extensions/context-mode
534
+ npm install
535
+ ```
536
+
537
+ 2. Add to `~/.pi/settings/mcp.json` (or `.pi/settings/mcp.json` for project-level):
538
+
539
+ ```json
540
+ {
541
+ "mcpServers": {
542
+ "context-mode": {
543
+ "command": "node",
544
+ "args": ["~/.pi/extensions/context-mode/node_modules/context-mode/start.mjs"]
545
+ }
546
+ }
547
+ }
548
+ ```
549
+
550
+ 3. Restart Pi.
477
551
 
478
- **Step 3 Restart Pi.**
552
+ **Verify:** In a Pi session, type `ctx stats`. Context-mode tools should appear and respond.
479
553
 
480
- The extension handles session continuity (event capture, resume snapshots, compaction recovery). The MCP server provides sandbox tools (batch_execute, execute, search, etc.).
554
+ **Routing:** Automatic. The extension registers all key lifecycle events (`tool_call`, `tool_result`, `session_start`, `session_before_compact`), providing full session continuity and routing enforcement.
481
555
 
482
556
  </details>
483
557
 
@@ -719,7 +793,7 @@ Hooks intercept tool calls programmatically — they can block dangerous command
719
793
  | Claude Code | Yes (auto) | [`CLAUDE.md`](configs/claude-code/CLAUDE.md) | **~98% saved** | ~60% saved |
720
794
  | Gemini CLI | Yes | [`GEMINI.md`](configs/gemini-cli/GEMINI.md) | **~98% saved** | ~60% saved |
721
795
  | VS Code Copilot | Yes | [`copilot-instructions.md`](configs/vscode-copilot/copilot-instructions.md) | **~98% saved** | ~60% saved |
722
- | Cursor | Yes | -- | **~98% saved** | Manual tool choice |
796
+ | Cursor | Yes | [`context-mode.mdc`](configs/cursor/context-mode.mdc) | **~98% saved** | ~60% saved |
723
797
  | OpenCode | Plugin | [`AGENTS.md`](configs/opencode/AGENTS.md) | **~98% saved** | ~60% saved |
724
798
  | OpenClaw | Plugin | [`AGENTS.md`](configs/openclaw/AGENTS.md) | **~98% saved** | ~60% saved |
725
799
  | Codex CLI | -- | [`AGENTS.md`](configs/codex/AGENTS.md) | -- | ~60% saved |