context-mode 2.0.0-next.24 → 2.0.0-next.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +276 -247
- package/SHA256SUMS +15 -15
- package/cli.mjs +23 -14
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +60 -60
- package/opencode/plugin.js +259 -112
- package/package.json +1 -1
- package/pi/index.js +290 -143
- package/qwen-extension.json +1 -1
- package/run.mjs +24 -22
- package/search.mjs +24 -22
- package/server.mjs +257 -127
package/README.md
CHANGED
|
@@ -1,319 +1,342 @@
|
|
|
1
1
|
# Context Mode
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**A free, local plugin that keeps tool output out of your coding agent's context window. 10 agents, zero telemetry, free forever.**
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/context-mode) [](https://github.com/mksglu/context-mode) [](https://news.ycombinator.com/item?id=47193064) [](https://github.com/uibm/trending-watcher/issues?q=%22mksglu%2Fcontext-mode%22) [](https://discord.gg/DCN9jUgN5v) [](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
5
|
+
[](https://www.npmjs.com/package/context-mode) [](https://github.com/mksglu/context-mode) [](https://news.ycombinator.com/item?id=47193064) [](https://github.com/uibm/trending-watcher/issues?q=%22mksglu%2Fcontext-mode%22) [](https://discord.gg/DCN9jUgN5v) [](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/LICENSE)
|
|
6
6
|
|
|
7
|
-
> **Context Mode Gateway** takes the same idea from tool output to the whole conversation. It is an optional hosted service that works next to this plugin: Recall keeps long sessions searchable, and Memory shares what your agents learn across sessions and tools. The plugin stays free
|
|
7
|
+
> **Context Mode Gateway** takes the same idea from tool output to the whole conversation. It is an optional hosted service that works next to this plugin: Gateway Recall keeps long sessions searchable, and Gateway Memory shares what your agents learn across sessions and tools. The plugin stays free and local, with its source open on GitHub. [See how the Gateway works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=quote)
|
|
8
8
|
|
|
9
9
|
<picture>
|
|
10
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.
|
|
11
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.
|
|
10
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/hero-dark.png">
|
|
11
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/hero-light.png" alt="Context Mode plugin: free and local, for 10 coding agents, zero telemetry, your data stays on your machine. 99.4% of output bytes saved (median of 36 rows with 10 KB or more of raw output).">
|
|
12
12
|
</picture>
|
|
13
13
|
|
|
14
|
-
**
|
|
15
|
-
|
|
16
|
-
<p align="center">
|
|
17
|
-
<sub>Starred by engineers at</sub>
|
|
18
|
-
<br><br>
|
|
19
|
-
<a href="#"><img src="https://img.shields.io/badge/Microsoft-141414?style=flat" alt="Microsoft" /></a>
|
|
20
|
-
<a href="#"><img src="https://img.shields.io/badge/Google-141414?style=flat&logo=google&logoColor=white" alt="Google" /></a>
|
|
21
|
-
<a href="#"><img src="https://img.shields.io/badge/Meta-141414?style=flat&logo=meta&logoColor=white" alt="Meta" /></a>
|
|
22
|
-
<a href="#"><img src="https://img.shields.io/badge/Amazon-141414?style=flat" alt="Amazon" /></a>
|
|
23
|
-
<a href="#"><img src="https://img.shields.io/badge/IBM-141414?style=flat" alt="IBM" /></a>
|
|
24
|
-
<a href="#"><img src="https://img.shields.io/badge/NVIDIA-141414?style=flat&logo=nvidia&logoColor=white" alt="NVIDIA" /></a>
|
|
25
|
-
<a href="#"><img src="https://img.shields.io/badge/ByteDance-141414?style=flat&logo=bytedance&logoColor=white" alt="ByteDance" /></a>
|
|
26
|
-
<a href="#"><img src="https://img.shields.io/badge/Stripe-141414?style=flat&logo=stripe&logoColor=white" alt="Stripe" /></a>
|
|
27
|
-
<a href="#"><img src="https://img.shields.io/badge/Datadog-141414?style=flat&logo=datadog&logoColor=white" alt="Datadog" /></a>
|
|
28
|
-
<a href="#"><img src="https://img.shields.io/badge/Salesforce-141414?style=flat" alt="Salesforce" /></a>
|
|
29
|
-
<a href="#"><img src="https://img.shields.io/badge/GitHub-141414?style=flat&logo=github&logoColor=white" alt="GitHub" /></a>
|
|
30
|
-
<a href="#"><img src="https://img.shields.io/badge/Red%20Hat-141414?style=flat&logo=redhat&logoColor=white" alt="Red Hat" /></a>
|
|
31
|
-
<a href="#"><img src="https://img.shields.io/badge/Supabase-141414?style=flat&logo=supabase&logoColor=white" alt="Supabase" /></a>
|
|
32
|
-
<a href="#"><img src="https://img.shields.io/badge/Canva-141414?style=flat" alt="Canva" /></a>
|
|
33
|
-
<a href="#"><img src="https://img.shields.io/badge/Notion-141414?style=flat&logo=notion&logoColor=white" alt="Notion" /></a>
|
|
34
|
-
<a href="#"><img src="https://img.shields.io/badge/Hasura-141414?style=flat&logo=hasura&logoColor=white" alt="Hasura" /></a>
|
|
35
|
-
<a href="#"><img src="https://img.shields.io/badge/Framer-141414?style=flat&logo=framer&logoColor=white" alt="Framer" /></a>
|
|
36
|
-
<a href="#"><img src="https://img.shields.io/badge/Cursor-141414?style=flat&logo=cursor&logoColor=white" alt="Cursor" /></a>
|
|
37
|
-
</p>
|
|
38
|
-
|
|
39
|
-
## Abstract
|
|
14
|
+
**Contents:** [Why](#why) · [Install](#install) · [Supported agents](#supported-agents) · [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) · [Star history](#star-history) · [License](#license) · [Community](#community)
|
|
40
15
|
|
|
41
|
-
|
|
42
|
-
One Playwright snapshot is 57.5 KB; one access log is 46.2 KB. The window fills, the agent compacts, and it forgets what it was doing.
|
|
43
|
-
Context Mode runs the tool work in a local sandbox, keeps the full output in a per-project SQLite index, and returns what the agent asks for.
|
|
44
|
-
On the 25 bench rows with 10 KB or more of raw output, it cut the bytes that reach the context by a median of 98.8%, measured with `ctx_bytes` against `raw_bytes`, 5 runs each.
|
|
45
|
-
Context Mode Gateway, an optional hosted service, takes the same idea to the whole conversation and all your agents. On a pre-registered long session with a 200K window it cut cost from $4.86 to $3.04 (2026-10-04) (-37.6%).
|
|
46
|
-
You can use both layers together. This paper gives the method, the numbers with their raw files, and the test setup behind each one.
|
|
47
|
-
|
|
48
|
-
## 1. The problem
|
|
49
|
-
|
|
50
|
-
Each tool result goes into the context window whole. Table 1 lists real outputs from the bench, and what Context Mode returns for each.
|
|
51
|
-
|
|
52
|
-
**Table 1.** Raw output against the reply the agent sees (median of 5 runs, bench of 2026-10-31).
|
|
53
|
-
|
|
54
|
-
| Tool output | Raw | Reply | Cut |
|
|
55
|
-
|---|---:|---:|---:|
|
|
56
|
-
| Playwright page snapshot | 57,521 B | 315 B | 99.5% |
|
|
57
|
-
| 20 GitHub issues | 60,310 B | 1,156 B | 98.1% |
|
|
58
|
-
| Access log, 500 requests | 46,216 B | 171 B | 99.6% |
|
|
59
|
-
| `npm install` log | 37,761 B | 451 B | 98.8% |
|
|
60
|
-
| Big source file | 61,576 B | 489 B | 99.2% |
|
|
61
|
-
| Large git log | 191,120 B | 153 B | 99.9% |
|
|
62
|
-
| Docs page through WebFetch | 215,354 B | 435 B | 99.8% |
|
|
63
|
-
|
|
64
|
-
Rule for every headline number in this paper: rows with 10 KB or more of raw output, median per category.
|
|
65
|
-
The full results file has [every row, including small outputs, where the cut is smaller](https://github.com/mksglu/context-mode/blob/v2.0.0-next.24/bench/results/2026-10-31-darwin-arm64.md).
|
|
66
|
-
|
|
67
|
-
## 2. Results
|
|
68
|
-
|
|
69
|
-
<picture>
|
|
70
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.24/docs/assets/readme/fig-saving-dark.png">
|
|
71
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.24/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.3%, Batch 93.1%, Externalize 92.3%, Hook redirect 99.8%, Session total 98.8%.">
|
|
72
|
-
</picture>
|
|
73
|
-
|
|
74
|
-
**Figure 2.** Median bytes saved per category, rows of 10 KB or more.
|
|
16
|
+
## Why
|
|
75
17
|
|
|
76
|
-
|
|
18
|
+
A coding agent reads files, runs commands and fetches pages, and every result goes into its context window.
|
|
19
|
+
Context Mode runs that work in a local sandbox, keeps the full output in a SQLite index on your machine, and gives the agent the part it asks for.
|
|
77
20
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
| g. Session total | One full scripted session | 1 | 98.8% |
|
|
21
|
+
- **Free forever.** Use it at home and at work, free of charge, under a source-available license.
|
|
22
|
+
- **Runs on your machine.** The hooks, the sandbox and search run as local processes next to your agent.
|
|
23
|
+
- **The plugin keeps your data on your machine.** Every index lives in `~/.context-mode`: one `context.db` per project.
|
|
24
|
+
- **Zero telemetry.** The plugin keeps all usage data on your machine. A CI test keeps its short list of network calls fixed: see [Security and privacy](#security-and-privacy).
|
|
25
|
+
- **Works offline after install.** Sandbox runs, file indexing and search use local SQLite and your own runtimes.
|
|
26
|
+
- **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.
|
|
85
27
|
|
|
86
|
-
|
|
87
|
-
Reproduce: `cd bench && node run.mjs`. Method and every data file: [bench/README.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.24/bench/README.md), [bench/evidence/](https://github.com/mksglu/context-mode/blob/v2.0.0-next.24/bench/evidence/README.md).
|
|
88
|
-
The plugin numbers are bytes; the dollar numbers come from the Gateway runs in section 8.
|
|
28
|
+
## Install
|
|
89
29
|
|
|
90
|
-
|
|
30
|
+
> [!IMPORTANT]
|
|
31
|
+
> You need Node 24.15.0 or later. On Windows you also need Git for Windows: the shell tools run in Git Bash, and `context-mode doctor` check D11 (shell) checks for it.
|
|
91
32
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
Result: 315 B reach the context, a 99.5% cut, measured over 5 runs.
|
|
33
|
+
Open your agent and copy its own install command. Each block also has the update, check and remove steps.
|
|
34
|
+
`release` and `next` are the 2.0 channels; each command below already names the right one.
|
|
95
35
|
|
|
96
|
-
|
|
97
|
-
Action: the `PreToolUse` hook denies the fetch and routes it to `ctx_index`, which keeps the page, and `ctx_search`, which returns the part asked for.
|
|
98
|
-
Result: a 435 B reply instead of 215,354 B, a 99.8% cut. The hook took 54 ms.
|
|
36
|
+
<details open id="install-claude-code"><summary><b>Claude Code</b></summary>
|
|
99
37
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
38
|
+
```sh
|
|
39
|
+
claude plugin marketplace add mksglu/context-mode#release
|
|
40
|
+
claude plugin install context-mode@context-mode
|
|
41
|
+
```
|
|
42
|
+
Update: `claude plugin update context-mode@context-mode`. Check: `context-mode doctor --agents claude-code`. Remove: `context-mode setup --remove --agents claude-code`. Guide: [docs/install/claude-code.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/claude-code.md).
|
|
43
|
+
</details>
|
|
44
|
+
<details open id="install-codex"><summary><b>Codex</b></summary>
|
|
103
45
|
|
|
104
|
-
|
|
46
|
+
```sh
|
|
47
|
+
codex plugin marketplace add mksglu/context-mode@release
|
|
48
|
+
codex plugin add context-mode@context-mode
|
|
49
|
+
```
|
|
50
|
+
Update: `codex plugin marketplace upgrade context-mode`. Check: `context-mode doctor --agents codex`. Remove: `context-mode setup --remove --agents codex`. Guide: [docs/install/codex.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/codex.md).
|
|
51
|
+
</details>
|
|
52
|
+
<details open id="install-gemini"><summary><b>Gemini CLI</b></summary>
|
|
105
53
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
54
|
+
```sh
|
|
55
|
+
gemini extensions install https://github.com/mksglu/context-mode --ref release
|
|
56
|
+
```
|
|
57
|
+
Update: `gemini extensions update context-mode`. Check: `context-mode doctor --agents gemini`. Remove: `context-mode setup --remove --agents gemini`, then `gemini extensions uninstall context-mode`. Guide: [docs/install/gemini.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/gemini.md).
|
|
58
|
+
</details>
|
|
59
|
+
<details id="install-qwen"><summary><b>Qwen Code</b></summary>
|
|
110
60
|
|
|
111
|
-
|
|
61
|
+
```sh
|
|
62
|
+
qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release
|
|
63
|
+
```
|
|
64
|
+
Update: `qwen extensions update context-mode`. Check: `context-mode doctor --agents qwen`. Remove: `context-mode setup --remove --agents qwen`, then `qwen extensions uninstall context-mode`. Guide: [docs/install/qwen.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/qwen.md).
|
|
65
|
+
</details>
|
|
66
|
+
<details id="install-pi"><summary><b>Pi</b></summary>
|
|
112
67
|
|
|
113
|
-
|
|
68
|
+
```sh
|
|
69
|
+
pi install npm:context-mode@next
|
|
70
|
+
```
|
|
71
|
+
Update: `pi update --extensions`. Check: `context-mode doctor --agents pi`. Remove: `context-mode setup --remove --agents pi`. Guide: [docs/install/pi.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/pi.md).
|
|
72
|
+
</details>
|
|
73
|
+
<details id="install-opencode"><summary><b>OpenCode</b></summary>
|
|
114
74
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
75
|
+
```sh
|
|
76
|
+
opencode plugin add context-mode@next
|
|
77
|
+
```
|
|
78
|
+
Update: `opencode plugin update`. Check: `context-mode doctor --agents opencode`. Remove: `opencode plugin remove context-mode@next`, then `context-mode setup --remove --agents opencode`. Guide: [docs/install/opencode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/opencode.md).
|
|
79
|
+
</details>
|
|
80
|
+
<details id="install-copilot-cli"><summary><b>Copilot CLI</b></summary>
|
|
118
81
|
|
|
119
|
-
|
|
82
|
+
```sh
|
|
83
|
+
npm i -g context-mode@next
|
|
84
|
+
context-mode setup --agents copilot-cli
|
|
85
|
+
```
|
|
86
|
+
Update: `context-mode upgrade`. Check: `context-mode doctor --agents copilot-cli`. Remove: `context-mode setup --remove --agents copilot-cli`. Guide: [docs/install/copilot-cli.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/copilot-cli.md).
|
|
87
|
+
</details>
|
|
88
|
+
<details id="install-kiro"><summary><b>Kiro</b></summary>
|
|
120
89
|
|
|
121
|
-
|
|
90
|
+
```sh
|
|
91
|
+
npm i -g context-mode@next
|
|
92
|
+
context-mode setup --agents kiro
|
|
93
|
+
```
|
|
94
|
+
Update: `context-mode upgrade`. Check: `context-mode doctor --agents kiro`. Remove: `context-mode setup --remove --agents kiro`. Guide: [docs/install/kiro.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/kiro.md).
|
|
95
|
+
</details>
|
|
96
|
+
<details id="install-vscode"><summary><b>VS Code (Copilot)</b></summary>
|
|
122
97
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
| OpenCode | `opencode plugin add context-mode@next` (1.19: `opencode plugin context-mode@next --global`) | `opencode plugin update` (1.19: `opencode plugin context-mode@next --global --force`) |
|
|
98
|
+
```sh
|
|
99
|
+
npm i -g context-mode@next
|
|
100
|
+
context-mode setup --agents vscode
|
|
101
|
+
```
|
|
102
|
+
Update: `context-mode upgrade`. Check: `context-mode doctor --agents vscode`. Remove: `context-mode setup --remove --agents vscode`. Guide: [docs/install/vscode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/vscode.md).
|
|
103
|
+
</details>
|
|
104
|
+
<details id="install-zcode"><summary><b>ZCode</b></summary>
|
|
131
105
|
|
|
132
|
-
|
|
106
|
+
```sh
|
|
107
|
+
npm i -g context-mode@next
|
|
108
|
+
context-mode setup --agents zcode
|
|
109
|
+
```
|
|
110
|
+
Update: `context-mode upgrade`. Check: `context-mode doctor --agents zcode`. Remove: `context-mode setup --remove --agents zcode`. Guide: [docs/install/zcode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/zcode.md).
|
|
111
|
+
</details>
|
|
133
112
|
|
|
113
|
+
The four GitHub-source commands name the `release` branch in each agent's own syntax.
|
|
114
|
+
Already installed from GitHub on `main`? Each agent page has the steps to switch to the `release` ref: see "Already installed from GitHub?" in [Claude Code](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/claude-code.md#already-installed-from-github), [Codex](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/codex.md#already-installed-from-github), [Gemini CLI](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/gemini.md#already-installed-from-github) and [Qwen Code](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/qwen.md#already-installed-from-github).
|
|
115
|
+
<!--
|
|
134
116
|
After v2 is on main: `claude plugin marketplace add mksglu/context-mode`, `codex plugin marketplace add mksglu/context-mode`, `gemini extensions install https://github.com/mksglu/context-mode`, `qwen extensions install https://github.com/mksglu/context-mode:context-mode`
|
|
117
|
+
`next` is the v2 prerelease tag on npm.
|
|
118
|
+
Switch day: remove the `release` and `next` lines and the "Already installed from GitHub?" line; drop `#release`, `@release`, `--ref release` and `@next` from the commands.
|
|
119
|
+
Agent note, native install then update per agent: claude-code: `claude plugin marketplace add mksglu/context-mode#release`, then `claude plugin install context-mode@context-mode`; update `claude plugin update context-mode@context-mode`. codex: `codex plugin marketplace add mksglu/context-mode@release`, then `codex plugin add context-mode@context-mode`; update `codex plugin marketplace upgrade context-mode`. gemini: `gemini extensions install https://github.com/mksglu/context-mode --ref release`; update `gemini extensions update context-mode`. qwen: `qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release`; update `qwen extensions update context-mode`. pi: `pi install npm:context-mode@next`; update `pi update --extensions`. opencode: `opencode plugin add context-mode@next`; update `opencode plugin update`.
|
|
120
|
+
-->
|
|
135
121
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
Copilot CLI, Kiro, VS Code and ZCode install through npm, which works for every agent:
|
|
122
|
+
The npm route works for every agent:
|
|
139
123
|
|
|
140
124
|
```sh
|
|
141
125
|
npm i -g context-mode@next
|
|
142
126
|
context-mode setup
|
|
143
127
|
```
|
|
144
128
|
|
|
145
|
-
`next` is the
|
|
146
|
-
|
|
147
|
-
`context-mode setup
|
|
148
|
-
|
|
129
|
+
`next` is the 2.0 tag on npm, so add `@next`.
|
|
130
|
+
`context-mode setup` is also the repair. It shows a plan, saves your earlier config, then applies the plan; if a step stops, it puts the saved config back.
|
|
131
|
+
Uninstall: `context-mode setup --remove && npm rm -g context-mode`. Details: [docs/install/README.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/README.md).
|
|
132
|
+
|
|
133
|
+
> [!TIP]
|
|
134
|
+
> Restart the agent, then run `context-mode doctor` (or `/ctx-doctor` in the agent). Each check prints PASS or a fix command.
|
|
135
|
+
|
|
136
|
+
## Supported agents
|
|
149
137
|
|
|
150
|
-
Every agent gets hooks, the MCP server and the skills. The Install column is the agent's own install command, or the npm route for the other four agents.
|
|
138
|
+
Every agent gets hooks, the MCP server and the plugin skills (files in `skills/`). The Install column is the agent's own install command, or the npm route for the other four agents.
|
|
151
139
|
|
|
152
140
|
<!-- agents:install:start (node build/readme-agents.mjs --write) -->
|
|
153
141
|
| Agent | Hooks | MCP | Skills | Install | Guide |
|
|
154
142
|
|---|---|---|---|---|---|
|
|
155
|
-
| Claude Code | yes, package | yes | yes | `claude plugin install context-mode@context-mode` | [docs/install/claude-code.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
156
|
-
| Codex | yes, hook file | yes | yes | `codex plugin add context-mode@context-mode` | [docs/install/codex.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
157
|
-
| Copilot CLI | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/copilot-cli.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
158
|
-
| Gemini CLI | yes, package | yes | yes | `gemini extensions install https://github.com/mksglu/context-mode --ref release` | [docs/install/gemini.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
159
|
-
| Kiro | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/kiro.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
160
|
-
| OpenCode | yes,
|
|
161
|
-
| Pi | yes,
|
|
162
|
-
| Qwen Code | yes, package | yes | yes | `qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release` | [docs/install/qwen.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
163
|
-
| VS Code (Copilot) | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/vscode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
164
|
-
| ZCode | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/zcode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
143
|
+
| Claude Code | yes, package | yes | yes | `claude plugin marketplace add mksglu/context-mode#release`<br>`claude plugin install context-mode@context-mode` | [docs/install/claude-code.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/claude-code.md#install) |
|
|
144
|
+
| Codex | yes, hook file | yes | yes | `codex plugin marketplace add mksglu/context-mode@release`<br>`codex plugin add context-mode@context-mode` | [docs/install/codex.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/codex.md#install) |
|
|
145
|
+
| Copilot CLI | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/copilot-cli.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/copilot-cli.md#install) |
|
|
146
|
+
| Gemini CLI | yes, package | yes | yes | `gemini extensions install https://github.com/mksglu/context-mode --ref release` | [docs/install/gemini.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/gemini.md#install) |
|
|
147
|
+
| Kiro | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/kiro.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/kiro.md#install) |
|
|
148
|
+
| OpenCode | yes, the plugin's own event handlers | yes | yes | `opencode plugin add context-mode@next` | [docs/install/opencode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/opencode.md#install) |
|
|
149
|
+
| Pi | yes, the plugin's own event handlers | plugin inside the agent | yes | `pi install npm:context-mode@next` | [docs/install/pi.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/pi.md#install) |
|
|
150
|
+
| Qwen Code | yes, package | yes | yes | `qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release` | [docs/install/qwen.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/qwen.md#install) |
|
|
151
|
+
| VS Code (Copilot) | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/vscode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/vscode.md#install) |
|
|
152
|
+
| ZCode | yes, hook file | yes | yes | npm + `context-mode setup` | [docs/install/zcode.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/zcode.md#install) |
|
|
165
153
|
<!-- agents:install:end -->
|
|
166
154
|
|
|
167
|
-
|
|
155
|
+
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).
|
|
156
|
+
The real agent binary ran our hook for Claude Code, Codex, Gemini CLI, Qwen Code, Pi, OpenCode, Copilot CLI and ZCode, in a clean temp home, logged out, with a local test model (2.0.0-next.15, the release that the record below covers).
|
|
157
|
+
VS Code runs the hook command with the documented payload, and kiro-cli 2.35.2 loads all 6 hook entries.
|
|
158
|
+
CI runs setup, doctor, a hook and an MCP handshake for all 10 agents from the packed package on Linux, macOS and Windows. Record: [docs/architecture/release/HOOKS-FIRE.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/architecture/release/HOOKS-FIRE.md).
|
|
159
|
+
|
|
160
|
+
## Use cases
|
|
161
|
+
|
|
162
|
+
Real tool output from public projects, run through Context Mode. Bench of 2026-11-01 on 2.0.0-next.23 (commit 16a4bcc5), median of 5 runs ([bench/results/2026-11-01-darwin-arm64.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/results/2026-11-01-darwin-arm64.json)); each source is in [bench/fixtures/data/SOURCE.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/fixtures/data/SOURCE.md).
|
|
163
|
+
|
|
164
|
+
| What you do | Tool | Raw | Reaches the context | Saved |
|
|
165
|
+
|---|---|---:|---:|---:|
|
|
166
|
+
| [Read a browser page](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-devtools-mcp-snapshot) | Chrome DevTools MCP `take_snapshot` | 136,514 B | 463 B | 99.7% |
|
|
167
|
+
| [List 40 issues](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-gh-issue-list-vite) | GitHub CLI `gh issue list --json` | 182,943 B | 850 B | 99.5% |
|
|
168
|
+
| [List 25 pull requests with checks](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-gh-pr-list-vite) | GitHub CLI `gh pr list --json` | 195,471 B | 776 B | 99.6% |
|
|
169
|
+
| [Look up library docs](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-context7-query-docs-vite) | Context7 `query-docs` | 6,917 B | 473 B | 93.2% |
|
|
170
|
+
| [Run 1,106 tests](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-vitest-run-vite) | Vitest `vitest run --reporter=verbose` | 62,909 B | 429 B | 99.3% |
|
|
171
|
+
| [Lint a source folder](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-biome-lint-vite) | Biome `biome lint --reporter=json` | 288,523 B | 577 B | 99.8% |
|
|
172
|
+
| [Install a workspace](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-pnpm-install-vite) | pnpm `pnpm install --frozen-lockfile` | 14,988 B | 199 B | 98.7% |
|
|
173
|
+
| [Install packages](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-npm-install-log) | npm `npm install --loglevel http` | 37,761 B | 435 B | 98.8% |
|
|
174
|
+
| [Read container logs](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-docker-logs-mongo) | Docker `docker logs` | 60,374 B | 587 B | 99.0% |
|
|
175
|
+
| [Plan 72 resources](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-terraform-plan) | Terraform `terraform plan` | 34,081 B | 166 B | 99.5% |
|
|
176
|
+
| [Read 300 commits with file stats](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/a-sandbox/README.md#a-git-log-stat-vite) | git `git log --stat` | 164,385 B | 268 B | 99.8% |
|
|
177
|
+
| [Read an 89 KB source file](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/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% |
|
|
178
|
+
| [Fetch a 265 KB docs page](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/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% |
|
|
179
|
+
| [Fetch a 214 KB API reply](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/f-hook-redirect/README.md#f-bash-curl-post) | curl in Bash, replaced after it runs | 219,175 B | 291 B | 99.9% |
|
|
180
|
+
| [Debug for a full session: 8 outputs, 3 searches](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/g-overhead/README.md#g-session-total) | All hooks and tools | 281,261 B | 3,266 B | 98.8% |
|
|
181
|
+
|
|
182
|
+
The agent gets the part it asks for. The full output stays in the local index, and `ctx_search` reads it back.
|
|
183
|
+
|
|
184
|
+
## Benchmarks
|
|
185
|
+
|
|
186
|
+
<picture>
|
|
187
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/fig-saving-dark.png">
|
|
188
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/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%.">
|
|
189
|
+
</picture>
|
|
190
|
+
|
|
191
|
+
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.
|
|
192
|
+
All 36 such rows, the six categories below: the plugin keeps a median of 99.4% of output bytes out of the context. Bench on 2.0.0-next.23, commit 16a4bcc5 with local edits (`dirty: true` in the file), macOS arm64, 2026-11-01.
|
|
193
|
+
|
|
194
|
+
| Category | What runs | Rows | Median saved |
|
|
195
|
+
|---|---|---:|---:|
|
|
196
|
+
| a. Sandbox | `ctx_execute` on a file or command | 19 | 99.5% |
|
|
197
|
+
| b. Retrieval | `ctx_search` over the local index | 3 | 77.2% |
|
|
198
|
+
| c. Batch | `ctx_batch`: many commands, then search | 2 | 93.1% |
|
|
199
|
+
| d. Externalize | Host tool output over the cap, indexed whole | 4 | 98.3% |
|
|
200
|
+
| f. Hook redirect | A big Read, curl or WebFetch sent to the sandbox | 7 | 99.8% |
|
|
201
|
+
| g. Session total | One full scripted session | 1 | 98.8% |
|
|
202
|
+
|
|
203
|
+
Search replies (category b) return the matching text, so they keep less out. The full file lists every row, small ones too: [bench/results/2026-11-01-darwin-arm64.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/results/2026-11-01-darwin-arm64.md).
|
|
204
|
+
Reproduce: `cd bench && node run.mjs`. Method and every data file: [bench/README.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/README.md), [bench/evidence/](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/evidence/README.md).
|
|
205
|
+
|
|
206
|
+
### Longer sessions
|
|
168
207
|
|
|
169
208
|
<picture>
|
|
170
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.
|
|
171
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.
|
|
209
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/fig-oss-dark.png">
|
|
210
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/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.">
|
|
172
211
|
</picture>
|
|
173
212
|
|
|
174
|
-
|
|
213
|
+
Each tool call: the hook sends large output to the sandbox or the index, the full copy goes into `context.db`, and the agent gets a small reply. At compaction, a snapshot of at most 2,048 B keeps the state, and `ctx_resume` and `ctx_search` read it back.
|
|
175
214
|
|
|
176
|
-
|
|
215
|
+
- Long session, 40 outputs, then compaction: a 442,893 B transcript, a 2,019 B `ctx_resume` block ([bench/results/2026-11-01-darwin-arm64.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/results/2026-11-01-darwin-arm64.json), row [e-long-session](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/e-continuity/README.md#e-long-session)).
|
|
216
|
+
- One large log: 666,796 B of output, 3,380 B reach the context (row [d-synth-1m](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/d-externalize/README.md#d-synth-1m)).
|
|
177
217
|
|
|
178
|
-
###
|
|
218
|
+
### Speed
|
|
179
219
|
|
|
180
|
-
|
|
181
|
-
`PreToolUse` checks rules in a fixed order: the user's deny list, WebFetch, curl and HTTP or build commands, then Read and shell dumps.
|
|
182
|
-
Context Mode denies a full-file `Read` of a file over 16,384 B, and the deny message names the exact `ctx_execute` call to use. A `Read` with a range still runs.
|
|
183
|
-
A hook always exits 0: on any error it gives the host's "allow" reply and writes one log line, so your agent keeps working. Spawned hooks time out after 5,000 ms.
|
|
220
|
+
Median of 5 runs, bench of 2026-11-01. Rows per agent and per query: [bench/results/2026-11-01-darwin-arm64.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/results/2026-11-01-darwin-arm64.md).
|
|
184
221
|
|
|
185
|
-
|
|
222
|
+
| Measure | Result |
|
|
223
|
+
|---|---|
|
|
224
|
+
| Hook time over a bare `node` start, per agent | 7.5 ms to 12.3 ms ([g-hook-kiro](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/g-overhead/README.md#g-hook-kiro) to [g-hook-claude-code](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/g-overhead/README.md#g-hook-claude-code)) |
|
|
225
|
+
| `ctx_search`, 20 queries over 8 indexed files | 1.62 ms median, 6.70 ms max ([g-search-latency](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/g-overhead/README.md#g-search-latency)) |
|
|
226
|
+
| `ctx_index`, 3 real files, 625,649 B | 150 ms per MB ([g-index-per-mb](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/g-overhead/README.md#g-index-per-mb)) |
|
|
186
227
|
|
|
187
|
-
|
|
188
|
-
It spawns the runtime directly from an argument list, in the project folder. The default and maximum timeout is 600,000 ms; on timeout it kills the whole process group (`taskkill /F /T` on Windows).
|
|
189
|
-
The child gets the parent environment minus the preload variables (`NODE_OPTIONS`, `BUN_OPTIONS`, `DENO_OPTIONS` and similar). The agent gets what the script prints, cut on a whole character.
|
|
228
|
+
## How it works
|
|
190
229
|
|
|
191
|
-
|
|
230
|
+
<picture>
|
|
231
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/fig-flow-dark.png">
|
|
232
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/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.">
|
|
233
|
+
</picture>
|
|
192
234
|
|
|
193
|
-
|
|
194
|
-
`ctx_search` ranks each table with BM25 and joins the two lists with Reciprocal Rank Fusion: a hit scores 1/(60 + rank) in each list.
|
|
195
|
-
On zero matches, it tries a spelling fix from the indexed words. Search covers one of three scopes: this session, this worktree (the default) or the whole project.
|
|
196
|
-
Chunks are at most 4,096 B. A Markdown chunk stays inside one heading section and carries its heading path as its title. A code block that fits in a chunk stays whole; a bigger one splits on blank lines, and each piece repeats the fence.
|
|
197
|
-
A reply snippet is at most 800 B, or a whole code block up to 2,048 B.
|
|
235
|
+
Context Mode has three parts: hooks, an MCP server with nine tools, and one SQLite database per project. All three run on your machine, and the data stays in `~/.context-mode`.
|
|
198
236
|
|
|
199
|
-
|
|
237
|
+
**Hooks.** The hooks listen to four events: `SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`. Gemini CLI, VS Code and OpenCode also send a compaction event; each host keeps its own event names. `PreToolUse` checks rules in a fixed order: the user's deny list, WebFetch, curl and HTTP or build commands, then Read and shell dumps. Context Mode denies a full-file `Read` of a file over 16,384 B, and the deny message names the exact `ctx_execute` call to use. A `Read` with a range still runs. A hook always exits 0: on any error it gives the host's "allow" reply and writes one log line, so your agent keeps working. Spawned hooks time out after 5,000 ms.
|
|
200
238
|
|
|
201
|
-
|
|
202
|
-
The agent gets the best-matching whole chunks and one `ctx_search` line for the rest. Context Mode keeps the full text in the index.
|
|
239
|
+
**Sandbox execution.** `ctx_execute` writes the script to a temp folder and runs it as a local subprocess: shell, PowerShell, JavaScript, TypeScript, Python, or any runtime found on `PATH`. It spawns the runtime directly from an argument list, in the project folder. The default and maximum timeout is 600,000 ms; on timeout it kills the whole process group (`taskkill /F /T` on Windows). The child gets the parent environment minus the preload variables (`NODE_OPTIONS`, `BUN_OPTIONS`, `DENO_OPTIONS` and similar). The agent gets what the script prints, cut on a whole character.
|
|
203
240
|
|
|
204
|
-
|
|
241
|
+
**Index and search.** Each output goes into SQLite FTS5 twice: a Porter-stemmed table for words, and a trigram table for paths, names and parts of words. `ctx_search` ranks each table with BM25 and joins the two lists with Reciprocal Rank Fusion: a hit scores 1/(60 + rank) in each list. Before it returns an empty list, it tries a spelling fix from the indexed words. Search covers one of three scopes: this session, this worktree (the default) or the whole project. Chunks are at most 4,096 B. A Markdown chunk stays inside one heading section and carries its heading path as its title. A code block that fits in a chunk stays whole; a bigger one splits on blank lines, and each piece repeats the fence. A reply snippet is at most 800 B, or a whole code block up to 2,048 B.
|
|
205
242
|
|
|
206
|
-
|
|
207
|
-
After a compaction the agent gets a state block of at most 2,048 B built from that log. Every line stays whole: a long line becomes a `ctx_resume(seq)` pointer that reads the full row.
|
|
208
|
-
On the next prompt, a recall block of at most 2,048 B brings back the log rows that match it by BM25, always as whole rows. The same rows always give the same bytes.
|
|
243
|
+
**Large output, run and replace.** When a host tool returns more than the cap, `PostToolUse` indexes the whole output and replaces it. The agent gets the best-matching whole chunks and one `ctx_search` line for the rest. Context Mode keeps the full text in the local index.
|
|
209
244
|
|
|
210
|
-
|
|
245
|
+
**Session continuity.** The hooks log each prompt, edit, command, tool error, index, cost and decision. After a compaction the agent gets a state block of at most 2,048 B built from that log. Every line stays whole: a long line becomes a `ctx_resume(seq)` pointer that reads the full row. On the next prompt, a prompt match block of at most 2,048 B brings back the log rows that match it by BM25, always as whole rows. The same rows always give the same bytes.
|
|
211
246
|
|
|
212
|
-
Context Mode uses Node's built-in `node:sqlite`, so the install
|
|
213
|
-
The database runs in WAL mode. On close it always runs a PASSIVE checkpoint. Context Mode builds a new database under a temp name, then moves it into place in one step, so the file on disk is always complete, even after a crash. Busy timeout: 5,000 ms.
|
|
247
|
+
**Storage.** Context Mode uses Node's built-in `node:sqlite`, so the install is plain JavaScript. Each project gets one `context.db` under `~/.context-mode` on your machine. The database runs in WAL mode. On close it always runs a PASSIVE checkpoint. Context Mode builds a new database under a temp name, then moves it into place in one step, so the file on disk is always complete, even after a crash. Busy timeout: 5,000 ms.
|
|
214
248
|
|
|
215
|
-
##
|
|
249
|
+
## Tools
|
|
216
250
|
|
|
217
251
|
| Tool | What it does |
|
|
218
252
|
|---|---|
|
|
219
253
|
| `ctx_execute` | Runs code or a shell command in a sandbox; returns what it prints |
|
|
220
254
|
| `ctx_batch` | Runs many commands, indexes the output, and searches it in one call |
|
|
221
255
|
| `ctx_index` | Indexes a file, a text or a URL into the project database |
|
|
222
|
-
| `ctx_search` | Searches the index; returns the matching parts |
|
|
223
|
-
| `ctx_resume` | Returns the state block, or one full row by `seq` |
|
|
256
|
+
| `ctx_search` | Searches the local index; returns the matching parts |
|
|
257
|
+
| `ctx_resume` | Returns the plugin's local state block (at most 2,048 B), or one full row by `seq` |
|
|
224
258
|
| `ctx_stats` | Shows how much output stayed out of context |
|
|
225
|
-
| `ctx_doctor` | Checks the install; each
|
|
259
|
+
| `ctx_doctor` | Checks the install; each check prints PASS or a fix command |
|
|
226
260
|
| `ctx_upgrade` | Installs, upgrades or uninstalls; replaces old context-mode entries |
|
|
227
261
|
| `ctx_purge` | Deletes indexed data by session, source or project |
|
|
228
262
|
|
|
229
|
-
Full reference: [docs/tools.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
263
|
+
Full reference: [docs/tools.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/tools.md).
|
|
230
264
|
|
|
231
|
-
|
|
265
|
+
Commands in the agent: `/ctx-stats` shows the `ctx_stats` result, `/ctx-doctor` runs `ctx_doctor` (send its report with a defect report), and `/ctx-upgrade` runs `ctx_upgrade`, then `ctx_doctor`.
|
|
232
266
|
|
|
233
|
-
|
|
234
|
-
|---|---|
|
|
235
|
-
| `/ctx-stats` | Calls `ctx_stats` and shows the result |
|
|
236
|
-
| `/ctx-doctor` | Calls `ctx_doctor`; use its report when you report a defect |
|
|
237
|
-
| `/ctx-upgrade` | Calls `ctx_upgrade`, then `ctx_doctor` |
|
|
267
|
+
## Security and privacy
|
|
238
268
|
|
|
239
|
-
|
|
269
|
+
- The plugin keeps all its data on your machine, in `~/.context-mode`: one `context.db` per project. `ctx_purge` deletes it by session, source or project.
|
|
270
|
+
- The plugin has zero telemetry: usage data, events and crash reports stay on your machine. It uses the network at these call sites, each one started by you or your agent:
|
|
271
|
+
- `ctx_index` of a URL the agent asks for: `src/core/sandbox/fetch.ts`. It 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.
|
|
272
|
+
- `context-mode doctor`: `git ls-remote` to the release repository, to check for a new version (`src/core/ops/doctor-env.ts`).
|
|
273
|
+
- `ctx_upgrade`: `git clone --depth 1` of the release branch (`src/core/ops/release-fetch.ts`). `context-mode upgrade`: `npm i -g context-mode@next` (`src/cli/commands.ts`).
|
|
274
|
+
- The debug report: `gh issue create`, after you press a key (`src/cli/commands.ts`).
|
|
275
|
+
- Install and update: your agent's own install command, npm or git.
|
|
276
|
+
- The guard test D-PRIVACY-NET-1 in `tests/0008-enforcement.test.mjs` scans `src` for HTTP clients, sockets, DNS lookups, git network calls and `gh` or `npm` spawns. It fails when a new call site appears outside this list, so this section stays true.
|
|
277
|
+
- Doctor and the debug report remove secrets by their structure before they print.
|
|
240
278
|
|
|
241
|
-
|
|
242
|
-
|
|
279
|
+
> [!NOTE]
|
|
280
|
+
> Here "sandbox" means the output stays in the sandbox, out of the context. Code from `ctx_execute` runs on your host as your user, with your environment (minus the preload variables), your files and your network; keep your agent's own permission prompts on.
|
|
243
281
|
|
|
244
|
-
|
|
245
|
-
VS Code and Kiro are at an earlier step: the VS Code hook command works with the documented payload (VS Code 1.144.0 sent 0 requests in the live run), and kiro-cli 2.35.2 loads all 6 hook entries (the live run recorded 0 hook fires).
|
|
246
|
-
CI runs setup, doctor, a hook and an MCP handshake for all 10 agents from the packed package on Linux, macOS and Windows. Record: [docs/architecture/release/HOOKS-FIRE.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.24/docs/architecture/release/HOOKS-FIRE.md).
|
|
282
|
+
## Context Mode Gateway
|
|
247
283
|
|
|
248
|
-
|
|
284
|
+
The plugin works on tool output, on your machine, and it is complete on its own. Context Mode Gateway is an optional hosted service that works on every request, across all your agents. Its 11 features, the full list: Context Saving, Recall, Memory, Skills, Search, Session resume, Active Context, Instructions, Protect, Prompt caching, Live and Analytics.
|
|
285
|
+
Teams add it for long sessions, shared memory and cost reports. The two work together.
|
|
249
286
|
|
|
250
|
-
|
|
287
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/live.mp4"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/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>
|
|
251
288
|
|
|
252
|
-
|
|
253
|
-
|---|---|
|
|
254
|
-
| Hook time over a bare `node` start, per agent | 7.3 ms to 14.6 ms |
|
|
255
|
-
| `ctx_search`, 20 queries over 8 indexed files | 1.73 ms median, 6.54 ms max |
|
|
256
|
-
| `ctx_index`, 3 real files, 0.6 MB | 155 ms per MB |
|
|
289
|
+
**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. [Full video](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/live.mp4)
|
|
257
290
|
|
|
258
|
-
|
|
291
|
+
Docs: [How saving works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=live), [Recall](https://contextmode.ai/docs/recall?utm_source=github&utm_medium=readme&utm_content=live), [Session resume](https://contextmode.ai/docs/session-resume?utm_source=github&utm_medium=readme&utm_content=live)
|
|
259
292
|
|
|
260
|
-
|
|
293
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/overview.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/gateway/overview-1200.webp" alt="Gateway Overview: money saved, AI spend, prompt-cache discount and cost per request over 30 days" width="100%"></a>
|
|
261
294
|
|
|
262
|
-
|
|
263
|
-
- Runs fully local: SQLite FTS5 and your own runtimes.
|
|
264
|
-
- Network use: npm or git (to the release repository) when you install or upgrade, `git ls-remote` in doctor (to check for a new version), and your agent's own install steps.
|
|
265
|
-
- `ctx_index` fetches a URL when the agent asks for it. It blocks private and link-local addresses. It checks each address the host name points to, connects to the address it checked, and checks again at each redirect.
|
|
266
|
-
- Doctor and the debug report remove secrets by their structure before they print.
|
|
295
|
+
**Overview.** What you paid and what the Gateway saved, per day, in one view.
|
|
267
296
|
|
|
268
|
-
|
|
269
|
-
Code from `ctx_execute` runs on your host as your user, with your environment (minus the preload variables), your files and your network; keep your agent's own permission prompts on.
|
|
297
|
+
Docs: [How saving works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=overview)
|
|
270
298
|
|
|
271
|
-
|
|
299
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/analytics.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/gateway/analytics-1200.webp" alt="Gateway Analytics: saved money over time, split by source" width="100%"></a>
|
|
272
300
|
|
|
273
|
-
|
|
274
|
-
Teams add it for long sessions, shared memory and cost reports. The two work together.
|
|
301
|
+
**Analytics.** Where each saving comes from: hidden tools, archived old results, large outputs kept in the archive and trimmed context.
|
|
275
302
|
|
|
276
|
-
|
|
303
|
+
Docs: [How saving works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=analytics), [Active Context](https://contextmode.ai/docs/active-context?utm_source=github&utm_medium=readme&utm_content=analytics)
|
|
277
304
|
|
|
278
|
-
|
|
305
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/spend.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/gateway/spend-1200.webp" alt="Gateway Spend: spend per day by model, cost per request and cache hit rate" width="100%"></a>
|
|
306
|
+
|
|
307
|
+
**Spend.** Spend per day and per model, cost per request and the cache hit rate, to help you plan a budget.
|
|
308
|
+
|
|
309
|
+
Docs: [Prompt caching](https://contextmode.ai/docs/prompt-caching?utm_source=github&utm_medium=readme&utm_content=spend)
|
|
310
|
+
|
|
311
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/memory.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/gateway/memory-top-1200.webp" alt="Gateway Memory: money saved by Recall and searches per day" width="100%"></a>
|
|
312
|
+
|
|
313
|
+
**Memory.** Facts and decisions carry across sessions and agents. The screen shows what Recall saved and how many searches found an answer.
|
|
314
|
+
|
|
315
|
+
Docs: [Memory](https://contextmode.ai/docs/memory?utm_source=github&utm_medium=readme&utm_content=memory), [Recall](https://contextmode.ai/docs/recall?utm_source=github&utm_medium=readme&utm_content=memory)
|
|
316
|
+
|
|
317
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/skills.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/gateway/skills-1200.webp" alt="Gateway Skills: import from GitHub and the list of installed skills" width="100%"></a>
|
|
318
|
+
|
|
319
|
+
**Skills.** Add a skill once and all your clients use it when it helps. Import skills from GitHub and see the installed ones.
|
|
279
320
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
<b>Memory.</b> Facts and decisions carry across sessions and agents. The screen shows what Recall saved and how many searches found an answer.
|
|
295
|
-
</td>
|
|
296
|
-
<td width="50%" valign="top">
|
|
297
|
-
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.24/docs/assets/readme/gateway/skills.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.24/docs/assets/readme/gateway/skills-1200.webp" alt="Gateway Skills: import from GitHub and the list of installed skills" width="100%"></a><br>
|
|
298
|
-
<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.
|
|
299
|
-
</td>
|
|
300
|
-
</tr>
|
|
301
|
-
<tr>
|
|
302
|
-
<td colspan="2" align="center">
|
|
303
|
-
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.24/docs/assets/readme/gateway/protect.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.24/docs/assets/readme/gateway/protect-1200.webp" alt="Gateway Protect: a new command rule that blocks terraform destroy" width="50%"></a><br>
|
|
304
|
-
<b>Protect.</b> Rules that check each shell command before it runs. Here, a rule that stops <code>terraform destroy</code>.
|
|
305
|
-
</td>
|
|
306
|
-
</tr>
|
|
307
|
-
</table>
|
|
308
|
-
|
|
309
|
-
Numbers in these screenshots 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.
|
|
310
|
-
|
|
311
|
-
**Table 4.** Context Mode Gateway features, from [contextmode.ai/docs](https://contextmode.ai/docs/how-saving-works).
|
|
321
|
+
Docs: [Skills](https://contextmode.ai/docs/skills?utm_source=github&utm_medium=readme&utm_content=skills)
|
|
322
|
+
|
|
323
|
+
<a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/assets/readme/gateway/protect.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/gateway/protect-1200.webp" alt="Gateway Protect: a new command rule that blocks terraform destroy" width="100%"></a>
|
|
324
|
+
|
|
325
|
+
**Protect.** Rules that check each shell command before it runs. Here, a rule that stops <code>terraform destroy</code>.
|
|
326
|
+
|
|
327
|
+
Docs: [Protect](https://contextmode.ai/docs/protect?utm_source=github&utm_medium=readme&utm_content=protect)
|
|
328
|
+
|
|
329
|
+
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.
|
|
330
|
+
|
|
331
|
+
<details>
|
|
332
|
+
<summary>Gateway features, from contextmode.ai/docs</summary>
|
|
333
|
+
|
|
334
|
+
Source: [contextmode.ai/docs](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=features):
|
|
312
335
|
|
|
313
336
|
| Feature | What it does | What you get | Details |
|
|
314
337
|
|---|---|---|---|
|
|
315
|
-
| Context Saving | Folds old tool output, runs data work as code (Thinking in Code), trims tool schemas, places cache marks |
|
|
316
|
-
| Recall | The model sees recent work and an index of older work; the agent searches the archive for the rest | 200K window, 2026-10-04: mean cost per session $4.86 to $3.04 (-37.6%) | Cost measured in Claude Code on Claude Opus 5.5 |
|
|
338
|
+
| Context Saving | Folds old tool output, runs data work as code (Thinking in Code), trims tool schemas, places cache marks | Gateway, Claude Code, Opus 5.5: tool schemas 102,784 B to 33,611 B per request (-67.3% of bytes); a tool output over 2,048 B becomes a pointer of about 285 B, with the full copy archived | Saves the most on sessions with many tool calls; A/B measured in Claude Code |
|
|
339
|
+
| 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.86 to $3.04 (-37.6% in dollars) | Cost measured in Claude Code on Claude Opus 5.5 |
|
|
317
340
|
| 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 |
|
|
318
341
|
| 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 |
|
|
319
342
|
| Search | Searches the prompts, commands and tool output that passed through, in the console and as an agent tool | Find any past prompt, command or tool output, from the console or your agent | The console searches the first 4,000 characters of each tool result |
|
|
@@ -324,47 +347,53 @@ Numbers in these screenshots come from the author's own account over 30 days (Oc
|
|
|
324
347
|
| Prompt caching | Keeps requests cache-friendly: cache marks on the fixed part of the prompt and a cache for fetched pages | Inside the measured costs above | Uses up to 4 cache marks, the provider's maximum |
|
|
325
348
|
| Live and Analytics | Shows each request and what the Gateway saved, as it happens and over time | See each request and its saving, live and over time | Covers every request that passes through the Gateway |
|
|
326
349
|
|
|
350
|
+
</details>
|
|
351
|
+
|
|
327
352
|
Gateway cost against Claude Code alone, Claude Opus 5.5, mean dollars per session at list price:
|
|
328
353
|
|
|
329
|
-
- Six short tasks (2026-09-29): 24.5%
|
|
330
|
-
- Long Claude Code session, 200K window (2026-10-03/04): mean cost per session $4.86 to $3.04 (-37.6%). [ab.json](https://contextmode.ai/benchmarks/recall/200k-r2/ab.json)
|
|
331
|
-
- We fixed the rules before each run: [contextmode.ai/docs/benchmarks](https://contextmode.ai/docs/benchmarks).
|
|
354
|
+
- Six short tasks (2026-09-29): 24.5% fewer dollars pooled over 176 sessions (21% to 29% per task). [v3-opus55-short.json](https://contextmode.ai/benchmarks/data/v3-opus55-short.json?utm_source=github&utm_medium=readme&utm_content=bench)
|
|
355
|
+
- Long Claude Code session, 200K window (2026-10-03/04): mean cost per session $4.86 to $3.04 (-37.6% in dollars). [ab.json](https://contextmode.ai/benchmarks/recall/200k-r2/ab.json?utm_source=github&utm_medium=readme&utm_content=bench)
|
|
356
|
+
- We fixed the rules before each run: [contextmode.ai/docs/benchmarks](https://contextmode.ai/docs/benchmarks?utm_source=github&utm_medium=readme&utm_content=bench).
|
|
332
357
|
|
|
333
358
|
Apps: Claude Code, Claude Desktop, Codex, Codex Desktop, T3 Code, OpenCode and Pi.
|
|
334
359
|
Setup is one command, `npx @context-mode/cli`. It signs you in and writes one config change per agent (it needs Node 20.12 or later).
|
|
335
|
-
|
|
360
|
+
The Gateway routes to Anthropic and OpenAI. The Gateway sends your requests to its server on the way to the model. Its privacy page is at [contextmode.ai/privacy](https://contextmode.ai/privacy?utm_source=github&utm_medium=readme&utm_content=privacy).
|
|
361
|
+
Keep your agent's own sandbox on next to Protect. More at [contextmode.ai](https://contextmode.ai/?utm_source=github&utm_medium=readme&utm_content=more).
|
|
336
362
|
|
|
337
|
-
|
|
338
|
-
Keep your agent's own sandbox on next to Protect.
|
|
339
|
-
More at [contextmode.ai](https://contextmode.ai).
|
|
363
|
+
## Star history
|
|
340
364
|
|
|
341
|
-
|
|
365
|
+
<picture>
|
|
366
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/star-history-dark.png">
|
|
367
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/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.">
|
|
368
|
+
</picture>
|
|
342
369
|
|
|
343
370
|
<picture>
|
|
344
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.
|
|
345
|
-
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.
|
|
371
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/docs/assets/readme/stargazers-dark.png">
|
|
372
|
+
<img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.26/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.">
|
|
346
373
|
</picture>
|
|
347
374
|
|
|
348
|
-
|
|
375
|
+
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.0.0-next.26/docs/assets/readme/data/stargazer-companies.json)).
|
|
376
|
+
|
|
377
|
+
GitHub stars over time, from the stargazers API (GraphQL, `starredAt`). A daily job redraws the chart; the date it was read is in the chart caption.
|
|
349
378
|
|
|
350
|
-
- **npm downloads.** The badge at the top shows
|
|
379
|
+
- **npm downloads.** The badge at the top shows npm downloads of the package over the last 365 days, read from the npm API ([stats.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/stats.json) keeps a daily copy).
|
|
351
380
|
- **Hacker News.** "MCP server that reduces Claude Code context consumption by 98%" reached the front page with 570+ points and 107 comments on 2026-02-28 ([thread](https://news.ycombinator.com/item?id=47193064)).
|
|
352
381
|
- **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)).
|
|
353
|
-
- **Companies.** Engineers at the companies under Figure 1 starred the repo.
|
|
354
382
|
|
|
355
383
|
## License
|
|
356
384
|
|
|
357
|
-
[Elastic License 2.0](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
358
|
-
The license keeps
|
|
385
|
+
[Elastic License 2.0](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/LICENSE) (ELv2), a source-available license. You may use, copy, change and share the code, and use it at work, free of charge.
|
|
386
|
+
The license keeps three uses for the licensor:
|
|
359
387
|
|
|
360
|
-
1. Offering
|
|
361
|
-
2.
|
|
388
|
+
1. Offering the software to others as a hosted or managed service that gives them a large part of its features.
|
|
389
|
+
2. Moving, changing, turning off or getting around the license key functions, or removing or hiding what the license key protects.
|
|
390
|
+
3. Changing, removing or hiding the licensor's license, copyright or other notices.
|
|
362
391
|
|
|
363
392
|
We chose ELv2 so the source stays open to all and the hosted service stays with the project.
|
|
364
393
|
|
|
365
|
-
##
|
|
394
|
+
## Community
|
|
366
395
|
|
|
367
396
|
Report a defect on [Discord](https://discord.gg/DCN9jUgN5v) with the full `/ctx-doctor` report.
|
|
368
|
-
|
|
397
|
+
The maintainer writes every change; send ideas and defect reports on Discord.
|
|
369
398
|
|
|
370
|
-
Docs: [docs/install/README.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.
|
|
399
|
+
Docs: [docs/install/README.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/install/README.md) (install, options, uninstall), [docs/how-it-works.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/how-it-works.md), [docs/algorithms.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/algorithms.md) (search, ranking, size limits, deny rules), [docs/tools.md](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/docs/tools.md), [bench/evidence/](https://github.com/mksglu/context-mode/blob/v2.0.0-next.26/bench/evidence/README.md).
|