
Research
/Security News
CanisterWorm: npm Publisher Compromise Deploys Backdoor Across 29+ Packages
The worm-enabled campaign hit @emilgroup and @teale.io, then used an ICP canister to deliver follow-on payloads.
context-mode
Advanced tools
MCP plugin that saves 98% of your context window. Works with Claude Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI. Sandboxed code execution, FTS5 knowledge base, and intent-driven search.
The other half of the context problem.
Context Mode is not a CLI output filter or a cloud analytics dashboard. It operates at the MCP protocol layer — raw data stays in a sandboxed subprocess and never enters your context window. Web pages, API responses, file analysis, Playwright snapshots, log files — everything is processed in complete isolation.
Nothing leaves your machine. No telemetry, no cloud sync, no usage tracking, no account required. Your code, your prompts, your session data — all local. The SQLite databases live in your home directory and die when you're done.
This is a deliberate architectural choice, not a missing feature. Context optimization should happen at the source, not in a dashboard behind a per-seat subscription. Privacy-first is our philosophy — and every design decision follows from it. License →
Every MCP tool call dumps raw data into your context window. A Playwright snapshot costs 56 KB. Twenty GitHub issues cost 59 KB. One access log — 45 KB. After 30 minutes, 40% of your context is gone. And when the agent compacts the conversation to free space, it forgets which files it was editing, what tasks are in progress, and what you last asked for.
Context Mode is an MCP server that solves both halves of this problem:
--continue, previous session data is deleted immediately — a fresh session means a clean slate.https://github.com/user-attachments/assets/07013dbf-07c0-4ef1-974a-33ea1207637b
Platforms are grouped by install complexity. Hook-capable platforms get automatic routing enforcement. Non-hook platforms need a one-time routing file copy.
Prerequisites: Claude Code v1.0.33+ (claude --version). If /plugin is not recognized, update first: brew upgrade claude-code or npm update -g @anthropic-ai/claude-code.
Install:
/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-mode
Restart Claude Code (or run /reload-plugins).
Verify:
/context-mode:ctx-doctor
All checks should show [x]. The doctor validates runtimes, hooks, FTS5, and plugin registration.
Routing: Automatic. The SessionStart hook injects routing instructions at runtime — no file is written to your project. The plugin registers all hooks (PreToolUse, PostToolUse, PreCompact, SessionStart) and 6 sandbox tools (ctx_batch_execute, ctx_execute, ctx_execute_file, ctx_index, ctx_search, ctx_fetch_and_index).
| Slash Command | What it does |
|---|---|
/context-mode:ctx-stats | Context savings — per-tool breakdown, tokens consumed, savings ratio. |
/context-mode:ctx-doctor | Diagnostics — runtimes, hooks, FTS5, plugin registration, versions. |
/context-mode:ctx-upgrade | Pull latest, rebuild, migrate cache, fix hooks. |
Note: Slash commands are a Claude Code plugin feature. On other platforms, type
ctx stats,ctx doctor, orctx upgradein the chat — the model calls the MCP tool automatically. See Utility Commands.
claude mcp add context-mode -- npx -y context-mode
This gives you the 6 sandbox tools without automatic routing. The model can still use them — it just won't be nudged to prefer them over raw Bash/Read/WebFetch. Good for trying it out before committing to the full plugin.
Prerequisites: Node.js 18+, Gemini CLI installed.
Install:
Install context-mode globally:
npm install -g context-mode
Add the following to ~/.gemini/settings.json. This single file registers the MCP server and all four hooks:
{
"mcpServers": {
"context-mode": {
"command": "context-mode"
}
},
"hooks": {
"BeforeTool": [
{
"matcher": "run_shell_command|read_file|read_many_files|grep_search|search_file_content|web_fetch|activate_skill|mcp__plugin_context-mode",
"hooks": [{ "type": "command", "command": "context-mode hook gemini-cli beforetool" }]
}
],
"AfterTool": [
{
"matcher": "",
"hooks": [{ "type": "command", "command": "context-mode hook gemini-cli aftertool" }]
}
],
"PreCompress": [
{
"matcher": "",
"hooks": [{ "type": "command", "command": "context-mode hook gemini-cli precompress" }]
}
],
"SessionStart": [
{
"matcher": "",
"hooks": [{ "type": "command", "command": "context-mode hook gemini-cli sessionstart" }]
}
]
}
}
Restart Gemini CLI.
Verify:
/mcp list
You should see context-mode: ... - Connected.
Routing: Automatic. The SessionStart hook injects routing instructions at runtime — no GEMINI.md file is written to your project. All four hooks (BeforeTool, AfterTool, PreCompress, SessionStart) handle enforcement programmatically.
Why the BeforeTool matcher? It targets only tools that produce large output (
run_shell_command,read_file,read_many_files,grep_search,search_file_content,web_fetch,activate_skill) plus context-mode's own tools (mcp__plugin_context-mode). This avoids unnecessary hook overhead on lightweight tools while intercepting every tool that could flood your context window.
Full config reference: configs/gemini-cli/settings.json
Prerequisites: Node.js 18+, VS Code with Copilot Chat v0.32+.
Install:
Install context-mode globally:
npm install -g context-mode
Create .vscode/mcp.json in your project root:
{
"servers": {
"context-mode": {
"command": "context-mode"
}
}
}
Create .github/hooks/context-mode.json:
{
"hooks": {
"PreToolUse": [
{ "type": "command", "command": "context-mode hook vscode-copilot pretooluse" }
],
"PostToolUse": [
{ "type": "command", "command": "context-mode hook vscode-copilot posttooluse" }
],
"SessionStart": [
{ "type": "command", "command": "context-mode hook vscode-copilot sessionstart" }
]
}
}
Restart VS Code.
Verify: Open Copilot Chat and type ctx stats. Context-mode tools should appear and respond.
Routing: Automatic. The SessionStart hook injects routing instructions at runtime — no copilot-instructions.md file is written to your project.
Full hook config including PreCompact: configs/vscode-copilot/hooks.json
Prerequisites: Node.js 18+, Cursor with agent mode.
Install:
Install context-mode globally:
npm install -g context-mode
Create .cursor/mcp.json in your project root (or ~/.cursor/mcp.json for global):
{
"mcpServers": {
"context-mode": {
"command": "context-mode"
}
}
}
Create .cursor/hooks.json (or ~/.cursor/hooks.json for global):
{
"version": 1,
"hooks": {
"preToolUse": [
{
"command": "context-mode hook cursor pretooluse",
"matcher": "Shell|Read|Grep|WebFetch|Task|MCP:ctx_execute|MCP:ctx_execute_file|MCP:ctx_batch_execute"
}
],
"postToolUse": [
{
"command": "context-mode hook cursor posttooluse"
}
]
}
}
The preToolUse matcher is optional — without it, the hook fires on all tools.
Copy the routing rules file. Cursor lacks a SessionStart hook, so the model needs a rules file for routing awareness:
mkdir -p .cursor/rules
cp node_modules/context-mode/configs/cursor/context-mode.mdc .cursor/rules/context-mode.mdc
Restart Cursor or open a new agent session.
Verify: Open Cursor Settings > MCP and confirm "context-mode" shows as connected. In agent chat, type ctx stats.
Routing: Hooks enforce routing programmatically via preToolUse/postToolUse. The .cursor/rules/context-mode.mdc file provides routing instructions at session start since Cursor's sessionStart hook is currently rejected by their validator (forum report). Project .cursor/hooks.json overrides ~/.cursor/hooks.json.
Full configs: configs/cursor/hooks.json | configs/cursor/mcp.json | configs/cursor/context-mode.mdc
Prerequisites: Node.js 18+, OpenCode installed.
Install:
Install context-mode globally:
npm install -g context-mode
Add to opencode.json in your project root (or ~/.config/opencode/opencode.json for global):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"context-mode": {
"type": "local",
"command": ["context-mode"]
}
},
"plugin": ["context-mode"]
}
The mcp entry registers the 6 sandbox tools. The plugin entry enables hooks — OpenCode calls the plugin's TypeScript functions directly before and after each tool execution, blocking dangerous commands and enforcing sandbox routing.
Restart OpenCode.
Verify: In the OpenCode session, type ctx stats. Context-mode tools should appear and respond.
Routing: Automatic. The plugin intercepts tool calls at runtime via tool.execute.before and tool.execute.after. No routing file is written to your project. The experimental.session.compacting hook builds resume snapshots when the conversation compacts.
Note: OpenCode's SessionStart hook is not yet available (#14808), so startup/resume session restore is not supported. Compaction recovery works fully via the plugin.
Full config: configs/opencode/opencode.json
Prerequisites: OpenClaw gateway running (>2026.1.29), Node.js 22+.
context-mode runs as a native OpenClaw gateway plugin, targeting Pi Agent sessions (Read/Write/Edit/Bash tools). Unlike other platforms, there's no separate MCP server — the plugin registers directly into the gateway runtime via OpenClaw's plugin API.
Install:
Clone and install:
git clone https://github.com/mksglu/context-mode.git
cd context-mode
npm run install:openclaw
The installer uses $OPENCLAW_STATE_DIR from your environment (default: /openclaw). To specify a custom path:
npm run install:openclaw -- /path/to/openclaw-state
Common locations: Docker — /openclaw (the default). Local — ~/.openclaw or wherever you set OPENCLAW_STATE_DIR.
The installer handles everything: npm install, npm run build, better-sqlite3 native rebuild, extension registration in runtime.json, and gateway restart via SIGUSR1.
Open a Pi Agent session.
Verify: The plugin registers 8 hooks via api.on() (lifecycle) and api.registerHook() (commands). Type ctx stats to confirm tools are loaded.
Routing: Automatic. All tool interception, session tracking, and compaction recovery hooks activate automatically — no manual hook configuration or routing file needed.
Minimum version: OpenClaw >2026.1.29 — this includes the
api.on()lifecycle fix from PR #9761. On older versions, lifecycle hooks silently fail. The adapter falls back to DB snapshot reconstruction (less precise but preserves critical state).
Full documentation: docs/adapters/openclaw.md
Prerequisites: Node.js 18+, Codex CLI installed.
Install:
Install context-mode globally:
npm install -g context-mode
Add to ~/.codex/config.toml:
[mcp_servers.context-mode]
command = "context-mode"
Copy routing instructions (Codex CLI has no hook support):
cp node_modules/context-mode/configs/codex/AGENTS.md ./AGENTS.md
For global use: cp node_modules/context-mode/configs/codex/AGENTS.md ~/.codex/AGENTS.md. Global applies to all projects. If both exist, Codex CLI merges them.
Restart Codex CLI.
Verify: Start a session and type ctx stats. Context-mode tools should appear and respond.
Routing: Manual. The AGENTS.md file is the only enforcement method (~60% compliance). There is no programmatic interception — the model can run raw curl, read large files, or bypass sandbox tools at any time. Hook support PRs #2904 and #9796 were closed without merge.
Prerequisites: Node.js 18+, Antigravity installed.
Install:
Install context-mode globally:
npm install -g context-mode
Add to ~/.gemini/antigravity/mcp_config.json:
{
"mcpServers": {
"context-mode": {
"command": "context-mode"
}
}
}
Copy routing instructions (Antigravity has no hook support):
cp node_modules/context-mode/configs/antigravity/GEMINI.md ./GEMINI.md
Restart Antigravity.
Verify: In an Antigravity session, type ctx stats. Context-mode tools should appear and respond.
Routing: Manual. The GEMINI.md file is the only enforcement method (~60% compliance). There is no programmatic interception. Auto-detected via MCP protocol handshake (clientInfo.name) — no manual platform configuration needed.
Full configs: configs/antigravity/mcp_config.json | configs/antigravity/GEMINI.md
Prerequisites: Node.js 18+, Kiro with MCP enabled (Settings > search "MCP").
Install:
Install context-mode globally:
npm install -g context-mode
Add to .kiro/settings/mcp.json in your project (or ~/.kiro/settings/mcp.json for global):
{
"mcpServers": {
"context-mode": {
"command": "context-mode"
}
}
}
Create .kiro/hooks/context-mode.json:
{
"name": "context-mode",
"description": "Context-mode hooks for context window protection",
"hooks": {
"preToolUse": [
{ "matcher": "*", "command": "context-mode hook kiro pretooluse" }
],
"postToolUse": [
{ "matcher": "*", "command": "context-mode hook kiro posttooluse" }
]
}
}
Copy routing instructions. Kiro's agentSpawn (SessionStart) is not yet implemented, so the model needs a routing file at session start:
cp node_modules/context-mode/configs/kiro/KIRO.md ./KIRO.md
Restart Kiro.
Verify: Open the Kiro panel > MCP Servers tab and confirm "context-mode" shows a green status indicator. In chat, type ctx stats.
Routing: Hooks enforce routing programmatically via preToolUse/postToolUse. The KIRO.md file provides routing instructions since agentSpawn (SessionStart equivalent) is not yet wired. Tool names appear as @context-mode/ctx_batch_execute, @context-mode/ctx_search, etc. Auto-detected via MCP protocol handshake.
Full configs: configs/kiro/mcp.json | configs/kiro/agent.json | configs/kiro/KIRO.md
Prerequisites: Node.js 18+, Zed installed.
Install:
Install context-mode globally:
npm install -g context-mode
Add to ~/.config/zed/settings.json (Windows: %APPDATA%\Zed\settings.json):
{
"context_servers": {
"context-mode": {
"command": {
"path": "context-mode"
}
}
}
}
Note: Zed uses "context_servers" and "command": { "path": "..." } syntax, not "mcpServers" or "command": "..." like other platforms.
Copy routing instructions (Zed has no hook support):
cp node_modules/context-mode/configs/zed/AGENTS.md ./AGENTS.md
Restart Zed (or save settings.json — Zed auto-restarts context servers on config change).
Verify: Open the Agent Panel (Cmd+Shift+A), go to settings, and check the indicator dot next to "context-mode" — green means active. Type ctx stats in the agent chat.
Routing: Manual. The AGENTS.md file is the only enforcement method (~60% compliance). There is no programmatic interception. Tool names appear as mcp:context-mode:ctx_batch_execute, mcp:context-mode:ctx_search, etc. Auto-detected via MCP protocol handshake.
Prerequisites: Node.js 18+, Pi Coding Agent installed.
Install:
Clone the extension:
git clone https://github.com/mksglu/context-mode.git ~/.pi/extensions/context-mode
cd ~/.pi/extensions/context-mode
npm install
Add to ~/.pi/settings/mcp.json (or .pi/settings/mcp.json for project-level):
{
"mcpServers": {
"context-mode": {
"command": "node",
"args": ["~/.pi/extensions/context-mode/node_modules/context-mode/start.mjs"]
}
}
}
Restart Pi.
Verify: In a Pi session, type ctx stats. Context-mode tools should appear and respond.
Routing: Automatic. The extension registers all key lifecycle events (tool_call, tool_result, session_start, session_before_compact), providing full session continuity and routing enforcement.
Context Mode uses better-sqlite3 on Node.js, which ships prebuilt native binaries for most platforms. On glibc >= 2.31 systems (Ubuntu 20.04+, Debian 11+, Fedora 34+, macOS, Windows), npm install works without any build tools.
Bun users: No native compilation needed. Context Mode automatically detects Bun and uses the built-in bun:sqlite module via a compatibility adapter. better-sqlite3 and all its build dependencies are skipped entirely.
On older glibc systems (CentOS 7/8, RHEL 8, Debian 10), prebuilt binaries don't load and better-sqlite3 automatically falls back to compiling from source via prebuild-install || node-gyp rebuild --release. This requires a C++20 compiler (GCC 10+), Make, and Python with setuptools.
CentOS 8 / RHEL 8 (glibc 2.28):
dnf install -y gcc-toolset-10-gcc gcc-toolset-10-gcc-c++ make python3 python3-setuptools
scl enable gcc-toolset-10 'npm install -g context-mode'
CentOS 7 / RHEL 7 (glibc 2.17):
yum install -y centos-release-scl
yum install -y devtoolset-10-gcc devtoolset-10-gcc-c++ make python3
pip3 install setuptools
scl enable devtoolset-10 'npm install -g context-mode'
Alpine Linux:
Alpine prebuilt binaries (musl) are available in better-sqlite3 v12.8.0+. With the ^12.6.2 dependency range, npm install resolves to the latest 12.x and works without build tools on Alpine. If you pin an older version:
apk add build-base python3 py3-setuptools
npm install -g context-mode
| Tool | What it does | Context saved |
|---|---|---|
ctx_batch_execute | Run multiple commands + search multiple queries in ONE call. | 986 KB → 62 KB |
ctx_execute | Run code in 11 languages. Only stdout enters context. | 56 KB → 299 B |
ctx_execute_file | Process files in sandbox. Raw content never leaves. | 45 KB → 155 B |
ctx_index | Chunk markdown into FTS5 with BM25 ranking. | 60 KB → 40 B |
ctx_search | Query indexed content with multiple queries in one call. | On-demand retrieval |
ctx_fetch_and_index | Fetch URL, detect content type (HTML/JSON/text), chunk and index. | 60 KB → 40 B |
ctx_stats | Show context savings, call counts, and session statistics. | — |
ctx_doctor | Diagnose installation: runtimes, hooks, FTS5, versions. | — |
ctx_upgrade | Upgrade to latest version from GitHub, rebuild, reconfigure hooks. | — |
Each ctx_execute call spawns an isolated subprocess with its own process boundary. Scripts can't access each other's memory or state. The subprocess runs your code, captures stdout, and only that stdout enters the conversation context. The raw data — log files, API responses, snapshots — never leaves the sandbox.
Eleven language runtimes are available: JavaScript, TypeScript, Python, Shell, Ruby, Go, Rust, PHP, Perl, R, and Elixir. Bun is auto-detected for 3-5x faster JS/TS execution.
Authenticated CLIs work through credential passthrough — gh, aws, gcloud, kubectl, docker inherit environment variables and config paths without exposing them to the conversation.
When output exceeds 5 KB and an intent is provided, Context Mode switches to intent-driven filtering: it indexes the full output into the knowledge base, searches for sections matching your intent, and returns only the relevant matches with a vocabulary of searchable terms for follow-up queries.
The ctx_index tool chunks markdown content by headings while keeping code blocks intact, then stores them in a SQLite FTS5 (Full-Text Search 5) virtual table. Search uses BM25 ranking — a probabilistic relevance algorithm that scores documents based on term frequency, inverse document frequency, and document length normalization. Porter stemming is applied at index time so "running", "runs", and "ran" match the same stem. Titles and headings are weighted 5x in BM25 scoring for precise navigational queries.
When you call ctx_search, it returns relevant content snippets focused around matching query terms — not full documents, not approximations, the actual indexed content with smart extraction around what you're looking for. ctx_fetch_and_index extends this to URLs: fetch, convert HTML to markdown, chunk, index. The raw page never enters context. Use the contentType parameter to filter results by type (e.g. code or prose).
Search runs two parallel strategies and merges them with Reciprocal Rank Fusion (RRF):
RRF merges both ranked lists into a single result set, so a document that ranks well in both strategies surfaces higher than one that ranks well in only one. This replaces the old cascading fallback approach where trigram results were only used if porter returned nothing.
Multi-term queries get an additional reranking pass. Results where query terms appear close together are boosted — "session continuity" ranks passages with adjacent terms higher than pages where "session" and "continuity" appear paragraphs apart.
Levenshtein distance corrects typos before re-searching. "kuberntes" becomes "kubernetes", "autentication" becomes "authentication".
Search results use intelligent extraction instead of truncation. Instead of returning the first N characters (which might miss the important part), Context Mode finds where your query terms appear in the content and returns windows around those matches.
ctx_batch_executeWhen the context window fills up, the agent compacts the conversation — dropping older messages to make room. Without session tracking, the model forgets which files it was editing, what tasks are in progress, what errors were resolved, and what you last asked for.
Context Mode captures every meaningful event during your session and persists them in a per-project SQLite database. When the conversation compacts (or you resume with --continue), your working state is rebuilt automatically — the model continues from your last prompt without asking you to repeat anything.
Session continuity requires 4 hooks working together:
| Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PostToolUse | Captures events after each tool call | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | ✓ (via tool_result event) |
| UserPromptSubmit | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
| PreCompact | Builds snapshot before compaction | Yes | Yes | Yes | -- | Plugin | Plugin | -- | -- | -- | -- | ✓ (via session_before_compact) |
| SessionStart | Restores state after compaction or resume | Yes | Yes | Yes | -- | -- | Plugin | -- | -- | -- | -- | ✓ (via session_start event) |
| Session completeness | Full | High | High | Partial | High | High | -- | -- | Partial | -- | High |
Note: Full session continuity (capture + snapshot + restore) works on Claude Code, Gemini CLI, VS Code Copilot, and OpenCode. Cursor captures tool events via
preToolUse/postToolUse, butsessionStartis currently rejected by Cursor's validator (forum report), so session restore after compaction is not available yet. OpenCode uses theexperimental.session.compactingplugin hook for compaction recovery, but SessionStart is not yet available (#14808), so startup/resume is not supported. OpenClaw uses native gateway plugin hooks (api.on()) for full session continuity. Pi Coding Agent provides high session continuity via extension hooks (tool_call,tool_result,session_start,session_before_compact). Codex CLI, Antigravity, Kiro, and Zed have no hook support in the current release, so session tracking is not available.
Every tool call passes through hooks that extract structured events:
| Category | Events | Priority | Captured By |
|---|---|---|---|
| Files | read, edit, write, glob, grep | Critical (P1) | PostToolUse |
| Tasks | create, update, complete | Critical (P1) | PostToolUse |
| Rules | CLAUDE.md / GEMINI.md / AGENTS.md paths + content | Critical (P1) | SessionStart |
| Decisions | User corrections, preferences ("use X instead", "don't do Y") | High (P2) | UserPromptSubmit |
| Git | checkout, commit, merge, rebase, stash, push, pull, diff, status | High (P2) | PostToolUse |
| Errors | Tool failures, non-zero exit codes | High (P2) | PostToolUse |
| Environment | cwd changes, venv, nvm, conda, package installs | High (P2) | PostToolUse |
| MCP Tools | All mcp__* tool calls with usage counts | Normal (P3) | PostToolUse |
| Subagents | Agent tool invocations | Normal (P3) | PostToolUse |
| Skills | Slash command invocations | Normal (P3) | PostToolUse |
| Role | Persona / behavioral directives ("act as senior engineer") | Normal (P3) | UserPromptSubmit |
| Intent | Session mode classification (investigate, implement, debug) | Low (P4) | UserPromptSubmit |
| Data | Large user-pasted data references (>1 KB) | Low (P4) | UserPromptSubmit |
| User Prompts | Every user message (for last-prompt restore) | Critical (P1) | UserPromptSubmit |
PreCompact fires
→ Read all session events from SQLite
→ Build priority-tiered XML snapshot (≤2 KB)
→ Store snapshot in session_resume table
SessionStart fires (source: "compact")
→ Retrieve stored snapshot
→ Write structured events file → auto-indexed into FTS5
→ Build Session Guide with 15 categories
→ Inject <session_knowledge> directive into context
→ Model continues from last user prompt with full working state
The snapshot is built in priority tiers — if the 2 KB budget is tight, lower-priority events (intent, MCP tool counts) are dropped first while critical state (active files, tasks, rules, decisions) is always preserved.
After compaction, the model receives a Session Guide — a structured narrative with actionable sections:
[x] completed, [ ] pending)Detailed event data is also indexed into FTS5 for on-demand retrieval via search().
Claude Code — Full session support. All 5 hook types fire, capturing tool events, user decisions, building compaction snapshots, and restoring state after compaction or --continue.
Gemini CLI — High coverage. PostToolUse (AfterTool), PreCompact (PreCompress), and SessionStart all fire. Missing UserPromptSubmit, so user decisions and corrections aren't captured — but file edits, git ops, errors, and tasks are fully tracked.
VS Code Copilot — High coverage. Same as Gemini CLI — PostToolUse, PreCompact, and SessionStart all fire. User decisions aren't captured but all tool-level events are.
Cursor — Partial coverage. Native preToolUse and postToolUse hooks capture tool events. sessionStart is documented by Cursor but currently rejected by their validator, so session restore is not available. Routing instructions are delivered via MCP server startup instead.
OpenCode — Partial. The TypeScript plugin captures PostToolUse events via tool.execute.after, but SessionStart is not yet available (#14808). Events are stored but not automatically restored after compaction.
OpenClaw / Pi Agent — High coverage. All tool lifecycle hooks (after_tool_call, before_compaction, session_start) fire via the native gateway plugin. User decisions aren't captured but file edits, git ops, errors, and tasks are fully tracked. Falls back to DB snapshot reconstruction if compaction hooks fail on older gateway versions. See docs/adapters/openclaw.md.
Codex CLI — No session support. No hooks means no event capture. Each compaction or new session starts fresh. Requires manually copying AGENTS.md to your project root.
Antigravity — No session support. Same as Codex CLI — no hooks, no event capture. Requires manually copying GEMINI.md to your project root. Auto-detected via MCP protocol handshake (clientInfo.name).
Zed — No session support. Same as Codex CLI — no hooks, no event capture. Requires manually copying AGENTS.md to your project root. Auto-detected via MCP protocol handshake (clientInfo.name).
Kiro — Partial coverage. Native preToolUse and postToolUse hooks capture tool events and enforce sandbox routing. agentSpawn (the Kiro equivalent of SessionStart) is not yet implemented, so session restore after compaction is not available. Requires manually copying KIRO.md to your project root. Auto-detected via MCP protocol handshake (clientInfo.name).
Pi Coding Agent — High coverage. The extension registers all key lifecycle events: tool_call (PreToolUse), tool_result (PostToolUse), session_start (SessionStart), and session_before_compact (PreCompact). File edits, git ops, errors, and tasks are fully tracked. Session restore after compaction works via the extension's event hooks.
| Feature | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
|---|---|---|---|---|---|---|---|---|---|---|---|
| MCP Server | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| PreToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | Yes (extension) |
| PostToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | Yes (extension) |
| SessionStart Hook | Yes | Yes | Yes | -- | -- | Plugin | -- | -- | -- | -- | Yes (extension) |
| PreCompact Hook | Yes | Yes | Yes | -- | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
| Can Modify Args | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
| Can Block Tools | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | Yes (extension) |
| Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes (/ctx-stats, /ctx-doctor) |
| Slash Commands | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
| Plugin Marketplace | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
OpenCode uses a TypeScript plugin paradigm — hooks run as in-process functions via
tool.execute.before,tool.execute.after, andexperimental.session.compacting, providing the same routing enforcement and session continuity as shell-based hooks. SessionStart is not yet available (#14808), but compaction recovery works via the plugin's compacting hook.OpenClaw runs context-mode as a native gateway plugin targeting Pi Agent sessions. Hooks register via
api.on()(tool/lifecycle) andapi.registerHook()(commands). All tool interception and compaction hooks are supported. Seedocs/adapters/openclaw.md.Codex CLI, Antigravity, and Zed do not support hooks. They rely solely on manually-copied routing instruction files (
AGENTS.md/GEMINI.md) for enforcement (~60% compliance). See each platform's install section for copy instructions. Antigravity and Zed are auto-detected via MCP protocol handshake — no manual platform configuration needed.Kiro supports native
preToolUseandpostToolUsehooks for routing enforcement and tool event capture.agentSpawn(SessionStart equivalent) andstopare not yet wired. Requires manually copyingKIRO.mdto your project root. Kiro is auto-detected via MCP protocol handshake (clientInfo.name).Pi Coding Agent runs context-mode as an extension with full hook support. The extension registers
tool_call,tool_result,session_start, andsession_before_compactevents, providing high session continuity coverage. The MCP server provides the 6 sandbox tools.
Hooks intercept tool calls programmatically — they can block dangerous commands and redirect them to the sandbox before execution. Instruction files guide the model via prompt instructions but cannot block anything. Always enable hooks where supported.
Note: Routing instruction files were previously auto-written to project directories on first session start. This was disabled to prevent git tree pollution (#158, #164). Hook-capable platforms (Claude Code, Gemini CLI, VS Code Copilot, OpenCode, OpenClaw) inject routing via hooks and need no file. Non-hook platforms (Codex, Zed, Cursor, Kiro, Antigravity) require a one-time manual copy — see each platform's install section.
| Platform | Hooks | Instruction File | With Hooks | Without Hooks |
|---|---|---|---|---|
| Claude Code | Yes (auto) | CLAUDE.md | ~98% saved | ~60% saved |
| Gemini CLI | Yes | GEMINI.md | ~98% saved | ~60% saved |
| VS Code Copilot | Yes | copilot-instructions.md | ~98% saved | ~60% saved |
| Cursor | Yes | context-mode.mdc | ~98% saved | ~60% saved |
| OpenCode | Plugin | AGENTS.md | ~98% saved | ~60% saved |
| OpenClaw | Plugin | AGENTS.md | ~98% saved | ~60% saved |
| Codex CLI | -- | AGENTS.md | -- | ~60% saved |
| Antigravity | -- | GEMINI.md | -- | ~60% saved |
| Kiro | Yes | KIRO.md | ~98% saved | ~60% saved |
| Zed | -- | AGENTS.md | -- | ~60% saved |
| Pi | ✓ | AGENTS.md | ~98% saved | ~60% saved |
Without hooks, one unrouted curl or Playwright snapshot can dump 56 KB into context — wiping out an entire session's worth of savings.
See docs/platform-support.md for the full capability comparison.
Inside any AI session — just type the command. The LLM calls the MCP tool automatically:
ctx stats → context savings, call counts, session report
ctx doctor → diagnose runtimes, hooks, FTS5, versions
ctx upgrade → update from GitHub, rebuild, reconfigure hooks
From your terminal — run directly without an AI session:
context-mode doctor
context-mode upgrade
Works on all platforms. On Claude Code, slash commands (/ctx-stats, /ctx-doctor, /ctx-upgrade) are also available.
| Scenario | Raw | Context | Saved |
|---|---|---|---|
| Playwright snapshot | 56.2 KB | 299 B | 99% |
| GitHub Issues (20) | 58.9 KB | 1.1 KB | 98% |
| Access log (500 requests) | 45.1 KB | 155 B | 100% |
| Context7 React docs | 5.9 KB | 261 B | 96% |
| Analytics CSV (500 rows) | 85.5 KB | 222 B | 100% |
| Git log (153 commits) | 11.6 KB | 107 B | 99% |
| Test output (30 suites) | 6.0 KB | 337 B | 95% |
| Repo research (subagent) | 986 KB | 62 KB | 94% |
Over a full session: 315 KB of raw output becomes 5.4 KB. Session time extends from ~30 minutes to ~3 hours.
Full benchmark data with 21 scenarios →
These prompts work out of the box. Run /context-mode:ctx-stats after each to see the savings.
Deep repo research — 5 calls, 62 KB context (raw: 986 KB, 94% saved)
Research https://github.com/modelcontextprotocol/servers — architecture, tech stack,
top contributors, open issues, and recent activity. Then run /context-mode:ctx-stats.
Git history analysis — 1 call, 5.6 KB context
Clone https://github.com/facebook/react and analyze the last 500 commits:
top contributors, commit frequency by month, and most changed files.
Then run /context-mode:ctx-stats.
Web scraping — 1 call, 3.2 KB context
Fetch the Hacker News front page, extract all posts with titles, scores,
and domains. Group by domain. Then run /context-mode:ctx-stats.
Large JSON API — 7.5 MB raw → 0.9 KB context (99% saved)
Create a local server that returns a 7.5 MB JSON with 20,000 records and a secret
hidden at index 13000. Fetch the endpoint, find the hidden record, and show me
exactly what's in it. Then run /context-mode:ctx-stats.
Documentation search — 2 calls, 1.8 KB context
Fetch the React useEffect docs, index them, and find the cleanup pattern
with code examples. Then run /context-mode:ctx-stats.
Session continuity — compaction recovery with full state
Start a multi-step task: "Create a REST API with Express — add routes, tests,
and error handling." After 20+ tool calls, type: ctx stats to see the session
event count. When context compacts, the model continues from your last prompt
with tasks, files, and decisions intact — no re-prompting needed.
Context Mode enforces the same permission rules you already use — but extends them to the MCP sandbox. If you block sudo, it's also blocked inside ctx_execute, ctx_execute_file, and ctx_batch_execute.
Zero setup required. If you haven't configured any permissions, nothing changes. This only activates when you add rules.
{
"permissions": {
"deny": [
"Bash(sudo *)",
"Bash(rm -rf /*)",
"Read(.env)",
"Read(**/.env*)"
],
"allow": [
"Bash(git:*)",
"Bash(npm:*)"
]
}
}
Add this to your project's .claude/settings.json (or ~/.claude/settings.json for global rules). All platforms read security policies from Claude Code's settings format — even on Gemini CLI, VS Code Copilot, and OpenCode. Codex CLI has no hook support, so security enforcement is not available.
The pattern is Tool(what to match) where * means "anything".
Commands chained with &&, ;, or | are split — each part is checked separately. echo hello && sudo rm -rf /tmp is blocked because the sudo part matches the deny rule.
deny always wins over allow. More specific (project-level) rules override global ones.
See CONTRIBUTING.md for the development workflow and TDD guidelines.
git clone https://github.com/mksglu/context-mode.git
cd context-mode && npm install && npm test
Licensed under Elastic License 2.0 (source-available). You can use it, fork it, modify it, and distribute it. Two things you can't do: offer it as a hosted/managed service, or remove the licensing notices. We chose ELv2 over MIT because MIT permits repackaging the code as a competing closed-source SaaS — ELv2 prevents that while keeping the source available to everyone.
FAQs
MCP plugin that saves 98% of your context window. Works with Claude Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI. Sandboxed code execution, FTS5 knowledge base, and intent-driven search.
The npm package context-mode receives a total of 5,897 weekly downloads. As such, context-mode popularity was classified as popular.
We found that context-mode demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
The worm-enabled campaign hit @emilgroup and @teale.io, then used an ICP canister to deliver follow-on payloads.

Research
/Security News
Attackers compromised Trivy GitHub Actions by force-updating tags to deliver malware, exposing CI/CD secrets across affected pipelines.

Security News
ENISA’s new package manager advisory outlines the dependency security practices companies will need to demonstrate as the EU’s Cyber Resilience Act begins enforcing software supply chain requirements.