### Startup Sequence Logic Source: https://github.com/mksglu/context-mode/blob/main/llms-full.txt Illustrates the steps involved in starting the context-mode plugin, including environment variable setup, version self-healing, dependency installation, and build selection. It prioritizes a pre-built bundle if available, otherwise falls back to installing dependencies and compiling TypeScript. ```javascript // 1. Set CLAUDE_PROJECT_DIR environment variable if not already set // 2. Version self-healing: Find newest version in plugin cache and update installed_plugins.json // 3. Dependency installation: Check for and install missing dependencies like better-sqlite3, turndown, etc. // 4. Build selection: Use server.bundle.mjs if exists, otherwise install node_modules, compile TS, and use build/server.js // 5. MCP server starts on stdio transport ``` -------------------------------- ### Startup Sequence Logic Source: https://github.com/mksglu/context-mode/blob/main/docs/llms-full.txt The start.mjs script handles environment variable setup, version self-healing, dependency installation, and build selection before starting the MCP server. ```javascript 1. Set `CLAUDE_PROJECT_DIR` environment variable if not already set 2. **Version self-healing:** If running from a plugin cache directory with multiple version subdirectories, find the newest version, update `installed_plugins.json` to point to it 3. **Dependency installation:** Check for `better-sqlite3`, `turndown`, `turndown-plugin-gfm`, `@mixmark-io/domino`. Install missing ones via `npm install --no-package-lock --no-save --silent` 4. **Build selection:** - If `server.bundle.mjs` exists (CI-built): import and start immediately - Otherwise: ensure `node_modules` exists (run `npm install`), ensure `build/server.js` exists (run `npx tsc`), then import `build/server.js` 5. MCP server starts on stdio transport ``` -------------------------------- ### Session Continuity Example Source: https://github.com/mksglu/context-mode/blob/main/README.md Demonstrates starting a multi-step task and observing session continuity after context compaction. The model resumes from the last prompt with tasks, files, and decisions intact. ```bash 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. ``` -------------------------------- ### Manual Install OpenClaw Plugin Source: https://github.com/mksglu/context-mode/blob/main/docs/adapters/openclaw.md Manual installation script for advanced users or custom setups. Ensure Node.js is in PATH and OpenClaw has been started at least once. ```bash bash scripts/install-openclaw-plugin.sh [OPENCLAW_STATE_DIR] ``` -------------------------------- ### Install OpenClaw Plugin Source: https://github.com/mksglu/context-mode/blob/main/docs/adapters/openclaw.md Quick installation command for the OpenClaw plugin. This script handles building, extension setup, runtime registration, and gateway restart. ```bash npm run install:openclaw ``` -------------------------------- ### Clone, Install, and Test Context Mode Source: https://github.com/mksglu/context-mode/blob/main/README.md Standard procedure for contributing to the context-mode project. Includes cloning the repository, installing dependencies, and running tests. ```bash git clone https://github.com/mksglu/context-mode.git cd context-mode && npm install && npm test ``` -------------------------------- ### Troubleshooting: Install context-mode Globally Source: https://github.com/mksglu/context-mode/blob/main/docs/jetbrains-copilot.md If `npx` is not found or context-mode commands fail, try installing it globally. Verify the installation using `which context-mode`. ```bash npm install -g context-mode ``` -------------------------------- ### Install context-mode using OMP Plugin Manager Source: https://github.com/mksglu/context-mode/blob/main/README.md Install context-mode as a plugin using the OMP plugin install command. This is the recommended installation method for OMP. ```bash omp plugin install context-mode ``` -------------------------------- ### Basic useEffect Hook Example Source: https://github.com/mksglu/context-mode/blob/main/tests/fixtures/context7-react-docs.md Use useEffect to synchronize a component with an external system. The setup function establishes a connection and returns a cleanup function to disconnect when dependencies change or the component unmounts. ```javascript import { useState, useEffect } from 'react'; import { createConnection } from './chat.js'; function ChatRoom({ roomId }) { const [serverUrl, setServerUrl] = useState('https://localhost:1234'); useEffect(() => { const connection = createConnection(serverUrl, roomId); connection.connect(); // Cleanup function return () => { connection.disconnect(); }; }, [serverUrl, roomId]); return
Chat Room
; } ``` -------------------------------- ### Install context-mode Hooks for JetBrains Copilot Source: https://github.com/mksglu/context-mode/blob/main/docs/jetbrains-copilot.md Run this command to install the necessary hooks for JetBrains Copilot integration. It creates a `.github/hooks/context-mode.json` file. ```bash npx context-mode@latest setup --adapter jetbrains-copilot ``` -------------------------------- ### Manually Install context-mode Plugin for OMP Source: https://github.com/mksglu/context-mode/blob/main/README.md Manually install context-mode as an OMP plugin by adding it to the local plugins directory and using bun or npm to install. This is an alternative if 'omp plugin install' is unavailable. ```bash cd ~/.omp/plugins bun add context-mode # or: npm install context-mode ``` -------------------------------- ### PHP Auto-Wrapping Example Source: https://github.com/mksglu/context-mode/blob/main/llms-full.txt If PHP code does not start with ' { const connection = createConnection(serverUrl, roomId); connection.connect(); return () => { connection.disconnect(); }; }, [serverUrl, roomId]); // ... ``` -------------------------------- ### Example of Large Output Externalization Source: https://github.com/mksglu/context-mode/blob/main/BENCHMARK.md Demonstrates how large outputs are handled by indexing into FTS5 and returning a pointer message. The LLM can query this indexed content on demand using ctx_search(). ```text Indexed N sections from: execute:shell Use ctx_search(...) to query. ``` -------------------------------- ### Live Benchmark Execution Source: https://github.com/mksglu/context-mode/blob/main/BENCHMARK.md Run a live benchmark, which requires the Context7 fixture to be set up. ```bash npx tsx tests/live-benchmark.ts ``` -------------------------------- ### JetBrains Copilot: Copy routing instructions Source: https://github.com/mksglu/context-mode/blob/main/README.md Optionally copy routing instructions to `.github/copilot-instructions.md` for full model awareness with JetBrains Copilot. ```bash cp node_modules/context-mode/configs/jetbrains-copilot/copilot-instructions.md .github/copilot-instructions.md ``` -------------------------------- ### Install Context Mode Plugin for Claude Code Source: https://github.com/mksglu/context-mode/blob/main/README.md Use these commands to add and install the context-mode plugin in Claude Code. Restart or reload plugins after installation. Verify with the doctor command. ```bash /plugin marketplace add mksglu/context-mode /plugin install context-mode@context-mode ``` ```bash /context-mode:ctx-doctor ``` -------------------------------- ### VS Code Copilot: Copy routing instructions Source: https://github.com/mksglu/context-mode/blob/main/README.md Optionally copy routing instructions to `.github/copilot-instructions.md` for full model awareness with VS Code Copilot. ```bash cp node_modules/context-mode/configs/vscode-copilot/copilot-instructions.md .github/copilot-instructions.md ``` -------------------------------- ### Copy Kiro Routing Instructions Source: https://github.com/mksglu/context-mode/blob/main/README.md Copy the KIRO.md routing file to the project root for Kiro integration. This is necessary as Kiro's agentSpawn is not yet implemented. ```bash cp node_modules/context-mode/configs/kiro/KIRO.md ./KIRO.md ``` -------------------------------- ### Alternative MCP-only Install for Claude Code Source: https://github.com/mksglu/context-mode/blob/main/README.md Install context-mode using the MCP-only method for access to MCP tools without automatic routing. This is useful for initial testing. ```bash claude mcp add context-mode -- npx -y context-mode ``` -------------------------------- ### Use Bash for Small Outputs (< 20 Lines) Source: https://github.com/mksglu/context-mode/blob/main/skills/context-mode/references/anti-patterns.md For outputs that are small and do not require LLM summarization, use Bash directly instead of `execute` to reduce overhead. ```shell BAD — wasteful use of execute: Tool: execute code: "echo $(node --version)" language: shell ``` ```shell GOOD — just use Bash: Tool: Bash command: node --version ``` -------------------------------- ### VS Code Copilot: Configure context-mode Source: https://github.com/mksglu/context-mode/blob/main/README.md Set up the context-mode server and hooks for VS Code Copilot by creating `.vscode/mcp.json` and `.github/hooks/context-mode.json` files. This enables automatic routing via the SessionStart hook. ```json { "servers": { "context-mode": { "command": "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" } ] } } ``` -------------------------------- ### Diagnose Context-Mode Installation Source: https://github.com/mksglu/context-mode/blob/main/llms-full.txt Runs a comprehensive set of server-side checks to diagnose the context-mode installation. It verifies runtime availability for all languages, sandbox functionality, FTS5/SQLite native module, hook scripts, and the current version. ```javascript ctx_doctor({}) // no parameters ``` -------------------------------- ### JetBrains Copilot: Configure context-mode Source: https://github.com/mksglu/context-mode/blob/main/README.md Set up the context-mode server and hooks for JetBrains Copilot. This involves adding the MCP server via IDE settings and creating `.github/hooks/context-mode.json`. ```json { "hooks": { "PreToolUse": [ { "type": "command", "command": "context-mode hook jetbrains-copilot pretooluse" } ], "PostToolUse": [ { "type": "command", "command": "context-mode hook jetbrains-copilot posttooluse" } ], "SessionStart": [ { "type": "command", "command": "context-mode hook jetbrains-copilot sessionstart" } ] } } ``` -------------------------------- ### Execute Shell Commands in Sandbox Source: https://github.com/mksglu/context-mode/blob/main/configs/openclaw/AGENTS.md Execute shell commands within the sandbox. This is restricted to specific commands like `git`, `mkdir`, `rm`, `mv`, `cd`, `ls`, `npm install`, and `pip install`. For other shell commands, use `context-mode__ctx_execute`. ```shell ... ``` -------------------------------- ### Additional Context Response Formats Source: https://github.com/mksglu/context-mode/blob/main/docs/platform-support.md Examples of how additional context is formatted for different platforms. Note the variations in key names and nesting. ```json { "additionalContext": "..." } ``` ```json { "hookSpecificOutput": { "additionalContext": "..." } } ``` ```json { "hookSpecificOutput": { "hookEventName": "PostToolUse", "additionalContext": "..." } } ``` ```json { "additional_context": "..." } ``` -------------------------------- ### Copy OMP System Configuration Source: https://github.com/mksglu/context-mode/blob/main/README.md Copies the system configuration file for context-mode to the OMP agent directory. This is part of the manual installation process. ```bash cp node_modules/context-mode/configs/omp/SYSTEM.md ~/.omp/agent/SYSTEM.md ``` -------------------------------- ### Session Statistics Tracking Object Source: https://github.com/mksglu/context-mode/blob/main/docs/llms-full.txt This object tracks per-session statistics for tool usage and data processing. Initialize this object at the start of each session. ```typescript const sessionStats = { sessionStart: Date.now(), calls: {} as Record, bytesReturned: {} as Record, bytesIndexed: 0, bytesSandboxed: 0, }; ``` -------------------------------- ### Manually Add context-mode to Pi Settings Source: https://github.com/mksglu/context-mode/blob/main/README.md Manually add context-mode to Pi's settings.json for package management. This can be used as an alternative to 'pi install'. ```json { "packages": ["npm:context-mode"] } ``` -------------------------------- ### Analyze Project Structure with Shell Source: https://github.com/mksglu/context-mode/blob/main/skills/context-mode/references/patterns-shell.md Use find and sort commands to display directory structure, file types, and largest files. Useful for understanding project layout and identifying potential issues. ```shell echo "=== Directory Structure ===" find . -maxdepth 3 -type d \ ! -path '*/node_modules/*' \ ! -path '*/.git/*' \ ! -path '*/dist/*' \ ! -path '*/.next/*' \ ! -path '*/__pycache__/*' \ | sort echo "" echo "=== File Type Distribution ===" find . -type f \ ! -path '*/node_modules/*' \ ! -path '*/.git/*' \ ! -path '*/dist/*' \ | sed 's/.*\.///' | sort | uniq -c | sort -rn | head -20 echo "" echo "=== Largest Files (top 20) ===" find . -type f \ ! -path '*/node_modules/*' \ ! -path '*/.git/*' \ -exec ls -la {} \; | sort -k5 -rn | head -20 | awk '{print $5, $9}' echo "" echo "=== Directory Sizes ===" du -sh */ 2>/dev/null | sort -rh | head -15 ``` -------------------------------- ### Register Context-Mode Hooks for Cursor Source: https://github.com/mksglu/context-mode/blob/main/docs/platform-support.md Use these commands to register context-mode hooks for Cursor. Ensure context-mode is installed globally or via a local plugin. ```bash context-mode hook cursor pretooluse ``` ```bash context-mode hook cursor posttooluse ``` ```bash context-mode hook cursor stop ``` -------------------------------- ### Fetch and Index External Documentation Source: https://github.com/mksglu/context-mode/blob/main/skills/context-mode/SKILL.md Use `ctx_fetch_and_index` to retrieve and index external documentation, such as web docs or GitHub-hosted files. This allows for searching within that specific content using the `source` parameter. ```shell Index React/Next.js/Zod docs, then search ``` ```shell https://raw.githubusercontent.com/org/repo/main/CHANGELOG.md ``` -------------------------------- ### LLM Summary Prompt Effectiveness Source: https://github.com/mksglu/context-mode/blob/main/skills/context-mode/references/anti-patterns.md Provide specific and actionable summary prompts to guide the LLM. Vague prompts may lead to irrelevant summarization. ```text summary_prompt: "Summarize this" ``` ```text summary_prompt: "Report the count of failing tests, list each failure with its file path and error message, and identify any patterns in the failures" ``` -------------------------------- ### Fetch and Index URL Source: https://github.com/mksglu/context-mode/blob/main/configs/jetbrains-copilot/copilot-instructions.md Use `ctx_fetch_and_index` to fetch content from a URL and index it. Raw HTML is never directly added to the context. ```javascript ctx_fetch_and_index(url, source) ``` -------------------------------- ### Elixir Auto-Wrapping Example Source: https://github.com/mksglu/context-mode/blob/main/docs/llms-full.txt If a `mix.exs` file exists in the project root, Elixir code has `Path.wildcard` prepended to add compiled BEAM paths to the code path. ```elixir Path.wildcard("*/ebin") |> Enum.each(&Code.prepend_path/1) # ... your code here ... ``` -------------------------------- ### Plugin Manifest Configuration Source: https://github.com/mksglu/context-mode/blob/main/llms-full.txt Defines the plugin's name, description, MCP server configuration, and skills directory. Ensure the 'command' and 'args' correctly point to your entry point script. ```json { "name": "context-mode", "description": "Claude Code MCP plugin that saves 98% of your context window.", "mcpServers": { "context-mode": { "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/start.mjs"] } }, "skills": "./skills/" } ``` -------------------------------- ### Build and Test Development Changes Source: https://github.com/mksglu/context-mode/blob/main/CONTRIBUTING.md Commands for building the project, running all tests using Vitest, performing type checking, and running tests in watch mode. ```bash # TypeScript compilation npm run build # Run all tests (parallel via Vitest) npm test # Type checking only npm run typecheck # Watch mode npm run test:watch ``` -------------------------------- ### Configure MCP Server for Context Mode (Manual Fallback) Source: https://github.com/mksglu/context-mode/blob/main/README.md Add this TOML configuration to `~/.codex/config.toml` to manually configure the MCP server for context-mode when `plugin_hooks` is not available. ```toml [features] hooks = true [mcp_servers.context-mode] command = "context-mode" ```