Context Mode 2.0
Context Mode is a free, local, open source plugin for 10 coding agents. The agent writes a short script, the script runs in a local sandbox, and only the answer enters the context window. The full output stays in a SQLite index on your machine, so the agent can search it later.
2.0 is a full rewrite: 9 tools, hooks on all 10 agents, one database per project, and a bench you can run yourself.
Upgrade from 1.x
Use your agent's own command. Then restart the agent and run /ctx-upgrade in it: it replaces the old 1.x entries and keeps your own settings. /ctx-doctor then shows PASS or a fix for each check.
| Agent | Install or update |
|---|---|
| Claude Code | claude plugin marketplace add mksglu/context-mode then claude plugin install context-mode@context-mode
|
| Codex | codex plugin marketplace add mksglu/context-mode then codex plugin add context-mode@context-mode, and once: npm i -g context-mode and context-mode setup --agents codex (trusts the plugin hooks)
|
| Gemini CLI | gemini extensions install https://github.com/mksglu/context-mode (update: gemini extensions update context-mode)
|
| Qwen Code | qwen extensions install https://github.com/mksglu/context-mode:context-mode (update: qwen extensions update context-mode)
|
| Pi | pi install npm:context-mode (update: pi update --extensions)
|
| OpenCode | opencode plugin add context-mode (update: opencode plugin update)
|
| Copilot CLI | npm i -g context-mode then context-mode setup --agents copilot-cli
|
| Kiro | npm i -g context-mode then context-mode setup --agents kiro
|
| VS Code (Copilot) | npm i -g context-mode then context-mode setup --agents vscode
|
| ZCode | npm i -g context-mode then context-mode setup --agents zcode
|
Every block, with check and remove steps: README, Install and the Install guide.
Highlights
- Thinking in Code. The agent sends a script, and only what it prints comes back. On 5,000 JSON records (1,039,898 B) the agent got 254 B. How it works, step 5
- Sandbox tools.
ctx_executeruns shell, JavaScript, TypeScript, Python and other runtimes in the project folder;ctx_batchruns many commands, indexes the output and searches it in one call. Tools - 99.4% of output bytes saved. Median over the 36 bench rows with 10 KB or more of raw output, 5 runs per row. Bench file
- Search. Each chunk goes into a Porter-stemmed FTS5 table and a trigram table.
ctx_searchranks each with BM25 and joins them with Reciprocal Rank Fusion (k = 60), with a spelling fix from the indexed words. 20 queries: 1.62 ms median. How it works, step 7 - One search for content and memory.
ctx_searchreads the index and every agent's memory files (such asAGENTS.md) in one call. How it works, step 7 - Run, then replace. On hosts that run the tool first, output over 4,096 B goes into the index whole, and the agent gets the best chunks. One 666,796 B log put 3,380 B into the context. Longer sessions
- Session continuity. The hooks keep a journal of prompts, edits, commands and errors. After compaction,
ctx_resumebrings back a state block of at most 2,048 B: a 442,893 B session came back in 2,019 B. Long sessions guide - A full session. One scripted debugging session: 281,261 B of raw output, 3,266 B in the context. Bench file
ctx_statsreport. Shows how much output stayed out of the context, this session and all-time. Toolsctx_doctorwith issue reports. One row per check, each with PASS or a fix command. When a check still fails, doctor writes a report file and a readygh issuecommand for the agent to show you. Doctor guide- 10 agents with hooks. Claude Code, Codex, Gemini CLI, Qwen Code, Pi, OpenCode, Copilot CLI, Kiro, VS Code and ZCode. A hook adds 7.5 ms to 12.3 ms over a bare
nodestart. Agents guide - Node's own SQLite. The store uses the built-in
node:sqlite: no native module to build, no Bun. How it works, step 10 - Windows. CI runs setup, doctor, a hook and an MCP handshake for all 10 agents on Windows, Linux and macOS. WINDOWS.md
- A bench you can run.
cd bench && node run.mjsruns offline with plain Node and writes the same tables. bench/README.md, Benchmarks guide
Changes for 1.x users
What changed and how to move
- Node 24.15.0 or later. 1.x needed Node 22.5. 2.0 uses
node:sqlite, and 24.15.0 is the first version with it unflagged. Bun and better-sqlite3 are gone. - Data store. Each project has one
context.dbunder~/.context-mode. 2.0 starts a new index and does not copy 1.x data.ctx_doctorshows where the 1.x data is and its size, and nothing gets deleted without asking you. - Setup. The CLI has three commands:
context-mode setup,context-mode doctorandcontext-mode upgrade. Setup shows a plan, saves your config, then applies the plan; it also replaces 1.x entries. The 1.x hook forms (context-mode hook <platform> <event>andmcp) still run, and doctor asks you to run setup to rewrite them. - Tools. Nine tools:
ctx_execute,ctx_batch,ctx_index,ctx_search,ctx_resume,ctx_stats,ctx_doctor,ctx_upgrade,ctx_purge.ctx_execute_fileis nowctx_executewith afilefield.ctx_batch_executeis nowctx_batch.ctx_fetch_and_indexis nowctx_indexwith aurlfield.ctx_insightandcontext-mode insightare gone.
- Removed in 2.0: statusline, HTTP daemon mode, the CLI
indexandsearchcommands, routing files in your project (CLAUDE.md,AGENTS.mdtemplates). The routing now lives in the tool descriptions, so setup never writes your instruction files. - Agents. 2.0 supports 10 agents. Cursor, JetBrains Copilot, Kimi, Codex Desktop, OpenClaw, OMP (Oh My Pi), Antigravity (agy) and Zed are not in 2.0. To keep one of them, stay on 1.0.169.
- Your settings stay. Setup and
/ctx-upgradekeep your own hooks, hook timeouts,permissions.denyand MCP entries.
The step to move: run your agent's command from the table above, restart the agent, run /ctx-upgrade, then /ctx-doctor. If you installed 1.x with npm, remove the old global package only after that: npm uninstall -g context-mode comes last, because 1.x hooks call the global command until /ctx-upgrade replaces them.
Features and fixes
This part covers 307 commits since 1.0.169: 72 features, 222 fixes and 13 performance changes.
Search
15 changes
ctx_searchranks every agent's memory files together with indexed content, and a source filter that names a memory file searches that file. 4415e2f 5ef0a2a- Search ranks in layers: stopwords, chunks that match every term first, then an OR fallback when hits are few. ba1b9b7 60e1b62
- Search uses porter stemming and a chunk title column. c1fd04f
- Search adds a trigram table, RRF fusion and typo correction from the index vocabulary. f8f7850
- Markdown chunks split on headings and keep the title path; code fences never split, and inline content with a heading or fence chunks as markdown. 697b13a 7a26490
- Fetched HTML turns into readable markdown before chunking. 7b47de8
- Snippets are verbatim, fence-aware and chosen by score; a snippet takes a whole neighbour fence, and typo words place it by prefix. 62ac32c de09a61
- A relevance reply holds 5 hits, and
More:pages the rest with one line per cursor. c312684 c028484 - Replies are lean when the top hit holds every query word, and smaller on small sources with no empty query blocks. c028484 0841fda
- A search over a JSON source returns whole BM25-ranked rows. 30c84f3
- A source query with no matching words lists that source's chunks by position. ce89bfc
- A stored label wins over a handle; a long label shows as handle, size and preview. a621d67
- A NUL in a query splits words and gives a normal result. eb52358
- Chunks keep a line over the small cap whole, so search returns the whole line. 6fefd96
- Search typo correction, scoped ranking and prepared statements run faster (perf). d36b505 e52388a 36ebb21
Sandbox (ctx_execute / ctx_batch)
ctx_executegives a bare reply with the whole output on exit 0, and a 4 KB preview when output is stored. 06535f1ctx_batchreplies show the exit code only when it is not zero and a pointer only when output was left out. d4c98b3- Each
ctx_batchcall answers from its own sources first, under its own labelctx_batch:<turn>:<n>. 5dd8a04 - The
mvn.cmdrewrite from #782 is back. 4fe21f7 - Every tool description starts with an exact example call; a bad call gets one line with the correct call on all hosts. b66edb3
- Server instructions and the
ctx_executedescription are shorter, so each session starts with fewer tokens (perf). c70f1e2
Hooks and routing
16 changes
- The hook never errors: all 10 hosts share one fallback decision. 6de9825
- The shell-dump deny checks every command in a chain, follows
cdand unwrapszsh -c. 9fba2c5 - The policy scans command substitutions inside
$(( )). 8e7edda - Unbounded PowerShell file dumps (
Get-Content,gc,type,[IO.File]::ReadAllText) get the same deny ascat. 765be33 - The Windows deny glob uses forward slashes and a drive-less
//anchor. 872216b - The Read deny is one line with the exact
ctx_executecall for the file. 6c9f8a3 - The main agent runs the tool, then the hook replaces large output with the best chunks. 3f4a4d0 16df63b
- The replace ranks chunks by the call's intent or the last user prompt words; with no description, intent comes from the command, path, pattern or URL. 8db7170 ae0a316
- The replace shapes output by content type, reads the whole stored Bash output, and the digest header carries counts only. 85c34f0 41eb547 ed0108c
- Non-ctx MCP results and Grep content results get the same replace; one-off categorical rows count as rare units. 90e3dce 37cc74b
- JSON output gets a digest header with the schema and numeric extremes for a named key, inside its own 256 B budget. 9433273 2ebdf84
- The replacement names the stored source by short id, size and the search call to run. 4bf03c9 c98b71a cccb08c 5e4a973 d5c1302
- The handle line adds the prompt words the output holds as a second query. 7e4d397
- Replace output stays clean at an empty body and the selection budget stops at 0. 0a4a77d fef7843
- Hook texts name tools with each host's own tool prefix on all 10 hosts. 054eb84
- The hook reads stdin as a stream in its entry. 693403b
Memory and session continuity
- The anchored state block has a decisions section. f249ef09
- Recall runs at the turn boundary after compaction. 0f1ea79
- Ledger line units build at PostToolUse and feed one ranked recall query. 83e0e8b
ctx_resumelists sources by short id and goal line units. 81be283- The MCP server uses the host session id from
CLAUDE_CODE_SESSION_ID. 5599042
Stats
ctx_statsgives a detailed text report with a short tool description. 8ebc8d4 4ca12ea- The report shows context window share, hook work, largest outputs, last 7 days cards and stacked bars. 859495b
- Rows add up, headings are scoped, blocks do not repeat, and the footer carries UTM links. 77cae47
- One
ctx_statsreply reads one database snapshot. d56aaf8 - The journal records returned bytes as the bytes the model got, after the replace decision, in the main agent and subagents. ec5c373 e18a93c
- In-process
ctx_*calls on OpenCode and Pi write the server's journal row. 80e687d
Doctor
15 changes
ctx_doctorshows an environment line, docs links and a ready agent issue report;.github/AGENT_ISSUE.mdis in the repo. 2f807ae baaa314- The report names the exact context-mode command to run. e37a961 4471e08
- The report fits 80 columns, with one docs link under the table and a wrapped
ghcommand. 88972ba ctx_doctorheals an orphan WAL and always returns its report; the report is stored whole and long echoes are named by id. 14e488e 42750b1- The version check starts git directly, names the exact cause, and compares in the bundle's channel: npm dist-tag first, git tags as fallback. 1eaec71 a65cd5a b542a67
- New checks: hook registered, hook runs, hook seen and skills. 780424c
- The hook-runs check confirms the saving effect on each host. 2e1fe50
- Doctor and setup fail when a host would run none of the installed hooks: Claude Code, Codex, Gemini CLI, Qwen Code, Pi, OpenCode, Copilot CLI, Kiro, VS Code and ZCode. 2250118 a66617d 6cd19e8 56f7284 6cba095 2600dbf 238e9c3 da5120d 807ae9a 5ef1f18
- The hook cost check covers all 10 agents, measures over bare node and runs 3 to 9 pairs, more only while over the bound. b542a67 7b68b5b 37a4804
- The hook cost check uses recorded native payloads and labels old hook errors as past. ea4179f
- The config check matches setup for Codex and MCP hosts and names setup for a missing MCP entry. 9dd4414 b542a67
- The config check accepts the quoted absolute-path hook command that setup writes. 3d8c491
- Report-only 1.x findings do not fail an agent that is set up. 9bce0b5
- Doctor verifies a native Codex plugin install and native Gemini CLI and Qwen Code extension installs; a disabled extension names the enable command. 9781e1c 518f406
- The report path prints with forward slashes on Windows. 6598e09
Setup and install
12 changes
- New
setup,doctorandupgradecommands with prompts, a report, typo hints, progress and rollback on abort. 966af39 b1d4f91 0483b1c ef8c727 - Each command has its own
--help;help <command>opens it, and output falls back to 80 columns when a terminal reports 0. 02cb17a d3638ec setup --print <agent>prints the manual step for that agent and writes nothing. 68e87b8- Setup writes the hook and skill channel for every agent. a90f47d c3eb44c
- Install docs lead with each agent's native install command, then the update, check and next steps, in short plain commands. 2e64a6b 3c0656a
- CLI help, setup and doctor output use 2.0 wording. 4b1a762
--yesworks with no terminal. e86bddc- Agent CLI install steps get 120 s, so a first run can unpack its package. feb8de1
- The hook gate takes the best of 3 rounds, so host noise does not roll back a good install. 0c9613a
- Setup finds its own hook entries by
hook.mjs --agent <id>and rewrites 1.x hook commands in flat hook files. b9b1a58 87a44c9 - Home-dir skills render from the bare-name skill dir with no doubled tool prefix. a7e3807
- The CLI, server and hook run on Node 22 and on Node below 22.3; setup reaches its report even on an EPIPE. 257a519 7b0df43 80fabdb 249f03b
Per agent
50 changes
Claude Code
- The PowerShell tool routes like Bash in PreToolUse, PostToolUse and hook matchers (#1212). f65e531
- Setup enables a disabled plugin; doctor fails on
disableAllHooks. 2250118 - Setup, doctor and plugin root honour
CLAUDE_CONFIG_DIR. 01e0654 - The project comes from
CLAUDE_PROJECT_DIR, then payload cwd, thenprocess.cwd(). 71ae2bc - The decoder names missing required fields and defaults the rest. 78de5ab
- Doctor fails on a stale plugin copy; setup and upgrade run
claude plugin updateand keep the dist-tag. 1aa584d - Setup and doctor find the real
claudepast a PATH shim and print the binary used. 37fd45c - Doctor judges the install this project uses (scope, projectPath, enabledPlugins,
CLAUDE_PLUGIN_ROOT) and reads the plugin root frominstalled_plugins.json. b353268 4653f73 - Claude Code gets its own rendered skills dir. 02e28bc
- The npm package carries
.claude-plugin/marketplace.jsonwith the owner object. 1d0c754 5c41eb6 - Uninstall deletes a marketplace root only inside the plugin cache. 58d6b74
- Claude Code never runs the Gemini hooks file under
/bin/sh. 96e3672
Codex
- Setup trusts its own plugin hooks after a native install and after
hooks/list; doctor fails on untrusted hooks with one shared check. a66617d 9508005 b93adce - The trust key handles Codex 0.166 composite hashes, an empty app-server reply, a symlinked HOME and the
codexHomespelling Codex reports. bbd7cef 4fb62aa 2f3bc32 - Setup waits up to 5 s for Codex to close after
hooks/listand ends the whole process tree. 7c72685 16a4bcc - Config, hooks, skills and doctor follow
CODEX_HOMEand the home the running plugin sits in. 952e2fc da6f91e 9e08df0 - The native plugin MCP resolves the host workspace, not the plugin cache dir. c988ff4
- The MCP entry sets
omit_tools_from = ["deferred"]anddefault_tools_approval_mode = approve, so ctx tools are direct. 056ef92 efdedf4 - Setup reads and edits any valid TOML 1.0 config. bf51198
- On Windows the hook command starts with bare node, since Codex 0.166 runs hooks in PowerShell. 135120e 31bb89d
- Plugin skills use Codex tool names; the marketplace on main points at the built plugin. d6f964f c961fda
Gemini CLI
- The row lists native tool ids, so shell and read rules reach BeforeTool. ecbe91f
- BeforeTool denies a one-file shell dump over the cap before it runs. 5aaf456
- A resume hint shows on the first BeforeAgent of a session. 831368b
- The extension carries the
extensionPathserver path andhooks/hooks.json; setup links it and never waits on stdin. 8d11ff6 8b6e4b6 - Skills render with Gemini tool names; doctor reads the extension hook file with the
${/}separator. 46a5892 8a36930 - Setup accepts the Windows exit-time crash of
gemini extensions linkwhen the extension is listed. c303961
Qwen Code
- The extension carries the
extensionPathserver path and hooks key; docs show the native extension install. 8feb0c4 c507e00 - The skills channel is the package
skills/dir with Qwen tool names. b20637f
Pi
- Pi gets the same system prompt every turn, so the prompt cache holds. e1b9821
- The out tree has a Pi-only
package.json; skills use Pi tool names. ffd762d 46a5892 - An empty
PI_CODING_AGENT_DIRcounts as unset. f98750f
OpenCode
- The OpenCode 2 native install is
opencode plugin add context-mode@next. 591197c - The plugin loads on OpenCode 2 and on the 1.19.4 loader. 2600c92 78af6be ad0e8a2 861d607
- One working plugin entry; doctor fails on a double or stale entry. 2600dbf
- The bash tool routes through the hook. 2e1fe50
- Setup lists with
--pure, followsOPENCODE_CONFIG_DIRandXDG_CONFIG_HOME, and readsopencode.jsonas JSONC. 09465cc 7ce8d4d 14710eb
Copilot CLI
- The decoder reads the documented payload with no
hookEventName. ff999dd - The own MCP tool prefix is
context-mode-; skills and deny texts name the real tool, and shared skills serve both Copilot CLI and VS Code. dcc576e 850821b b195b99 - Setup checks hooks are enabled and cleans
disabledHooks. 238e9c3 - Hooks, skills and detection follow
COPILOT_HOME. 5094c63 - Hook entries get an explicit
powershellfield, also on VS Code. 7aaaf89
Kiro
- The decoder reads camelCase tool events and the UserPromptSubmit trigger; shell matcher names follow Kiro docs. 397cc04 c507e00 1830135
- Kiro registers the shell tool
execute_bashnext to@mcp; deny text goes to stderr with exit 2. d13980c - Hooks, MCP entry, skills and detection follow
KIRO_HOME. 663aa66
VS Code
- The decoder reads the camelCase hook payload and maps every documented terminal, read and fetch tool. 16fa82b a531951
- The project comes from
--workspace-folder ${workspaceFolder}and the payload cwd;run_in_terminalis the shell. 51fd189 - The MCP entry goes to the user-profile
mcp.json; doctor reads the user hook file setup writes. 38c191e db09aee - Skills move to
~/.agents/skills. b195b99
ZCode
- Setup writes matcher groups and
mcp.servers/features.mcp; uninstall drops the nested entry. 6be8e76
Windows
13 changes
- Home is
USERPROFILEfirst on Windows andHOMEfirst elsewhere, from one helper; doctor namesUSERPROFILEwhen no home is found. 7b54a2e d6a0648 8c9d87a - File writes retry a busy rename (EPERM, EBUSY, EACCES), name the held file and clean their tmp file. d788697 31c21f7 567970c 3874f2c 49db049 ee95ebb
- Setup finds agent CLIs via PATHEXT and runs
.cmdshims throughcmd.exewith/v:off. 6fcc311 76029ea 37db76f - The shim line refuses only a
%NAME%thatcmd.exewould expand, so file URLs with%7Eor%20pass. 2c1b166 c38d4a2 - Double quotes in PATH entries are cut. 0ba3728 cf1abd1
- Every child process starts hidden. bb4045e
- Host config files with a BOM and CRLF read correctly and keep their layout and line ends on write. cf6a343 b3a3256
- The sandbox shell is Git Bash from the installed Git. 46cb4ca
- The
currentupgrade link is a junction on Windows. 941ea21 - Kiro, Copilot CLI, VS Code and Codex fixes for Windows homes and paths are in Per agent. 663aa66 5094c63 38c191e 135120e
- Store labels for path sources use forward slashes on every OS. bbee5c2
- Doctor prints the report path with forward slashes. 6598e09
- Hook start loads
node:fsthroughgetBuiltinModule, cutting Windows hook overhead (perf). 12a51f7
Store
closeDbcheckpoints in PASSIVE mode and skips the checkpoint on a read-only handle, soctx_statsandctx_searchstay fast. 45145b8 086bde8- Writable connections run
synchronous=NORMAL, so a COMMIT needs no fsync (perf). fbb923d - A reserved source row goes away when its write fails; the retention cap counts real bytes. e2a822a c56e86a
- A project dir outside any git repo is a project keyed by its realpath. d32aa0c
rankTextsruns on a one-column contentless FTS5 table with the same BM25 scores (perf). 82655e3
Performance
- The hook bundle is minified: 155 KB to 91 KB parse per call. 92f165e
- Hook start skips
fs/promises, readline, streams andnode:crypto, and loadschild_processandrandomUUIDonly when needed. b227991 4bbccb4 639da51 - The hook reads stdin and writes stdout with sync fd I/O. 6d56a48 43d1e80
resolveProjectcomputes the project key, dir and db path on first read. 7d75314- PostToolUse chunks output once and selects in memory for both sizes. dd2be18
- See also the perf lines in Search, Sandbox, Windows and Store.
Build and release
12 changes
- Releases run from main in one click: plan, npm publish, release commit and tag in one push, and a GitHub release; rollback is a forward commit. 4aab995 b3db26c 2d6ab77
- The main tree holds
plugins/claude-code, both marketplaces and root Gemini CLI and Qwen Code manifests from the packed package. a3642a3 ace68ce c961fda - Smoke tests cover the main layout, a Qwen Code leg and the native Codex commands. ebd0a74 c961fda
- A pushed release tag sets the version, prerelease versions build, and a prerelease GitHub release is not marked latest. 21d8e43 e2bee53 7894f2d 630a61c 7d37721
- The GitHub release runs after npm publish. 6136a9c c3a1ae2
- One config file lists the npm names a release publishes. 3f78ebd
- The package carries
repository.urlfor npm provenance. 496670b - The npm package ships
README.mdandLICENSEwith absolute links, and acli.mjsbin. 84f719f 68e0af5 207ba63 - Plugin manifests carry the 2.0 version and description;
package.jsonis the source of release fields with no unused deps. 322aadc 1e2f68f - Codex plugin manifests and the OpenCode package main ship in the npm package. 861d607
- The generated tool file is rewritten only when changed, through temp and rename. adc4420
- The README shows an agent table, daily npm download charts, a working star chart and daily adoption history from GitHub and npm. fef7750 d0aee2d 33775e3 45caf2e e19d949 a74baad 9f20042
Thanks
Code and docs since 1.0.169: @mksglu (Mert Köseoğlu), with release and stats commits from github-actions.
Thanks to everyone whose issue reports and tests shaped this release, among them @EvolveAegis, @fl4pj4ck, @chinkung, @artemkorolev1, @rrva, @alove20, @isoux35, @Shodocan, @igorggor, @yuanminze, @wasikarn, @aliyzl, @sjoerd2025, @Lunasciel, @taonos, @flowq-C, @ftonioloviemar, @hshindys, @hilman2, @chelebyy, @DnaMes, @VinayPolisetti, @jeanmonet, @madonoharu, @eli-pritykin, @marcusyoung, @patroc, @daniel-vincent-veriforce, @HectorBernstorff, @nwilliams-lucas, @ryanstempski-cmyk, @kewtyboi, @matkatmusic, @Tomodad, @zer09, @JimCline, @michael-partoo, @nufiko, @asherepenko, @RGalli, @hiddenadhd, @cidoferruco, @CatcherITGF, @riddlex-beep, @HaleTom, @tomerikjansen-crypto, @monossido, @wotjr1649, @finnvyrn, @sdkkds, @chrisjenx, @LukeSal88, @Kirchlive, @devcode4510-code, @MarshalCurrier, @raremalo, @jetnet, @2slowDD, @jasonwujch, @dashanlkk, @SkipXS, @PhiWett, @ccheng555, @zkzi3254, @alaa-nassef, @se7enango, @benzntech, @vigo, @liby and @hasandenizuk, and to the testers who ran each 2.0 preview build.