Your Claude sessions degrade as context fills up. context-mode sandboxes raw output,
compresses what comes back with a self-learning pipeline, and routes tools automatically
— so Claude stays sharp for the entire conversation. 30–60% less context consumed in typical sessions, more in research-heavy ones.
Run ctx_stats to see your savings in tokens and dollars.
npx --yes --package=github:scottconverse/context-mode context-mode
/plugin marketplace add scottconverse/context-mode
/plugin install context-mode@scottconverse-context-mode
Run code in isolated subprocesses. Only stdout returns to context. Raw file contents, command output, and web pages never bloat your context window. Supports JavaScript, TypeScript, Python, Shell, Ruby, Go, Rust, PHP, Perl, R, and Elixir.
3-stage pipeline: deterministic ANSI stripping, pattern-based matchers for 10 tool formats (jest, pytest, git log, cargo build, etc.), and session-aware relevance filtering. Passing tests collapse to counts. Compile steps summarize. Errors and failures are always preserved verbatim.
A feedback loop tracks what compressed content Claude later retrieves. High retrieval rates raise retention; low rates increase compression. Learner accuracy, lifetime token savings, and estimated cost savings (Opus/Sonnet/Haiku) are all visible in ctx_stats.
Index documents into a local SQLite FTS5 database with BM25 ranking, trigram matching, and Reciprocal Rank Fusion. Search returns only relevant snippets. Fuzzy correction handles typos. 24-hour TTL cache for web pages.
Hooks capture file operations, git commands, errors, tasks, and decisions into SQLite. Before context compaction, a priority-tiered XML snapshot (under 2KB) preserves what matters. Claude resumes from exactly where it left off.
PreToolUse hooks intercept Bash, Read, Grep, WebFetch, and Agent calls. 23 matchers cover git, npm, pytest, cargo, docker, make, curl/wget, and more. Large-output commands redirect through the compression pipeline automatically.
| Tool | Purpose |
|---|---|
ctx_execute | Run code in a sandboxed subprocess (11 languages) |
ctx_execute_file | Process files through sandbox — raw content stays out of context |
ctx_batch_execute | Multiple commands + searches in one call |
ctx_index | Index text/markdown/JSON into the knowledge base |
ctx_search | BM25 + trigram search with RRF fusion |
ctx_fetch_and_index | Fetch URL, convert to markdown, index with 24h TTL cache |
ctx_stats | Token savings, compression breakdown, cost estimates (Opus/Sonnet/Haiku), and learner accuracy |
ctx_doctor | Plugin environment diagnostics |
ctx_purge | Delete all indexed content |
| Spec | Value |
|---|---|
| Language | JavaScript (ES modules, Node.js ≥ 18) |
| Database | SQLite via better-sqlite3 with WAL mode |
| Search | FTS5 (Porter + trigram), BM25, RRF (K=60), proximity reranking |
| Sandbox | Subprocess isolation, 100MB cap, 30s timeout |
| Session | 1000 events max, SHA-256 dedup, FIFO eviction |
| Snapshot | Priority-tiered XML, ≤2KB budget |
| Cache | 24h TTL for fetched URLs |
| Throttling | Progressive: 2→1→blocked over 60s window |
| Compression | 3-stage pipeline: deterministic → pattern-based (10 matchers) → session-aware (learner weights) |
| Learner | Retrieval-based feedback loop, retention weights (5min cache), 7-day decay, signal files |
| Hooks | 6 events, 18 declarative routing rules (PreToolUse, PostToolUse, PreCompact, SessionStart, UserPromptSubmit, SubagentStop) |
| Platform | Windows, macOS, Linux (cross-platform .cmd wrapper) |
| Schema | PRAGMA user_version tracking, ordered migrations, automatic backup |
| Tests | 222 E2E (20 sections) + 58 adversarial + 76 compression + ~55 per-rule routing (vitest) = 410+ total |
| License | Elastic License 2.0 |