context-mode 2.1.10 → 2.2.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/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +2 -2
- package/.zcode-plugin/plugin.json +2 -2
- package/README.md +98 -79
- package/SHA256SUMS +21 -20
- package/cli.mjs +438 -99
- package/copilot/plugin.json +2 -2
- package/fixtures/hook-roundtrip.json +13 -0
- package/gemini-extension.json +2 -2
- package/hook.mjs +97 -97
- package/omp/index.js +5 -0
- package/opencode/plugin.js +823 -438
- package/package.json +9 -2
- package/pi/index.js +888 -465
- package/qwen-extension.json +2 -2
- package/run.mjs +136 -47
- package/search.mjs +136 -47
- package/server.mjs +704 -419
- package/skills/ctx-doctor/SKILL.md +1 -1
- package/skills/ctx-stats/SKILL.md +1 -1
- package/skills/ctx-upgrade/SKILL.md +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "Context window saver for
|
|
2
|
+
"description": "Context window saver for 11 coding agents. Local and free: sandboxed code execution, FTS5 search, session continuity.",
|
|
3
3
|
"name": "context-mode",
|
|
4
4
|
"owner": {
|
|
5
5
|
"name": "context-mode"
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"name": "Mert Koseoglu",
|
|
11
11
|
"url": "https://github.com/mksglu/context-mode#readme"
|
|
12
12
|
},
|
|
13
|
-
"description": "Context window saver for
|
|
13
|
+
"description": "Context window saver for 11 coding agents. Local and free: sandboxed code execution, FTS5 search, session continuity.",
|
|
14
14
|
"name": "context-mode",
|
|
15
15
|
"source": "./",
|
|
16
|
-
"version": "2.1
|
|
16
|
+
"version": "2.2.1"
|
|
17
17
|
}
|
|
18
18
|
]
|
|
19
19
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "Mert Koseoglu",
|
|
4
4
|
"url": "https://github.com/mksglu/context-mode#readme"
|
|
5
5
|
},
|
|
6
|
-
"description": "Context window saver for
|
|
6
|
+
"description": "Context window saver for 11 coding agents. Local and free: sandboxed code execution, FTS5 search, session continuity.",
|
|
7
7
|
"hooks": "./hooks/claude-code.json",
|
|
8
8
|
"mcpServers": {
|
|
9
9
|
"context-mode": {
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"name": "context-mode",
|
|
19
|
-
"version": "2.1
|
|
19
|
+
"version": "2.2.1"
|
|
20
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "Context window saver for
|
|
2
|
+
"description": "Context window saver for 11 coding agents. Local and free: sandboxed code execution, FTS5 search, session continuity.",
|
|
3
3
|
"hooks": "./.codex-plugin/hooks.json",
|
|
4
4
|
"interface": {
|
|
5
5
|
"category": "Productivity",
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
"mcpServers": "./.codex-plugin/mcp.json",
|
|
9
9
|
"name": "context-mode",
|
|
10
10
|
"skills": "./codex/skills/",
|
|
11
|
-
"version": "2.1
|
|
11
|
+
"version": "2.2.1"
|
|
12
12
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "Mert Koseoglu",
|
|
4
4
|
"url": "https://github.com/mksglu/context-mode#readme"
|
|
5
5
|
},
|
|
6
|
-
"description": "Context window saver for
|
|
6
|
+
"description": "Context window saver for 11 coding agents. Local and free: sandboxed code execution, FTS5 search, session continuity.",
|
|
7
7
|
"hooks": "./.zcode-plugin/hooks.json",
|
|
8
8
|
"mcpServers": {
|
|
9
9
|
"context-mode": {
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"name": "context-mode",
|
|
19
|
-
"version": "2.1
|
|
19
|
+
"version": "2.2.1"
|
|
20
20
|
}
|
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Context Mode
|
|
2
2
|
|
|
3
|
-
**A free, local plugin for
|
|
3
|
+
**A free, local plugin for 11 coding agents. It keeps tool output out of your agent's context window and keeps all usage data on your machine. The plugin is free forever.**
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/context-mode) [](https://github.com/mksglu/context-mode) [](https://discord.gg/DCN9jUgN5v) [](https://github.com/mksglu/context-mode/blob/v2.1
|
|
5
|
+
[](https://www.npmjs.com/package/context-mode) [](https://github.com/mksglu/context-mode) [](https://discord.gg/DCN9jUgN5v) [](https://github.com/mksglu/context-mode/blob/v2.2.1/LICENSE)
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**34K GitHub stars · 846K npm downloads** (read 2026-11-17, [stats.json](https://github.com/mksglu/context-mode/blob/v2.2.1/stats.json)) · on the Hacker News front page and GitHub Trending: [charts and sources](#adoption-stars-and-npm-downloads)
|
|
8
8
|
|
|
9
9
|
> The Context Mode plugin is free and local, with its source open on GitHub. **Context Mode Gateway** is a separate hosted service with its own account and subscription. It takes the same idea from tool output to the whole conversation: Gateway Recall keeps long sessions searchable, and Gateway Memory shares what your agents learn across sessions and tools. [See how the Gateway works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=quote)
|
|
10
10
|
|
|
11
11
|
<picture>
|
|
12
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
13
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
12
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/hero-dark.png">
|
|
13
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/hero-light.png" alt="Context Mode plugin: free and local, zero telemetry, the plugin keeps your data on your machine. Bench of 2026-11-01: 99.4% of output bytes saved (median of 36 rows with 10 KB or more of raw output). A full debugging session (row g-session-total): 281,261 B raw to 3,266 B in context, about 70K to 817 tokens (an estimate at 4 B per token). Resume after compaction (row e-long-session): a 442,893 B transcript to a 2,019 B block, about 111K to 505 tokens (an estimate). Runs in 10 coding agents with 9 MCP tools.">
|
|
14
14
|
</picture>
|
|
15
15
|
|
|
16
16
|
**Contents:** [Why](#why) · [Adoption](#adoption-stars-and-npm-downloads) · [Install](#install) · [Try it](#try-it) · [Use cases](#use-cases) · [Benchmarks](#benchmarks) · [How it works](#how-it-works) · [Tools](#tools) · [Security and privacy](#security-and-privacy) · [Context Mode Gateway](#context-mode-gateway) · [License](#license) · [Community](#community)
|
|
@@ -25,14 +25,14 @@ The Context Mode plugin runs that work in a local sandbox, keeps the full output
|
|
|
25
25
|
- **The plugin keeps your data on your machine.** Every index lives in `~/.context-mode`: one `context.db` per project.
|
|
26
26
|
- **Zero telemetry.** The plugin keeps all usage data on your machine. [Security and privacy](#security-and-privacy) lists each network call it makes.
|
|
27
27
|
- **Works offline after install.** Sandbox runs, file indexing and search use local SQLite and your own runtimes.
|
|
28
|
-
- **
|
|
28
|
+
- **Code Mode.** The agent writes a short script instead of reading the data, and only what the script prints reaches the context: see [How it works, step 5](#code-mode).
|
|
29
29
|
- **Small replies.** On the 36 bench rows with 10 KB or more of raw output, the plugin's median reply is 99.4% smaller than the raw output.
|
|
30
30
|
|
|
31
31
|
## Adoption: stars and npm downloads
|
|
32
32
|
|
|
33
33
|
<table><tr>
|
|
34
|
-
<td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#stars"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
35
|
-
<td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#daily"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
34
|
+
<td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#stars"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/star-history-dark.png"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/star-history-light.png" alt="Line chart of cumulative GitHub stars for mksglu/context-mode since 2026-02-23. A daily job redraws it."></picture></a></td>
|
|
35
|
+
<td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#daily"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/npm-downloads-dark.png"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/npm-downloads-light.png" alt="Area chart of npm downloads per day for context-mode, the last 90 days. A daily job redraws it."></picture></a></td>
|
|
36
36
|
</tr></table>
|
|
37
37
|
|
|
38
38
|
Open the [interactive chart](https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#daily) and point at a bar to read its value. Tabs there show days, weeks, months and years. Stars come from the GitHub GraphQL API (`starredAt`); npm downloads come from `api.npmjs.org/downloads/range`. The total up to 2026-10-29 is 683K npm downloads (`stats.json` keeps a daily copy). A daily job redraws both charts.
|
|
@@ -41,19 +41,19 @@ Open the [interactive chart](https://contextmode.ai/open-source/stats?utm_source
|
|
|
41
41
|
- **GitHub Trending.** A bot that watches GitHub Trending logged the repo there on 14 days from 2026-04-24 to 2026-10-17 ([uibm/trending-watcher](https://github.com/uibm/trending-watcher/issues?q=%22mksglu%2Fcontext-mode%22)).
|
|
42
42
|
|
|
43
43
|
<picture>
|
|
44
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
45
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
44
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/stargazers-dark.png">
|
|
45
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/stargazers-light.png" alt="Companies that stargazers of mksglu/context-mode name in their GitHub profile, Microsoft, Tencent, Alibaba, ByteDance, Google and more.">
|
|
46
46
|
</picture>
|
|
47
47
|
|
|
48
|
-
Starred by engineers at these companies: each name is the company field of 2 or more stargazer profiles, read with the GitHub GraphQL API on 2026-11-01 ([data](https://github.com/mksglu/context-mode/blob/v2.1
|
|
48
|
+
Starred by engineers at these companies: each name is the company field of 2 or more stargazer profiles, read with the GitHub GraphQL API on 2026-11-01 ([data](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/data/stargazer-companies.json)).
|
|
49
49
|
|
|
50
50
|
## Install
|
|
51
51
|
|
|
52
|
-
Pick your agent: [Claude Code](#install-claude-code) · [Codex](#install-codex) · [Gemini CLI](#install-gemini) · [Qwen Code](#install-qwen) · [Pi](#install-pi) · [OpenCode](#install-opencode) · [Copilot CLI](#install-copilot-cli) · [Kiro](#install-kiro) · [VS Code](#install-vscode) · [ZCode](#install-zcode)
|
|
52
|
+
Pick your agent: [Claude Code](#install-claude-code) · [Codex](#install-codex) · [Gemini CLI](#install-gemini) · [Qwen Code](#install-qwen) · [Pi](#install-pi) · [OMP](#install-omp) · [OpenCode](#install-opencode) · [Copilot CLI](#install-copilot-cli) · [Kiro](#install-kiro) · [VS Code](#install-vscode) · [ZCode](#install-zcode)
|
|
53
53
|
|
|
54
54
|
Open its block and copy its own install command. Each block also holds the update, check and remove steps, and the [Install guide](https://contextmode.ai/docs/engine/install?utm_source=github&utm_medium=readme&utm_content=install) walks through them.
|
|
55
55
|
|
|
56
|
-
The plugin needs Node 24.15.0 or later, from the engines field in [package.json](https://github.com/mksglu/context-mode/blob/v2.1
|
|
56
|
+
The plugin needs Node 24.15.0 or later, from the engines field in [package.json](https://github.com/mksglu/context-mode/blob/v2.2.1/package.json). On Windows, add Git for Windows: the shell tools run in Git Bash, and doctor checks for it.
|
|
57
57
|
contextmode installs as the npm package and command `context-mode`.
|
|
58
58
|
Claude Code, Codex, Gemini CLI and Qwen Code install from GitHub, and each of their commands names the release branch.
|
|
59
59
|
|
|
@@ -151,6 +151,24 @@ pi remove npm:context-mode
|
|
|
151
151
|
|
|
152
152
|
Hooks ✓ (the plugin's own event handlers) · MCP ✓ (ctx tools built into the plugin) · Skills ✓
|
|
153
153
|
|
|
154
|
+
</details>
|
|
155
|
+
<details id="install-omp"><summary><b>OMP</b></summary>
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
omp plugin install context-mode
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
# update
|
|
163
|
+
omp plugin upgrade context-mode
|
|
164
|
+
# check
|
|
165
|
+
omp plugin list
|
|
166
|
+
# remove
|
|
167
|
+
omp plugin uninstall context-mode
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Hooks ✓ (the plugin's own event handlers) · MCP ✓ (ctx tools built into the plugin) · Skills ✓
|
|
171
|
+
|
|
154
172
|
</details>
|
|
155
173
|
<details id="install-opencode"><summary><b>OpenCode</b></summary>
|
|
156
174
|
|
|
@@ -268,11 +286,11 @@ Restart the agent, then run `/ctx-doctor` in it. Each check prints PASS or a fix
|
|
|
268
286
|
<details><summary><b>How we tested the install</b></summary>
|
|
269
287
|
|
|
270
288
|
Every agent gets hooks, the MCP server and the plugin skills; the last line of each block above says how.
|
|
271
|
-
Hooks reach each agent in one of three ways: in the plugin package (Claude Code, Gemini CLI, Qwen Code), in a hook file (Codex, Copilot CLI, Kiro, VS Code, ZCode), or in a plugin inside the agent (OpenCode, Pi). The [Agents guide](https://contextmode.ai/docs/engine/agents?utm_source=github&utm_medium=readme&utm_content=install-agents) shows what each agent runs.
|
|
272
|
-
We ran the real binary of each agent with the plugin hook: Claude Code, Codex, Gemini CLI, Qwen Code, Pi, OpenCode, Copilot CLI and ZCode. Each run used a clean temp home and a local test model, on 2.0.0-next.15.
|
|
289
|
+
Hooks reach each agent in one of three ways: in the plugin package (Claude Code, Gemini CLI, Qwen Code), in a hook file (Codex, Copilot CLI, Kiro, VS Code, ZCode), or in a plugin inside the agent (OpenCode, Pi, OMP). The [Agents guide](https://contextmode.ai/docs/engine/agents?utm_source=github&utm_medium=readme&utm_content=install-agents) shows what each agent runs.
|
|
290
|
+
We ran the real binary of each agent with the plugin hook: Claude Code, Codex, Gemini CLI, Qwen Code, Pi, OpenCode, Copilot CLI and ZCode. Each run used a clean temp home and a local test model, on 2.0.0-next.15. OMP 18.20.0 ran the same way with ADR-0026, and CI installs the real OMP on Linux, macOS and Windows.
|
|
273
291
|
For VS Code and Kiro, the check covers the hook setup: VS Code runs the hook command with the documented payload, and kiro-cli 2.35.2 loads all 6 hook entries.
|
|
274
|
-
CI runs setup, doctor, a hook and an MCP handshake for all
|
|
275
|
-
Each agent uses its own install command, and [ADR-0023](https://github.com/mksglu/context-mode/blob/v2.1
|
|
292
|
+
CI runs setup, doctor, a hook and an MCP handshake for all 11 agents from the packed package on Linux, macOS and Windows. Record: [HOOKS-FIRE.md](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/architecture/release/HOOKS-FIRE.md).
|
|
293
|
+
Each agent uses its own install command, and [ADR-0023](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/architecture/adr/ADR-0023-native-install.md) says why.
|
|
276
294
|
|
|
277
295
|
</details>
|
|
278
296
|
|
|
@@ -280,7 +298,7 @@ Your first task with the plugin, step by step: [First session](https://contextmo
|
|
|
280
298
|
|
|
281
299
|
## Try it
|
|
282
300
|
|
|
283
|
-
Paste one of these prompts into your agent after the install. Each one ran once, live, in Claude Code 2.1.312, and its answer matched the source data ([evidence and rerun steps](https://github.com/mksglu/context-mode/blob/v2.1
|
|
301
|
+
Paste one of these prompts into your agent after the install. Each one ran once, live, in Claude Code 2.1.312, and its answer matched the source data ([evidence and rerun steps](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/evidence/try-it-2026-11-02/README.md)). The headline numbers in [Benchmarks](#benchmarks) use the median of 5 runs. Other agents do the same job with the same tools: `ctx_execute`, `ctx_index` and `ctx_search`.
|
|
284
302
|
After a prompt, run the stats skill and read the report yourself ([See the saving](#see-the-saving)).
|
|
285
303
|
```text
|
|
286
304
|
On https://react.dev/reference/react/useEffect, show me the example that connects to a chat server and cleans up, and list the rules for the dependency array.
|
|
@@ -310,6 +328,7 @@ Run the stats skill right after a prompt. Each agent uses its own command; the s
|
|
|
310
328
|
| Copilot CLI | `/ctx-stats` |
|
|
311
329
|
| Gemini CLI | `Call ctx_stats and show me the report.` |
|
|
312
330
|
| Kiro | `Call ctx_stats and show me the report.` |
|
|
331
|
+
| OMP | `/skill:ctx-stats` |
|
|
313
332
|
| OpenCode | `Call ctx_stats and show me the report.` |
|
|
314
333
|
| Pi | `/skill:ctx-stats` |
|
|
315
334
|
| Qwen Code | `Call ctx_stats and show me the report.` |
|
|
@@ -338,28 +357,28 @@ Real tool output from public projects, run through Context Mode. Bench of 2026-1
|
|
|
338
357
|
|
|
339
358
|
| What you do | Tool | Raw | Reaches the context | Saved |
|
|
340
359
|
|---|---|---:|---:|---:|
|
|
341
|
-
| [Read a browser page](https://github.com/mksglu/context-mode/blob/v2.1
|
|
342
|
-
| [List 40 issues](https://github.com/mksglu/context-mode/blob/v2.1
|
|
343
|
-
| [List 25 pull requests with checks](https://github.com/mksglu/context-mode/blob/v2.1
|
|
344
|
-
| [Look up library docs](https://github.com/mksglu/context-mode/blob/v2.1
|
|
345
|
-
| [Run 1,106 tests](https://github.com/mksglu/context-mode/blob/v2.1
|
|
346
|
-
| [Lint a source folder](https://github.com/mksglu/context-mode/blob/v2.1
|
|
347
|
-
| [Install a workspace](https://github.com/mksglu/context-mode/blob/v2.1
|
|
348
|
-
| [Install packages](https://github.com/mksglu/context-mode/blob/v2.1
|
|
349
|
-
| [Read container logs](https://github.com/mksglu/context-mode/blob/v2.1
|
|
350
|
-
| [Plan 72 resources](https://github.com/mksglu/context-mode/blob/v2.1
|
|
351
|
-
| [Read 300 commits with file stats](https://github.com/mksglu/context-mode/blob/v2.1
|
|
352
|
-
| [Read an 89 KB source file](https://github.com/mksglu/context-mode/blob/v2.1
|
|
353
|
-
| [Fetch a 265 KB docs page](https://github.com/mksglu/context-mode/blob/v2.1
|
|
354
|
-
| [Fetch a 214 KB API reply](https://github.com/mksglu/context-mode/blob/v2.1
|
|
355
|
-
| [Print a 187 KB git log in Bash](https://github.com/mksglu/context-mode/blob/v2.1
|
|
356
|
-
| [Print the same git log through a host tool](https://github.com/mksglu/context-mode/blob/v2.1
|
|
357
|
-
| [Print a 214 KB GitHub API reply through a host tool](https://github.com/mksglu/context-mode/blob/v2.1
|
|
358
|
-
| [Read a 45 KB log file](https://github.com/mksglu/context-mode/blob/v2.1
|
|
359
|
-
| [Read a 60 KB source file](https://github.com/mksglu/context-mode/blob/v2.1
|
|
360
|
-
| [Debug for a full session: 8 outputs, 3 searches](https://github.com/mksglu/context-mode/blob/v2.1
|
|
361
|
-
|
|
362
|
-
Source: [bench/results/2026-11-01-darwin-arm64.json](https://github.com/mksglu/context-mode/blob/v2.1
|
|
360
|
+
| [Read a browser page](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-devtools-mcp-snapshot) | Chrome DevTools MCP `take_snapshot`, [Code Mode](#code-mode) | 136,514 B | 463 B | 99.7% |
|
|
361
|
+
| [List 40 issues](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-gh-issue-list-vite) | GitHub CLI `gh issue list --json`, [Code Mode](#code-mode) | 182,943 B | 850 B | 99.5% |
|
|
362
|
+
| [List 25 pull requests with checks](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-gh-pr-list-vite) | GitHub CLI `gh pr list --json`, [Code Mode](#code-mode) | 195,471 B | 776 B | 99.6% |
|
|
363
|
+
| [Look up library docs](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-context7-query-docs-vite) | Context7 `query-docs`, [Code Mode](#code-mode) | 6,917 B | 473 B | 93.2% |
|
|
364
|
+
| [Run 1,106 tests](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-vitest-run-vite) | Vitest `vitest run --reporter=verbose`, [Code Mode](#code-mode) | 62,909 B | 429 B | 99.3% |
|
|
365
|
+
| [Lint a source folder](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-biome-lint-vite) | Biome `biome lint --reporter=json`, [Code Mode](#code-mode) | 288,523 B | 577 B | 99.8% |
|
|
366
|
+
| [Install a workspace](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-pnpm-install-vite) | pnpm `pnpm install --frozen-lockfile`, [Code Mode](#code-mode) | 14,988 B | 199 B | 98.7% |
|
|
367
|
+
| [Install packages](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-npm-install-log) | npm `npm install --loglevel http`, [Code Mode](#code-mode) | 37,761 B | 435 B | 98.8% |
|
|
368
|
+
| [Read container logs](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-docker-logs-mongo) | Docker `docker logs`, [Code Mode](#code-mode) | 60,374 B | 587 B | 99.0% |
|
|
369
|
+
| [Plan 72 resources](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-terraform-plan) | Terraform `terraform plan`, [Code Mode](#code-mode) | 34,081 B | 166 B | 99.5% |
|
|
370
|
+
| [Read 300 commits with file stats](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/a-sandbox/README.md#a-git-log-stat-vite) | git `git log --stat`, [Code Mode](#code-mode) | 164,385 B | 268 B | 99.8% |
|
|
371
|
+
| [Read an 89 KB source file](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/f-hook-redirect/README.md#f-read-vite-config) | Read, sent to `ctx_execute` by the hook | 91,362 B | 375 B | 99.6% |
|
|
372
|
+
| [Fetch a 265 KB docs page](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/f-hook-redirect/README.md#f-webfetch-vite-docs) | WebFetch, sent to `ctx_index` and `ctx_search` | 271,731 B | 439 B | 99.8% |
|
|
373
|
+
| [Fetch a 214 KB API reply](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/f-hook-redirect/README.md#f-bash-curl-post) | curl in Bash, replaced after it runs | 219,175 B | 291 B | 99.9% |
|
|
374
|
+
| [Print a 187 KB git log in Bash](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/f-hook-redirect/README.md#f-bash-dump-post) | Bash, output replaced after it runs | 191,120 B | 204 B | 99.9% |
|
|
375
|
+
| [Print the same git log through a host tool](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/d-externalize/README.md#d-real-git-log) | Host tool output over the cap, indexed whole | 191,120 B | 2,842 B | 98.5% |
|
|
376
|
+
| [Print a 214 KB GitHub API reply through a host tool](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/d-externalize/README.md#d-real-github-json) | Host tool output over the cap, indexed whole | 219,175 B | 4,060 B | 98.1% |
|
|
377
|
+
| [Read a 45 KB log file](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/f-hook-redirect/README.md#f-read-large-file) | Read, sent to `ctx_execute` by the hook | 46,216 B | 371 B | 99.2% |
|
|
378
|
+
| [Read a 60 KB source file](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/f-hook-redirect/README.md#f-read-big-source) | Read, sent to `ctx_execute` by the hook | 61,576 B | 374 B | 99.4% |
|
|
379
|
+
| [Debug for a full session: 8 outputs, 3 searches](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/g-overhead/README.md#g-session-total) | All hooks and tools | 281,261 B | 3,266 B | 98.8% |
|
|
380
|
+
|
|
381
|
+
Source: [bench/results/2026-11-01-darwin-arm64.json](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/results/2026-11-01-darwin-arm64.json), one row per line; [SOURCE.md](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/fixtures/data/SOURCE.md) names where each input comes from.
|
|
363
382
|
Click a task to open its case: the command, the input file with its sha256, and the run command, so you can run the same row on your machine.
|
|
364
383
|
|
|
365
384
|
The agent gets the part it asks for. The full output stays in the local index, and `ctx_search` reads it back.
|
|
@@ -371,8 +390,8 @@ Next, how the bench counts these bytes, in [Benchmarks](#benchmarks).
|
|
|
371
390
|
## Benchmarks
|
|
372
391
|
|
|
373
392
|
<picture>
|
|
374
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
375
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
393
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/fig-saving-dark.png">
|
|
394
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/fig-saving-light.png" alt="Bar chart: median output bytes saved per category for rows of 10 KB or more. Sandbox 99.5%, Batch 93.1%, Externalize 98.3%, Hook redirect 99.8%, Session total 98.8%. The table below adds Retrieval, 77.2%.">
|
|
376
395
|
</picture>
|
|
377
396
|
|
|
378
397
|
Rule for every headline number in this README: rows with 10 KB or more of raw output, median of 5 runs per row, measured with `ctx_bytes` against `raw_bytes`; a category is the median of its rows; 1 KB = 1,024 B.
|
|
@@ -387,24 +406,24 @@ All 36 such rows, the six categories below: the plugin keeps a median of 99.4% o
|
|
|
387
406
|
| f. Hook redirect | A big Read, curl or WebFetch sent to the sandbox | 7 | 99.8% |
|
|
388
407
|
| g. Session total | One full scripted session | 1 | 98.8% |
|
|
389
408
|
|
|
390
|
-
Search replies (category b) carry the matching text, so they save 77.2%. Category e (long sessions) is in [Longer sessions](#longer-sessions). The full file lists every row, small ones too: [2026-11-01-darwin-arm64.md](https://github.com/mksglu/context-mode/blob/v2.1
|
|
391
|
-
Reproduce with `cd bench && node run.mjs`. It needs plain Node and runs offline; [bench/README.md](https://github.com/mksglu/context-mode/blob/v2.1
|
|
409
|
+
Search replies (category b) carry the matching text, so they save 77.2%. Category e (long sessions) is in [Longer sessions](#longer-sessions). The full file lists every row, small ones too: [2026-11-01-darwin-arm64.md](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/results/2026-11-01-darwin-arm64.md).
|
|
410
|
+
Reproduce with `cd bench && node run.mjs`. It needs plain Node and runs offline; [bench/README.md](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/README.md) lists each scenario and its options.
|
|
392
411
|
Method, data files and rerun steps: [Benchmarks guide](https://contextmode.ai/docs/engine/benchmarks?utm_source=github&utm_medium=readme&utm_content=benchmarks).
|
|
393
412
|
|
|
394
413
|
### Longer sessions
|
|
395
414
|
|
|
396
415
|
<picture>
|
|
397
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
398
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
416
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/fig-oss-dark.png">
|
|
417
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/fig-oss-light.png" alt="A session grows, the context stays small. The PreToolUse hook sends a tool call to ctx_execute or ctx_index; the full output goes into context.db and a small reply returns. At compaction a snapshot keeps the state, and ctx_resume and ctx_search read it back.">
|
|
399
418
|
</picture>
|
|
400
419
|
|
|
401
420
|
Say you debug a slow test all afternoon. The agent reads files, runs the suite and fetches docs, and each result goes into the context window. When the window is full, the host compacts it, and from then on the agent sees a short summary plus your next message.
|
|
402
421
|
|
|
403
422
|
Context Mode keeps the full output of each large tool call in `context.db` on your machine and gives the agent a small reply. At compaction, a snapshot of at most 2,048 B keeps the session state. After the compaction, the agent calls `ctx_resume` to read that snapshot back and `ctx_search` to find any earlier output by keyword.
|
|
404
423
|
|
|
405
|
-
In the bench, a scripted session of 40 tool outputs and one compaction made a 442,893 B transcript, and the `ctx_resume` block that brought the agent back was 2,019 B (row `e-long-session` in the bench file; [open the case](https://github.com/mksglu/context-mode/blob/v2.1
|
|
406
|
-
In the same bench, one large log of 666,796 B put 3,380 B into the context, and the full log stayed in the index for `ctx_search` (row `d-synth-1m`; [open the case](https://github.com/mksglu/context-mode/blob/v2.1
|
|
407
|
-
How the snapshot picks what to keep: the [Long sessions guide](https://contextmode.ai/docs/engine/long-sessions?utm_source=github&utm_medium=readme&utm_content=longer-sessions) and [ADR-0009](https://github.com/mksglu/context-mode/blob/v2.1
|
|
424
|
+
In the bench, a scripted session of 40 tool outputs and one compaction made a 442,893 B transcript, and the `ctx_resume` block that brought the agent back was 2,019 B (row `e-long-session` in the bench file; [open the case](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/e-continuity/README.md#e-long-session)).
|
|
425
|
+
In the same bench, one large log of 666,796 B put 3,380 B into the context, and the full log stayed in the index for `ctx_search` (row `d-synth-1m`; [open the case](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/d-externalize/README.md#d-synth-1m)).
|
|
426
|
+
How the snapshot picks what to keep: the [Long sessions guide](https://contextmode.ai/docs/engine/long-sessions?utm_source=github&utm_medium=readme&utm_content=longer-sessions) and [ADR-0009](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/architecture/adr/0009-compaction-and-memory.md).
|
|
408
427
|
|
|
409
428
|
### Speed
|
|
410
429
|
|
|
@@ -416,27 +435,27 @@ Median of 5 runs, bench of 2026-11-01.
|
|
|
416
435
|
| `ctx_search`, 20 queries over 8 indexed files | 1.62 ms median, 6.70 ms max |
|
|
417
436
|
| `ctx_index`, 3 real files, 625,649 B | 150 ms per MB |
|
|
418
437
|
|
|
419
|
-
Source: rows `g-hook-kiro` to `g-hook-claude-code`, `g-search-latency` and `g-index-per-mb` of [the bench file](https://github.com/mksglu/context-mode/blob/v2.1
|
|
438
|
+
Source: rows `g-hook-kiro` to `g-hook-claude-code`, `g-search-latency` and `g-index-per-mb` of [the bench file](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/results/2026-11-01-darwin-arm64.md), with every agent and query. The [overhead cases](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/g-overhead/README.md) show how each one runs.
|
|
420
439
|
|
|
421
440
|
Next, what happens inside one tool call, in [How it works](#how-it-works).
|
|
422
441
|
|
|
423
442
|
## How it works
|
|
424
443
|
|
|
425
444
|
<picture>
|
|
426
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
427
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.1
|
|
445
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/fig-flow-dark.png">
|
|
446
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/fig-flow-light.png" alt="One tool call, step by step: the agent runs a tool, the PreToolUse hook denies a big Read and names the ctx_execute call, the MCP server runs it in the sandbox, SQLite FTS5 keeps the output, and after compaction a state block of at most 2,048 B comes back.">
|
|
428
447
|
</picture>
|
|
429
448
|
|
|
430
449
|
One tool call, in time order, from the install to a hook error.
|
|
431
450
|
|
|
432
|
-
1. **Install.** Each agent's own install command adds the MCP server, the hooks and the skills `ctx-doctor`, `ctx-stats` and `ctx-upgrade` to that agent's config folder, for example `~/.codex/skills/<name>/SKILL.md`. `context-mode setup` writes or repairs any part the native command leaves out ([ADR-0023](https://github.com/mksglu/context-mode/blob/v2.1
|
|
433
|
-
2. **Session start.** The `SessionStart` hook opens the project database. When the session ran before, the agent gets one line that tells it to call `ctx_resume` ([dispatch.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
434
|
-
3. **PreToolUse checks.** Before a tool runs, the `PreToolUse` hook checks the call in a fixed order: the user's deny list, WebFetch, curl and wget, inline HTTP and build commands, then a full-file Read over `OUTPUT_CAP` (16,384 B) and one-file shell dumps such as `cat` or `tail`. A Read with a line range runs as usual ([decide.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
435
|
-
4. **The exact call.** When a check matches, the hook stops the call and its reply names the exact `ctx_*` call to use, for example `ctx_execute` with `{"language":"shell","code":"<the command>","intent":"<what you need>"}`. For WebFetch the reply names `ctx_index`, then `ctx_search` ([read-deny.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
436
|
-
5. **The sandbox.** This is the
|
|
437
|
-
<a id="
|
|
451
|
+
1. **Install.** Each agent's own install command adds the MCP server, the hooks and the skills `ctx-doctor`, `ctx-stats` and `ctx-upgrade` to that agent's config folder, for example `~/.codex/skills/<name>/SKILL.md`. `context-mode setup` writes or repairs any part the native command leaves out ([ADR-0023](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/architecture/adr/ADR-0023-native-install.md)).
|
|
452
|
+
2. **Session start.** The `SessionStart` hook opens the project database. When the session ran before, the agent gets one line that tells it to call `ctx_resume` ([dispatch.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/hooks/dispatch.ts)).
|
|
453
|
+
3. **PreToolUse checks.** Before a tool runs, the `PreToolUse` hook checks the call in a fixed order: the user's deny list, WebFetch, curl and wget, inline HTTP and build commands, then a full-file Read over `OUTPUT_CAP` (16,384 B) and one-file shell dumps such as `cat` or `tail`. A Read with a line range runs as usual ([decide.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/policy/decide.ts)).
|
|
454
|
+
4. **The exact call.** When a check matches, the hook stops the call and its reply names the exact `ctx_*` call to use, for example `ctx_execute` with `{"language":"shell","code":"<the command>","intent":"<what you need>"}`. For WebFetch the reply names `ctx_index`, then `ctx_search` ([read-deny.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/policy/read-deny.ts)).
|
|
455
|
+
5. **The sandbox.** This is the Code Mode step: the agent's script runs here, and only what it prints comes back. `ctx_execute` writes the script to a temp folder and spawns the runtime from an argument list in the project folder. The timeout is `EXEC_TIMEOUT_MS` (600,000 ms, default and maximum); on timeout it stops the whole process group (`taskkill /F /T` on Windows). The child gets your environment minus preload variables such as `NODE_OPTIONS`, and the agent gets what the script prints, at most `OUTPUT_CAP` ([execute.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/tools/execute.ts)).
|
|
456
|
+
<a id="code-mode"></a>**Code Mode.** The agent sends a short script as a tool parameter, the script reads the data in the sandbox, and only what it prints goes into the context. Two real calls, in the form the Claude Code terminal shows them:
|
|
438
457
|
|
|
439
|
-
`ctx_execute` on 5,000 JSON records, from the Claude Code 2.1.312 stream of the Try-it run with Context Mode 2.0.0-next.26 ([04-api-json.json](https://github.com/mksglu/context-mode/blob/v2.1
|
|
458
|
+
`ctx_execute` on 5,000 JSON records, from the Claude Code 2.1.312 stream of the Try-it run with Context Mode 2.0.0-next.26 ([04-api-json.json](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/evidence/try-it-2026-11-02/04-api-json.json)). The data is 1,039,898 B; the agent gets 254 B.
|
|
440
459
|
|
|
441
460
|
```text
|
|
442
461
|
⏺ context-mode - ctx_execute (MCP)(language: "javascript", c…jsonplaceholder.typicode.com/photos\");
|
|
@@ -464,7 +483,7 @@ One tool call, in time order, from the install to a hook error.
|
|
|
464
483
|
}
|
|
465
484
|
```
|
|
466
485
|
|
|
467
|
-
`ctx_batch` on an install log and a long git log, one live MCP call to `release-out/server.mjs` of Context Mode 2.0.0-next.36 on 2026-11-03 ([2026-11-03-ctx-batch.json](https://github.com/mksglu/context-mode/blob/v2.1
|
|
486
|
+
`ctx_batch` on an install log and a long git log, one live MCP call to `release-out/server.mjs` of Context Mode 2.0.0-next.36 on 2026-11-03 ([2026-11-03-ctx-batch.json](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/evidence/code-mode/2026-11-03-ctx-batch.json)). The commands print 228,881 B; the agent gets 8,667 B, the parts that match its two queries, and the full output stays in the index.
|
|
468
487
|
|
|
469
488
|
```text
|
|
470
489
|
⏺ context-mode - ctx_batch (MCP)(commands: ["cat npm-install… queries: ["cache miss","feat commit"])
|
|
@@ -476,15 +495,15 @@ One tool call, in time order, from the install to a hook error.
|
|
|
476
495
|
npm http fetch GET 200 https://registry.npmjs.org/@esbuild%2fdarwin-arm64 99ms (cache miss)
|
|
477
496
|
… +95 lines (ctrl+o to expand)
|
|
478
497
|
```
|
|
479
|
-
6. **Indexing.** The full output goes into the index in chunks of at most `MAX_CHUNK_BYTES` (4,096 B). A Markdown chunk stays inside one heading section, and a code block that fits stays whole. Each chunk goes into two SQLite FTS5 tables: a Porter-stemmed table for words and a trigram table for paths, names and parts of words ([fts.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
498
|
+
6. **Indexing.** The full output goes into the index in chunks of at most `MAX_CHUNK_BYTES` (4,096 B). A Markdown chunk stays inside one heading section, and a code block that fits stays whole. Each chunk goes into two SQLite FTS5 tables: a Porter-stemmed table for words and a trigram table for paths, names and parts of words ([fts.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/store/fts.ts)).
|
|
480
499
|
|
|
481
|
-
`ctx_index` on a copy of this repo's `docs/how-it-works.md`, one live MCP call to `release-out/server.mjs` of Context Mode 2.0.0-next.36 on 2026-11-03 ([calls.json](https://github.com/mksglu/context-mode/blob/v2.1
|
|
500
|
+
`ctx_index` on a copy of this repo's `docs/how-it-works.md`, one live MCP call to `release-out/server.mjs` of Context Mode 2.0.0-next.36 on 2026-11-03 ([calls.json](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/evidence/terminal-calls-2026-11-03/calls.json)). The file is 11,577 B; the agent gets 64 B.
|
|
482
501
|
|
|
483
502
|
```text
|
|
484
503
|
⏺ context-mode - ctx_index (MCP)(path: "how-it-works.md")
|
|
485
504
|
⎿ Indexed 1 source(s), 17 chunk(s) from s1. Label: how-it-works.md
|
|
486
505
|
```
|
|
487
|
-
7. **Search.** `ctx_search` ranks each table with BM25 and joins the two lists with Reciprocal Rank Fusion: a hit scores 1/(`RRF_K` + rank), with `RRF_K` = 60. Before it returns an empty list, it tries a spelling fix from the indexed words. Search covers this session, this worktree (the default) or the whole project, and each snippet is at most `SNIPPET_MAX_BYTES` (800 B) ([search.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
506
|
+
7. **Search.** `ctx_search` ranks each table with BM25 and joins the two lists with Reciprocal Rank Fusion: a hit scores 1/(`RRF_K` + rank), with `RRF_K` = 60. Before it returns an empty list, it tries a spelling fix from the indexed words. Search covers this session, this worktree (the default) or the whole project, and each snippet is at most `SNIPPET_MAX_BYTES` (800 B) ([search.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/tools/search.ts)).
|
|
488
507
|
|
|
489
508
|
`ctx_search` on that index, in the same run, in a project that also holds an `AGENTS.md`. One search reads the index and every agent's memory files. The agent gets 1,268 B: one content hit and one memory hit, each with its source and heading. For memory shared across machines, agents and sessions, see [Context Mode Gateway Memory](https://contextmode.ai/docs/memory?utm_source=github&utm_medium=readme&utm_content=search-memory).
|
|
490
509
|
|
|
@@ -497,8 +516,8 @@ One tool call, in time order, from the install to a hook error.
|
|
|
497
516
|
memory AGENTS.md #0: # Agent rules
|
|
498
517
|
… +10 lines (ctrl+o to expand)
|
|
499
518
|
```
|
|
500
|
-
8. **Run, then replace.** On hosts that run the tool first, the `PostToolUse` hook checks the result. Output over `REPLACE_TRIGGER_BYTES` (4,096 B) goes into the index whole, and the agent gets the best-matching chunks and one `ctx_search` line for the rest ([dispatch.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
501
|
-
9. **Journal and compaction.** The hooks log each prompt, edit, command, tool error and decision in a journal. After a compaction the agent gets a state block of at most `STATE_BUDGET` (2,048 B), and each long line becomes a `ctx_resume(seq)` pointer to the full row; one `ctx_resume` reply is at most `RESUME_CAP` (2,048 B). On the next prompt, a prompt-match block brings back the journal rows that match it by BM25 ([ADR-0009](https://github.com/mksglu/context-mode/blob/v2.1
|
|
519
|
+
8. **Run, then replace.** On hosts that run the tool first, the `PostToolUse` hook checks the result. Output over `REPLACE_TRIGGER_BYTES` (4,096 B) goes into the index whole, and the agent gets the best-matching chunks and one `ctx_search` line for the rest ([dispatch.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/hooks/dispatch.ts)).
|
|
520
|
+
9. **Journal and compaction.** The hooks log each prompt, edit, command, tool error and decision in a journal. After a compaction the agent gets a state block of at most `STATE_BUDGET` (2,048 B), and each long line becomes a `ctx_resume(seq)` pointer to the full row; one `ctx_resume` reply is at most `RESUME_CAP` (2,048 B). On the next prompt, a prompt-match block brings back the journal rows that match it by BM25 ([ADR-0009](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/architecture/adr/0009-compaction-and-memory.md)).
|
|
502
521
|
|
|
503
522
|
`ctx_resume` with empty parameters returns the state block, in the same run: 209 B.
|
|
504
523
|
|
|
@@ -510,10 +529,10 @@ One tool call, in time order, from the install to a hook error.
|
|
|
510
529
|
more: ctx_search(queries:[], scope:"session")
|
|
511
530
|
</context_mode_state>
|
|
512
531
|
```
|
|
513
|
-
10. **The database.** Each project has one `context.db` under `~/.context-mode`, in Node's built-in `node:sqlite`. The database runs in WAL mode and runs a PASSIVE checkpoint on close. A new database gets built under a temp name and moves into place in one atomic step, and the busy timeout is `DB_TIMEOUT_MS` (5,000 ms) ([db.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
514
|
-
11. **A hook error.** A hook always ends with exit 0. On any error it gives the host's allow reply and writes one log line to `~/.context-mode/hook-errors.log`, so your agent keeps working. A spawned hook has `HOOK_TIMEOUT_MS` (5,000 ms) ([fallback.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
532
|
+
10. **The database.** Each project has one `context.db` under `~/.context-mode`, in Node's built-in `node:sqlite`. The database runs in WAL mode and runs a PASSIVE checkpoint on close. A new database gets built under a temp name and moves into place in one atomic step, and the busy timeout is `DB_TIMEOUT_MS` (5,000 ms) ([db.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/store/db.ts)).
|
|
533
|
+
11. **A hook error.** A hook always ends with exit 0. On any error it gives the host's allow reply and writes one log line to `~/.context-mode/hook-errors.log`, so your agent keeps working. A spawned hook has `HOOK_TIMEOUT_MS` (5,000 ms) ([fallback.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/hooks/fallback.ts)).
|
|
515
534
|
|
|
516
|
-
Every number with its reason: [How it works](https://github.com/mksglu/context-mode/blob/v2.1
|
|
535
|
+
Every number with its reason: [How it works](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/how-it-works.md). The rules the hook follows: [ADR-0008](https://github.com/mksglu/context-mode/blob/v2.2.1/docs/architecture/adr/0008-enforcement-rewrite-and-cap.md). Next, the [Tools](#tools) the agent calls.
|
|
517
536
|
|
|
518
537
|
## Tools
|
|
519
538
|
|
|
@@ -529,7 +548,7 @@ Every number with its reason: [How it works](https://github.com/mksglu/context-m
|
|
|
529
548
|
| `ctx_upgrade` | Installs, upgrades or uninstalls; replaces old contextmode entries |
|
|
530
549
|
| `ctx_purge` | Deletes indexed data by session, source or project |
|
|
531
550
|
|
|
532
|
-
Three more real calls, from the same live run of Context Mode 2.0.0-next.36 on 2026-11-03 ([calls.json](https://github.com/mksglu/context-mode/blob/v2.1
|
|
551
|
+
Three more real calls, from the same live run of Context Mode 2.0.0-next.36 on 2026-11-03 ([calls.json](https://github.com/mksglu/context-mode/blob/v2.2.1/bench/evidence/terminal-calls-2026-11-03/calls.json)).
|
|
533
552
|
|
|
534
553
|
`ctx_stats`: the agent gets 3,097 B, the first line is the summary.
|
|
535
554
|
|
|
@@ -570,12 +589,12 @@ Commands in the agent: `/ctx-stats` shows the `ctx_stats` result, `/ctx-doctor`
|
|
|
570
589
|
|
|
571
590
|
| Call | When | File |
|
|
572
591
|
|---|---|---|
|
|
573
|
-
| Fetch of a URL, for `ctx_index` | Your agent asks for a page. The fetch blocks private and link-local addresses, checks each address the host name points to, connects to the address it checked, and checks again at each redirect. | [fetch.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
574
|
-
| One read of the npm dist-tags, with `git ls-remote` of the release tags as the fallback | You run `context-mode doctor`, to check for a new version | [doctor-env.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
575
|
-
| `npm i -g context-mode`, or `gh issue create` | You run `context-mode upgrade`, or you press a key to send the debug report | [commands.ts](https://github.com/mksglu/context-mode/blob/v2.1
|
|
592
|
+
| Fetch of a URL, for `ctx_index` | Your agent asks for a page. The fetch blocks private and link-local addresses, checks each address the host name points to, connects to the address it checked, and checks again at each redirect. | [fetch.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/sandbox/fetch.ts) |
|
|
593
|
+
| One read of the npm dist-tags, with `git ls-remote` of the release tags as the fallback | You run `context-mode doctor`, to check for a new version | [doctor-env.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/core/ops/doctor-env.ts) |
|
|
594
|
+
| `npm i -g context-mode`, or `gh issue create` | You run `context-mode upgrade`, or you press a key to send the debug report | [commands.ts](https://github.com/mksglu/context-mode/blob/v2.2.1/src/cli/commands.ts) |
|
|
576
595
|
| Your agent's own install command, npm or git | You install or update | Your agent |
|
|
577
596
|
|
|
578
|
-
- The guard test D-PRIVACY-NET-1 in [tests/0008-enforcement.test.mjs](https://github.com/mksglu/context-mode/blob/v2.1
|
|
597
|
+
- The guard test D-PRIVACY-NET-1 in [tests/0008-enforcement.test.mjs](https://github.com/mksglu/context-mode/blob/v2.2.1/tests/0008-enforcement.test.mjs) scans the source for HTTP clients, sockets, DNS lookups, git network calls and gh or npm spawns. It flags each new call site, so this table stays true.
|
|
579
598
|
- Doctor and the debug report remove secrets by their structure before they print.
|
|
580
599
|
|
|
581
600
|
Code from `ctx_execute` runs on your host as your user, with your files, your network and your environment except the preload variables, so keep your agent's own permission prompts on. Here "sandbox" means the output stays in the sandbox and out of the context.
|
|
@@ -602,16 +621,16 @@ npx @context-mode/cli
|
|
|
602
621
|
`npx @context-mode/cli` signs you in to your Gateway account, which has its own subscription, and writes one config change per agent.
|
|
603
622
|
Apps: Claude Code, Claude Desktop, Codex, Codex Desktop, T3 Code, OpenCode and Pi. The Gateway CLI needs Node 20.12 or later, from its npm engines field.
|
|
604
623
|
|
|
605
|
-
<a href="https://github.com/mksglu/context-mode/blob/v2.1
|
|
624
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/live.mp4"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/live.webp" width="100%" alt="Gateway Live screen during a session: money saved, bytes kept out per request, history kept and sent, and a feed of each request with its cost and saving"></a>
|
|
606
625
|
|
|
607
626
|
**Live.** One session as it runs: money saved this session, bytes kept out per request, history kept and sent, and a feed of each request with its cost and saving. Click the image for the full video.
|
|
608
627
|
|
|
609
628
|
Docs: [How saving works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=live)
|
|
610
629
|
|
|
611
630
|
<table>
|
|
612
|
-
<tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.1
|
|
613
|
-
<tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.1
|
|
614
|
-
<tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.1
|
|
631
|
+
<tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/overview.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/overview-1200.webp" alt="Gateway Overview: money saved, AI spend, prompt-cache discount and cost per request over 30 days"></a><br><b>Overview.</b> Your spend and what the Gateway saved, per day, in one view.<br>Docs: <a href="https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=overview">How saving works</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/analytics.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/analytics-1200.webp" alt="Gateway Analytics: saved money over time, split by source"></a><br><b>Analytics.</b> Where each saving comes from: hidden tools, archived old results, large outputs kept in the archive and trimmed context.<br>Docs: <a href="https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=analytics">How saving works</a></td></tr>
|
|
632
|
+
<tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/spend.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/spend-1200.webp" alt="Gateway Spend: spend per day by model, cost per request and cache hit rate"></a><br><b>Spend.</b> Spend per day and per model, cost per request and the cache hit rate, to help you plan a budget.<br>Docs: <a href="https://contextmode.ai/docs/prompt-caching?utm_source=github&utm_medium=readme&utm_content=spend">Prompt caching</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/memory.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/memory-top-1200.webp" alt="Gateway Memory: money saved by Recall and searches per day"></a><br><b>Memory.</b> Facts and decisions carry across sessions and agents. The screen shows what Recall saved and how many searches found an answer.<br>Docs: <a href="https://contextmode.ai/docs/memory?utm_source=github&utm_medium=readme&utm_content=memory">Memory</a></td></tr>
|
|
633
|
+
<tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/skills.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/skills-1200.webp" alt="Gateway Skills: import from GitHub and the list of installed skills"></a><br><b>Skills.</b> Add a skill once and all your clients use it when it helps. Import skills from GitHub and see the installed ones.<br>Docs: <a href="https://contextmode.ai/docs/skills?utm_source=github&utm_medium=readme&utm_content=skills">Skills</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.2.1/docs/assets/readme/gateway/protect.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.2.1/docs/assets/readme/gateway/protect-1200.webp" alt="Gateway Protect: a new command rule that blocks terraform destroy"></a><br><b>Protect.</b> Rules that check each shell command before it runs. Here, a rule that stops <code>terraform destroy</code>.<br>Docs: <a href="https://contextmode.ai/docs/protect?utm_source=github&utm_medium=readme&utm_content=protect">Protect</a></td></tr>
|
|
615
634
|
</table>
|
|
616
635
|
|
|
617
636
|
Numbers in these screens come from the author's own account over 30 days (Oct 3 - Nov 1, 2026), so read them as one account's usage. Click an image for the full size.
|
|
@@ -637,7 +656,7 @@ Source: [contextmode.ai/docs](https://contextmode.ai/docs/how-saving-works?utm_s
|
|
|
637
656
|
|
|
638
657
|
| Feature | What it does | What you get | Details |
|
|
639
658
|
|---|---|---|---|
|
|
640
|
-
| Context Saving | Folds old tool output, runs data work as code (
|
|
659
|
+
| Context Saving | Folds old tool output, runs data work as code (Code Mode), trims tool schemas, places cache marks | A tool output over 2,048 B becomes a short pointer, with the full copy archived | Saves the most on sessions with many tool calls |
|
|
641
660
|
| Recall | The model sees recent work and an index of older work; the agent searches the archive for the rest | Gateway, Claude Code, Opus 5.5, 200K window, 2026-10-04: mean cost per session $4.8627 to $3.0353 (-37.6% in dollars, `ab.json` below) | Cost measured in Claude Code on Claude Opus 5.5 |
|
|
642
661
|
| Memory | Each fact keeps two times: when it was true and when the Gateway learned it | Claude Code and Codex on one account share one store, tested end to end | The memory block goes into the first request of a new session |
|
|
643
662
|
| Skills | A skill catalog on the Gateway for your account; it loads the skill that matches your message | The matching skill loads on the message that needs it | Import skills from GitHub; a loaded skill joins the prompt in full |
|
|
@@ -673,6 +692,6 @@ We chose ELv2 so the source stays open to all and the hosted service stays with
|
|
|
673
692
|
|
|
674
693
|
## Community
|
|
675
694
|
|
|
676
|
-
Report a defect on [Discord](https://discord.gg/DCN9jUgN5v) with the full `/ctx-doctor` report, and send ideas there too. The maintainer writes every change; [CONTRIBUTING.md](https://github.com/mksglu/context-mode/blob/v2.1
|
|
695
|
+
Report a defect on [Discord](https://discord.gg/DCN9jUgN5v) with the full `/ctx-doctor` report, and send ideas there too. The maintainer writes every change; [CONTRIBUTING.md](https://github.com/mksglu/context-mode/blob/v2.2.1/CONTRIBUTING.md) shows how an agent files an issue.
|
|
677
696
|
|
|
678
697
|
**Videos.** [Better Stack on Context Mode](https://www.youtube.com/watch?v=QUHrntlfPo4). Make your own video and share it on [Discord](https://discord.gg/DCN9jUgN5v); we add videos over 10K views here.
|
package/SHA256SUMS
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
6b8741f2aa084d3787022378ff1d1349d0f7fe6461c643113dca498a6b1ef638 .claude-plugin/marketplace.json
|
|
2
|
+
e87b75644b95af114f3a7c187f96b539a2dcc772214c52ca6e1098be0e07185d .claude-plugin/plugin.json
|
|
3
3
|
187503e1455560d4ab5a72e3b8cd2f274abd4ccc5faa60dd66c37e44bb5f10c2 .codex-plugin/hooks.json
|
|
4
4
|
4edea851775bc3f0418f8d9cf6ead74f2767c3a9e3b8c05749eacb78ebb3b896 .codex-plugin/mcp.json
|
|
5
|
-
|
|
5
|
+
25f1923c8159fb30d539eb710166029cf00667d362e909222d9e234628fc1493 .codex-plugin/plugin.json
|
|
6
6
|
c43e4955e50a2b3d50b6ba4009fed79a530cdffc9874653b68d840af8c9d098e .zcode-plugin/hooks.json
|
|
7
|
-
|
|
7
|
+
7fbef9c7ee9ba392a7b8e2d329193b2c41f83ccc1bdec151bc1287011a93906b .zcode-plugin/plugin.json
|
|
8
8
|
92f11a867c41c9e575ccb978ff205ae2011c244a14aa3c576e914e537105caa0 LICENSE
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
6de05d3b06de480efa2a853ea9b415631ab5df64e7fe218c0aec697b6238a6f9 README.md
|
|
10
|
+
ccd31a1f44eb1ecd583ee4cb47757d9ca22432ef22af829738801ddbf0957409 cli.mjs
|
|
11
11
|
83c297020ed0c592fc68c9c482546a6999d41df5d06d8a329498f10edb1bd38e codex/skills/ctx-doctor/SKILL.md
|
|
12
12
|
5652e791d5fa00033aebb0f6f85b6a3c9db8ab45cfc402e74ffc5f87bdc08922 codex/skills/ctx-stats/SKILL.md
|
|
13
13
|
5c12cdd19a5e3ed7d9ba3a47b24d03864a28d36cf7006876284ee07cd4221ec4 codex/skills/ctx-upgrade/SKILL.md
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
2e643f534107cc2fdd3d49f771e0d714434fb194f4a896f25a07ad45d9c77319 copilot/plugin.json
|
|
15
|
+
5eeb472d843abe5663be73c5fbd855b64e9d6480383b97e290e81156e6537735 fixtures/hook-roundtrip.json
|
|
16
|
+
5ca21c49bbefd23ce6284608144afc9faf90180452ebe88b698ff7b2c5155c89 gemini-extension.json
|
|
17
|
+
50e3c48ed339bf7db7df056e3d76dd680887f16cbdf3f64c76420643faa7fd88 hook.mjs
|
|
18
18
|
676dd9cddc3bb4dbf163296cdd72aac521010fdf33ab80bd2641f647ae475dc1 hooks/claude-code.json
|
|
19
19
|
2524a0eb52683b65c65943c5097db513e9845ba14e84324b39e9a8ea2bb43193 hooks/codex.json
|
|
20
20
|
b656fed2b754ebcfd4c156bee81d5879c21a8083fc0d6b8e3241462b63a214b6 hooks/copilot-cli.json
|
|
@@ -23,16 +23,17 @@ f336d1db67de49e641687bbd41ba1a9424e31dfe2377b2284bf44358288ebd8b hooks/kiro.jso
|
|
|
23
23
|
017c9cc3997dd53231b8548b1a1609fddc51177af53501565a4f334602039860 hooks/qwen.json
|
|
24
24
|
33f69267645338d0dc392ce551dcd7c69a0b508113469d6ea637d3f34239ef1d hooks/vscode.json
|
|
25
25
|
085630bccf2073ac9a62be24ef91dfc47d106092dc82c822db70890b7d3ae1c0 hooks/zcode.json
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
61d6599bc5a861d378bafc89fcbe9b52d503720de60b47d9b7639547ad067061 omp/index.js
|
|
27
|
+
54aa5d4e4b3cf210d40b237ff5d0e92d4568d0fb633ae009f29775a578b16a86 opencode/plugin.js
|
|
28
|
+
6b0355b01045b1fe07c1d00f89cfb84103e9d6ee252439da74911a477ce08bc3 package.json
|
|
29
|
+
8b8cc6a163210096daba9de2ab1cc8345cf0387e48a58e77b7c5e9f33c335dff pi/index.js
|
|
29
30
|
8712881622c9905aa4836af50d903042d34a91506264e459bc7839331f6f0192 pi/skills/ctx-doctor/SKILL.md
|
|
30
31
|
4ff03de9581acbb827266eb9461aa34c8da5c3d01d51a3738064e582bf466a79 pi/skills/ctx-stats/SKILL.md
|
|
31
32
|
db6f9c006bc864a7271f1eeffb1e316ebb537a3414f1c22f8b9de0a896e8e3c5 pi/skills/ctx-upgrade/SKILL.md
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
83f61c608c807d63576c0991511d56deb260ab285452f1e2981082e7dd3ec987 qwen-extension.json
|
|
34
|
+
e19be7165fad581f251ddde17b1d1df686e59c15e904d3ee95584b5f18b4b3aa run.mjs
|
|
35
|
+
e19be7165fad581f251ddde17b1d1df686e59c15e904d3ee95584b5f18b4b3aa search.mjs
|
|
36
|
+
f5ae6e9ea401817aa3ae83e99a6150c4d474c24085e52f3c99f12720347efff8 server.mjs
|
|
37
|
+
a75ca34ce13494cffafea8835ee2396f07108310705cb34228b3a3409b089cb3 skills/ctx-doctor/SKILL.md
|
|
38
|
+
9151ed7ebc3e6d997418349265f2e7dd03aabe564ece6492294f173d90d8f149 skills/ctx-stats/SKILL.md
|
|
39
|
+
f67dab4cba555e44e97f5a3ecbc3322f3fea0baaf45f3027615f7b2482e6d018 skills/ctx-upgrade/SKILL.md
|