-
Notifications
You must be signed in to change notification settings - Fork 1
feat(context-mode): add context-mode plugin — context window optimizer #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
creativerezz
wants to merge
3
commits into
StackOneHQ:main
Choose a base branch
from
creativerezz:context-mode-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
227f50e
feat(context-mode): add context-mode plugin — context window optimize…
creativerezz 4cbf86a
fix(context-mode): track plugin.json version in release-please extra-…
creativerezz 44557d3
chore(claude): add repo skills, skill-reviewer agent, and plugin-dev …
creativerezz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
plugins/integrations/context-mode/.claude-plugin/plugin.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "context-mode", | ||
| "version": "1.0.0", | ||
| "description": "Save 40-60% of agent context window — auto-index tool output, persist session state through compaction, and search across sessions via FTS5 knowledge base. Works with Pi, Claude Code, Cursor, Codex, and 15+ agent platforms.", | ||
| "author": { | ||
| "name": "mksglu", | ||
| "url": "https://github.com/mksglu" | ||
| }, | ||
| "homepage": "https://pi.dev/packages/context-mode", | ||
| "repository": "https://github.com/mksglu/context-mode", | ||
| "license": "Elastic-2.0", | ||
| "keywords": [ | ||
| "context-mode", | ||
| "context-window", | ||
| "session-persistence", | ||
| "fts5", | ||
| "knowledge-base", | ||
| "tool-output", | ||
| "compaction", | ||
| "mcp", | ||
| "hook" | ||
| ] | ||
| } |
167 changes: 167 additions & 0 deletions
167
plugins/integrations/context-mode/skills/context-mode/SKILL.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| --- | ||
| name: context-mode | ||
| description: Install and use Context Mode — the context window optimizer for AI coding agents. Saves 40-60% of context by auto-indexing tool output into FTS5, persisting session state through compaction, and enabling cross-session search. Supports Pi, Claude Code, Cursor, Codex, and 15+ platforms. Use when user asks about "context-mode", "context window", "tool output indexing", "session continuity", "installing context-mode", "ctx batch execute", "ctx search", or "FTS5 knowledge base". Do NOT use for StackOne integration tasks (use stackone-agents, stackone-platform, etc.). | ||
| license: Elastic-2.0 | ||
| compatibility: Requires Node.js >= 22.5 or Bun. Works as Pi extension (auto-routing), Claude Code plugin (hook-based), or MCP server (manual routing). | ||
| metadata: | ||
| author: mksglu (Reza) | ||
| version: "1.0.0" | ||
| --- | ||
|
|
||
| # Context Mode | ||
|
|
||
| **The other half of the context problem.** | ||
|
|
||
| Context Mode is an extension (+ skill) that solves one problem: **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 intercepts tool output, auto-indexes it into a persistent FTS5 knowledge base, and injects only the **derived summary** into context — saving 40-60% of your context window. On compaction, it captures a **Session Guide** so the agent resumes with full working state. | ||
|
|
||
| ## Available Tools | ||
|
|
||
| | Tool | Purpose | | ||
| |------|---------| | ||
| | `ctx_execute` | Run code in sandbox; only `console.log()` output enters context | | ||
|
creativerezz marked this conversation as resolved.
|
||
| | `ctx_execute_file` | Read a file into sandbox variable; only derived summary enters context | | ||
| | `ctx_batch_execute` | Run multiple commands, auto-index all output, query inline | | ||
| | `ctx_search` | Search the FTS5 knowledge base (indexed content + session memory) | | ||
| | `ctx_index` | Index content (docs, READMEs, API refs) into searchable knowledge base | | ||
| | `ctx_fetch_and_index` | Fetch URL content, convert to markdown, index without touching context | | ||
| | `ctx_stats` | Show context savings, token consumption, per-tool breakdown | | ||
| | `ctx_doctor` | Diagnose context-mode installation | | ||
| | `ctx_purge` | Delete indexed content (destructive — requires confirmation) | | ||
| | `ctx_insight` | Launch analytics dashboard in browser | | ||
| | `ctx_upgrade` | Upgrade to latest version | | ||
|
|
||
| ## Install | ||
|
|
||
| ### Option A — Pi (extension, automatic routing) | ||
|
|
||
| ```bash | ||
| # Install globally | ||
| npm install -g context-mode | ||
|
|
||
| # Install into Pi | ||
| pi install npm:context-mode | ||
|
|
||
| # Verify | ||
| ctx_stats | ||
| ``` | ||
|
|
||
| ### Option B — Claude Code (hook-based, automatic routing) | ||
|
|
||
| ```bash | ||
| # Via plugin marketplace | ||
| /plugin install context-mode | ||
|
|
||
| # Or directly | ||
| npm install -g context-mode | ||
| /plugin add context-mode | ||
| ``` | ||
|
|
||
| ### Option C — Any agent (MCP server, manual routing) | ||
|
|
||
| ```bash | ||
| npm install -g context-mode | ||
| ``` | ||
|
|
||
| Then add to your MCP config: | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "context-mode": { | ||
| "command": "context-mode" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Option D — Any agent (via npx skills) | ||
|
|
||
| ```bash | ||
| npx skills add mksglu/context-mode | ||
| ``` | ||
|
|
||
| ### Verify | ||
|
|
||
| After install, run any of these: | ||
| - `ctx_stats` — shows context savings and tool usage | ||
| - `ctx_doctor` — diagnostic report | ||
| - `ctx_search(queries: ["hello"])` — quick smoke test | ||
|
|
||
| ## Usage Patterns | ||
|
|
||
| ### Think-in-Code: Keep raw bytes out of context | ||
|
|
||
| Instead of reading files or dumping output, run code in the sandbox and print only the answer: | ||
|
|
||
| ``` | ||
| ctx_execute(language: "javascript", code: ` | ||
| const files = fs.readdirSync('src').filter(f => f.endsWith('.ts')); | ||
| files.forEach(f => { | ||
| const lines = fs.readFileSync('src/'+f,'utf8').split('\\n').length; | ||
| console.log(f + ': ' + lines + ' lines'); | ||
| }); | ||
| `) | ||
| ``` | ||
|
|
||
| ### Batch + Search: Gather data, get answers in one round trip | ||
|
|
||
| ``` | ||
| ctx_batch_execute( | ||
| commands: [ | ||
| {label: "issues", command: "gh issue list --json number,title,labels --limit 50"}, | ||
| {label: "prs", command: "gh pr list --json number,title,state --limit 20"} | ||
| ], | ||
| queries: ["bug", "security", "priority"], | ||
| concurrency: 2 | ||
| ) | ||
| ``` | ||
|
|
||
| ### Fetch docs without context pollution | ||
|
|
||
| ``` | ||
| ctx_fetch_and_index( | ||
| url: "https://docs.stackone.com/llms.txt", | ||
| source: "stackone-docs" | ||
| ) | ||
| // Later, search it: | ||
| ctx_search(queries: ["API keys", "linked accounts"], source: "stackone-docs") | ||
| ``` | ||
|
|
||
| ## Session Continuity | ||
|
|
||
| Context Mode persists session state across compaction via a **Session Guide** — a structured snapshot with these categories: | ||
|
|
||
| - **Last Request** — user's last prompt so agent continues seamlessly | ||
| - **Active Files** — files being edited with line ranges and content hashes | ||
| - **Active Tasks** — tasks in progress with open file, description, and checkpoints | ||
| - **Rules** — active project rules paths | ||
| - **Decisions** — user corrections, preference changes, and accepted/rejected approaches | ||
| - **Errors & Resolutions** — error → resolution pairs | ||
| - **Blockers** — open and resolved blockers | ||
| - **Git** — operations performed (checkout, commit, push) | ||
| - **MCP Tools Used** — tool names with call counts | ||
| - **Rejected Approaches** — tool calls the user denied | ||
|
|
||
| ## Platform Support | ||
|
|
||
| Context Mode runs on **15+ agent platforms** including: | ||
| Pi, Claude Code, Qwen Code, Gemini CLI, VS Code Copilot, JetBrains Copilot, Cursor, Codex CLI, OpenCode, KiloCode, Kiro, Zed, and more. | ||
|
|
||
| | Feature | Pi | Claude Code | Cursor | Codex | | ||
| |---------|:--:|:-----------:|:------:|:-----:| | ||
| | MCP Tools | ✅ extension | ✅ hook | ✅ plugin | ✅ hook | | ||
|
creativerezz marked this conversation as resolved.
|
||
| | PreToolUse Hook | ✅ | ✅ | ✅ | ✅ | | ||
| | PostToolUse Hook | ✅ | ✅ | ✅ | ✅ | | ||
| | SessionStart Hook | ✅ | ✅ | — | ✅ | | ||
| | PreCompact Hook | ✅ | ✅ | — | ✅ | | ||
| | Block Tools | ✅ | ✅ | ✅ | ✅ | | ||
|
|
||
| ## Resources | ||
|
|
||
| - **Homepage**: https://pi.dev/packages/context-mode | ||
| - **Repository**: https://github.com/mksglu/context-mode | ||
| - **npm**: https://www.npmjs.com/package/context-mode | ||
| - **Discord**: https://discord.gg/DCN9jUgN5v | ||
| - **License**: Elastic-2.0 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.