context-mode 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "claude-context-mode",
3
+ "owner": {
4
+ "name": "Mert Koseoğlu",
5
+ "email": "code.bm.ksglu@gmail.com"
6
+ },
7
+ "metadata": {
8
+ "description": "Claude Code plugins by Mert Koseoğlu",
9
+ "version": "1.0.0"
10
+ },
11
+ "plugins": [
12
+ {
13
+ "name": "context-mode",
14
+ "source": "./",
15
+ "description": "Claude Code MCP plugin that saves 94% of your context window. Sandboxed code execution in 10 languages, FTS5 knowledge base with BM25 ranking, and smart truncation.",
16
+ "version": "0.4.1",
17
+ "author": {
18
+ "name": "Mert Koseoğlu"
19
+ },
20
+ "category": "development",
21
+ "keywords": [
22
+ "mcp",
23
+ "context-window",
24
+ "sandbox",
25
+ "code-execution",
26
+ "fts5",
27
+ "bm25",
28
+ "playwright",
29
+ "context7"
30
+ ]
31
+ }
32
+ ]
33
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Claude Code MCP plugin that saves 94% of your context window. Sandboxed code execution in 10 languages, FTS5 knowledge base with BM25 ranking, and smart truncation.",
5
5
  "author": {
6
6
  "name": "Mert Koseoğlu",
package/README.md CHANGED
@@ -10,16 +10,16 @@ Context Mode intercepts these operations, processes data in isolated subprocesse
10
10
 
11
11
  Claude Code has a 200K token context window. Here's how fast popular MCP servers eat through it:
12
12
 
13
- | MCP Server | Tool | Output per Call | Source |
14
- |---|---|---|---|
15
- | **Playwright** | `browser_snapshot` | 10K-135K tokens (50-540 KB) | [playwright-mcp#1233](https://github.com/microsoft/playwright-mcp/issues/1233) |
16
- | **Context7** | `query-docs` | 4K-10K tokens per query | [upstash/context7](https://github.com/upstash/context7) |
17
- | **GitHub** | `list_commits` (30) | 29K-64K tokens | [github-mcp-server#142](https://github.com/github/github-mcp-server/issues/142) |
18
- | **Sentry** | full mode tools | 14K tokens (definitions only) | [getsentry/sentry-mcp](https://github.com/getsentry/sentry-mcp) |
19
- | **Supabase** | database tools | 4.2K tokens (definitions only) | [supabase-community/supabase-mcp](https://github.com/supabase-community/supabase-mcp) |
20
- | **Firecrawl** | `scrape` / `crawl` | 5K-50K+ tokens per page | [firecrawl](https://github.com/mendableai/firecrawl) |
21
- | **Chrome DevTools** | all tools | 17K tokens (definitions only) | Community benchmark |
22
- | **Fetch** | `fetch` | 5K-50K tokens per page | Official reference server |
13
+ | MCP Server | Tool | Without Context Mode | With Context Mode | Savings | Source |
14
+ |---|---|---|---|---|---|
15
+ | **Playwright** | `browser_snapshot` | 10K-135K tokens | ~20 tokens | **99%** | [playwright-mcp#1233](https://github.com/microsoft/playwright-mcp/issues/1233) |
16
+ | **Context7** | `query-docs` | 4K-10K tokens | ~70 tokens | **98%** | [upstash/context7](https://github.com/upstash/context7) |
17
+ | **GitHub** | `list_commits` (30) | 29K-64K tokens | ~10 tokens | **99%** | [github-mcp-server#142](https://github.com/github/github-mcp-server/issues/142) |
18
+ | **Sentry** | issue analysis | 5K-30K tokens | ~25 tokens | **99%** | [getsentry/sentry-mcp](https://github.com/getsentry/sentry-mcp) |
19
+ | **Supabase** | schema queries | 2K-30K tokens | ~30 tokens | **99%** | [supabase-community/supabase-mcp](https://github.com/supabase-community/supabase-mcp) |
20
+ | **Firecrawl** | `scrape` / `crawl` | 5K-50K+ tokens | ~70 tokens | **99%** | [firecrawl](https://github.com/mendableai/firecrawl) |
21
+ | **Chrome DevTools** | DOM / network | 5K-50K+ tokens | ~25 tokens | **99%** | Community benchmark |
22
+ | **Fetch** | `fetch` | 5K-50K tokens | ~70 tokens | **99%** | Official reference server |
23
23
 
24
24
  **Real measurement** ([Scott Spence, 2025](https://scottspence.com/posts/optimising-mcp-server-context-usage-in-claude-code)): With 81+ MCP tools enabled across multiple servers, **143K of 200K tokens (72%) consumed** — 82K tokens just for MCP tool definitions. Only 28% left for actual work.
25
25
 
@@ -44,10 +44,11 @@ Claude Code has a 200K token context window. Here's how fast popular MCP servers
44
44
  ### Option 1: Claude Code Plugin (Recommended)
45
45
 
46
46
  ```bash
47
- /plugin install context-mode@claude-plugin-directory
47
+ /plugin marketplace add mksglu/claude-context-mode
48
+ /plugin install context-mode@claude-context-mode
48
49
  ```
49
50
 
50
- Installs as a Claude Code plugin with skills and MCP server bundled together.
51
+ Installs as a Claude Code plugin with MCP server + skills bundled. The skill automatically guides Claude to route large outputs through Context Mode.
51
52
 
52
53
  ### Option 2: MCP Server Only
53
54
 
@@ -57,6 +58,12 @@ claude mcp add context-mode -- npx -y context-mode
57
58
 
58
59
  Restart Claude Code. 5 tools are now available.
59
60
 
61
+ ### Option 3: Local Development
62
+
63
+ ```bash
64
+ claude --plugin-dir ./path/to/context-mode
65
+ ```
66
+
60
67
  ## Tools
61
68
 
62
69
  ### `execute` — Run Code in Sandbox
@@ -264,6 +271,72 @@ Typical 45-minute debugging session:
264
271
  | Source code to edit | Plain `Read` tool | Need full content for edits |
265
272
  | Small files (<20 lines) | Plain `Read` tool | Minimal overhead |
266
273
 
274
+ ## Example Prompts
275
+
276
+ Just ask naturally — Claude automatically routes through Context Mode when it saves tokens.
277
+
278
+ ### Git & GitHub
279
+
280
+ ```
281
+ "Analyze the last 50 commits and find the most frequently changed files"
282
+ "List all open PRs on this repo and summarize their status"
283
+ "Show contributors ranked by commit count this month"
284
+ "Find all commits that touched the auth module in the last 30 days"
285
+ ```
286
+
287
+ ### Code Analysis
288
+
289
+ ```
290
+ "Analyze all TypeScript files in src/ and report function counts per file"
291
+ "Find all TODO and FIXME comments across the codebase"
292
+ "Count lines of code per language in this project"
293
+ "List all exported functions from src/utils/ and their parameter signatures"
294
+ ```
295
+
296
+ ### Logs & Debugging
297
+
298
+ ```
299
+ "Read the access log and break down requests by HTTP status code"
300
+ "Find the top 10 slowest API endpoints from the request log"
301
+ "Parse the error log and group exceptions by type with frequency"
302
+ "Analyze the build output and list all warnings with file locations"
303
+ ```
304
+
305
+ ### Test & CI
306
+
307
+ ```
308
+ "Run the test suite and give me a pass/fail summary"
309
+ "Analyze test coverage output and find untested files"
310
+ "Check which tests have been flaky in the last 10 CI runs"
311
+ ```
312
+
313
+ ### Data & Config
314
+
315
+ ```
316
+ "Analyze package-lock.json and find the 10 largest dependencies by size"
317
+ "Parse the CSV export and compute average response time per endpoint"
318
+ "Read the Kubernetes manifests and summarize resource limits per pod"
319
+ "Compare tsconfig.json across packages in this monorepo"
320
+ ```
321
+
322
+ ### Documentation Lookup
323
+
324
+ ```
325
+ "Fetch the React useEffect docs and find the cleanup pattern"
326
+ "Index the Next.js App Router documentation and search for loading states"
327
+ "Look up the Zod docs and find string validation examples"
328
+ "Fetch the Tailwind docs and search for responsive breakpoint utilities"
329
+ ```
330
+
331
+ ### Cloud & Infrastructure
332
+
333
+ ```
334
+ "List all S3 buckets and their sizes using AWS CLI"
335
+ "Show running Kubernetes pods and their restart counts"
336
+ "List all Docker containers with their memory and CPU usage"
337
+ "Check the status of all Cloudflare Workers in this account"
338
+ ```
339
+
267
340
  ## Requirements
268
341
 
269
342
  - **Node.js 18+**
package/build/server.js CHANGED
@@ -9,7 +9,7 @@ const runtimes = detectRuntimes();
9
9
  const available = getAvailableLanguages(runtimes);
10
10
  const server = new McpServer({
11
11
  name: "context-mode",
12
- version: "0.4.0",
12
+ version: "0.4.1",
13
13
  });
14
14
  const executor = new PolyglotExecutor({ runtimes });
15
15
  // Lazy singleton — no DB overhead unless index/search is used
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "Claude Code MCP plugin that saves 94% of your context window. Sandboxed code execution, FTS5 knowledge base, and smart truncation.",
6
6
  "author": "Mert Koseoğlu",
@@ -1,120 +1,139 @@
1
1
  ---
2
2
  name: context-mode
3
3
  description: |
4
- Use context-mode tools (execute, execute_file) instead of Bash/cat when processing
5
- large outputs. Trigger phrases: "analyze logs", "summarize output", "process data",
6
- "parse JSON", "filter results", "extract errors", "check build output",
7
- "analyze dependencies", "process API response", "large file analysis".
4
+ ALWAYS use context-mode tools instead of Bash/curl/cat when output MIGHT exceed 20 lines.
5
+ This includes: API requests (curl, fetch, gh, aws), file reading (cat, head, tail),
6
+ command output (npm test, git log, docker ps, kubectl), log analysis, data processing,
7
+ and ANY operation where you cannot guarantee the output will be small.
8
+ When in doubt, use context-mode — the cost of routing through it is near zero,
9
+ but the cost of flooding context with 50KB+ of raw data is catastrophic.
8
10
  ---
9
11
 
10
- # Context Mode: execute & execute_file
12
+ # Context Mode: Default for All Large Output
11
13
 
12
- ## When to Use (Decision Tree)
14
+ ## MANDATORY RULE
13
15
 
14
- ```
15
- Will the command output > 20 lines?
16
- ├── YES → Will you process/filter/summarize that output?
17
- │ ├── YES → Use execute or execute_file
18
- │ └── NO → Use Bash (you need raw output)
19
- └── NO → Use Bash (small output fits in context)
20
- ```
21
-
22
- **Rule of thumb:** If you would pipe Bash output through grep/awk/jq to reduce it,
23
- use `execute` or `execute_file` instead — the LLM summary is better.
24
-
25
- ## Quick Reference
26
-
27
- | Tool | Purpose | Key Parameters |
28
- |------|---------|---------------|
29
- | `execute` | Run inline code, get LLM summary | `code`, `language`, `timeout_ms`, `summary_prompt` |
30
- | `execute_file` | Run a script file, get LLM summary | `file_path`, `args`, `timeout_ms`, `summary_prompt` |
16
+ **Before using Bash, curl, cat, or any command that produces output, ask yourself:**
31
17
 
32
- Both tools execute code and return an **LLM-generated summary** instead of raw stdout.
33
- The raw output never enters your context window — only the summary does.
18
+ > "Could this output be more than 20 lines?"
34
19
 
35
- ## Language Selection Guide
20
+ If YES or UNCERTAIN → use `execute` or `execute_file`. Not Bash. Not curl. Not cat.
36
21
 
37
- | Scenario | Language | Why |
38
- |----------|----------|-----|
39
- | HTTP requests, JSON APIs | `javascript` | Native fetch, JSON.parse |
40
- | Data analysis, CSV, math | `python` | pandas, csv module, statistics |
41
- | Piping commands, grep, find | `shell` | Native OS tools |
42
- | TypeScript project analysis | `javascript` | Can require/import project files |
43
- | Log file filtering | `shell` | grep/awk are purpose-built |
44
- | File comparison | `python` | difflib is excellent |
22
+ **This is not optional.** Every KB of unnecessary context reduces the quality and speed of the entire session.
45
23
 
46
- ## Usage Pattern
47
-
48
- ### execute — inline code
24
+ ## Decision Tree
49
25
 
50
26
  ```
51
- Tool: execute
52
- Parameters:
53
- code: |
54
- const data = require('fs').readFileSync('package.json', 'utf8');
55
- const pkg = JSON.parse(data);
56
- console.log(`Name: ${pkg.name}`);
57
- console.log(`Dependencies: ${Object.keys(pkg.dependencies || {}).length}`);
58
- console.log(`DevDependencies: ${Object.keys(pkg.devDependencies || {}).length}`);
59
- Object.entries(pkg.dependencies || {}).forEach(([k, v]) => console.log(` ${k}: ${v}`));
60
- language: javascript
61
- timeout_ms: 10000
62
- summary_prompt: "List the package name, dependency count, and any outdated patterns"
27
+ About to run a command / read a file / call an API?
28
+
29
+ ├── Output is GUARANTEED small (<20 lines)?
30
+ │ └── Use Bash (git status, pwd, ls, echo, etc.)
31
+
32
+ ├── Output MIGHT be large or you're UNSURE?
33
+ │ └── Use context-mode execute or execute_file
34
+
35
+ ├── Fetching web documentation or HTML page?
36
+ │ └── Use fetch_and_index → search
37
+
38
+ ├── Processing output from another MCP tool (Playwright, Context7, etc.)?
39
+ │ └── Use index → search
40
+
41
+ └── Reading a file to analyze/summarize (not edit)?
42
+ └── Use execute_file (file loads into FILE_CONTENT, not context)
63
43
  ```
64
44
 
65
- ### execute_file run existing script
66
-
67
- ```
68
- Tool: execute_file
69
- Parameters:
70
- file_path: ./scripts/analyze-bundle.js
71
- args: ["--format", "summary"]
72
- timeout_ms: 30000
73
- summary_prompt: "Report bundle size changes and any chunks exceeding 500KB"
74
- ```
45
+ ## When to Use Each Tool
46
+
47
+ | Situation | Tool | Example |
48
+ |-----------|------|---------|
49
+ | Hit an API endpoint | `execute` | `fetch('http://localhost:3000/api/orders')` |
50
+ | Run CLI that returns data | `execute` | `gh pr list`, `aws s3 ls`, `kubectl get pods` |
51
+ | Run tests | `execute` | `npm test`, `pytest`, `go test ./...` |
52
+ | Git operations | `execute` | `git log --oneline -50`, `git diff HEAD~5` |
53
+ | Docker/K8s inspection | `execute` | `docker stats --no-stream`, `kubectl describe pod` |
54
+ | Read a log file | `execute_file` | Parse access.log, error.log, build output |
55
+ | Read a data file | `execute_file` | Analyze CSV, JSON, YAML, XML |
56
+ | Read source code to analyze | `execute_file` | Count functions, find patterns, extract metrics |
57
+ | Fetch web docs | `fetch_and_index` | Index React/Next.js/Zod docs, then search |
58
+ | Process large MCP output | `index` → `search` | Index Playwright snapshot, then query elements |
59
+
60
+ ## Automatic Triggers
61
+
62
+ Use context-mode for ANY of these, without being asked:
63
+
64
+ - **API debugging**: "hit this endpoint", "call the API", "check the response", "find the bug in the response"
65
+ - **Log analysis**: "check the logs", "what errors", "read access.log", "debug the 500s"
66
+ - **Test runs**: "run the tests", "check if tests pass", "test suite output"
67
+ - **Git history**: "show recent commits", "git log", "what changed", "diff between branches"
68
+ - **Data inspection**: "look at the CSV", "parse the JSON", "analyze the config"
69
+ - **Infrastructure**: "list containers", "check pods", "S3 buckets", "show running services"
70
+ - **Dependency audit**: "check dependencies", "outdated packages", "security audit"
71
+ - **Build output**: "build the project", "check for warnings", "compile errors"
72
+ - **Code metrics**: "count lines", "find TODOs", "function count", "analyze codebase"
73
+ - **Web docs lookup**: "look up the docs", "check the API reference", "find examples"
74
+
75
+ ## Language Selection
76
+
77
+ | Situation | Language | Why |
78
+ |-----------|----------|-----|
79
+ | HTTP/API calls, JSON | `javascript` | Native fetch, JSON.parse, async/await |
80
+ | Data analysis, CSV, stats | `python` | csv, statistics, collections, re |
81
+ | Shell commands with pipes | `shell` | grep, awk, jq, native tools |
82
+ | File pattern matching | `shell` | find, wc, sort, uniq |
75
83
 
76
84
  ## Critical Rules
77
85
 
78
- 1. **Always print/log output.** The tool captures stdout. No output = empty summary.
79
- 2. **Use `summary_prompt`** to guide what the LLM extracts from the output.
80
- 3. **Set appropriate `timeout_ms`** network calls need 15000+, file ops need 5000+.
81
- 4. **Print structured data** JSON.stringify or formatted tables summarize better.
82
- 5. **Don't use for < 20 lines** Bash is simpler and wastes no LLM call.
86
+ 1. **Always console.log/print your findings.** stdout is all that enters context. No output = wasted call.
87
+ 2. **Write analysis code, not just data dumps.** Don't `console.log(JSON.stringify(data))` analyze first, print findings.
88
+ 3. **Be specific in output.** Print bug details with IDs, line numbers, exact values — not just counts.
89
+ 4. **For files you need to EDIT**: Use the normal Read tool. context-mode is for analysis, not editing.
90
+ 5. **For tiny outputs (<5 lines guaranteed)**: Use Bash. Don't over-engineer `git status` through context-mode.
83
91
 
84
- ## Examples by Language
92
+ ## Examples
85
93
 
86
- ### JavaScript: API response analysis
94
+ ### Debug an API endpoint
87
95
  ```javascript
88
- const resp = await fetch('https://api.example.com/status');
89
- const data = await resp.json();
90
- console.log(JSON.stringify(data, null, 2));
96
+ const resp = await fetch('http://localhost:3000/api/orders');
97
+ const { orders } = await resp.json();
98
+
99
+ const bugs = [];
100
+ const negQty = orders.filter(o => o.quantity < 0);
101
+ if (negQty.length) bugs.push(`Negative qty: ${negQty.map(o => o.id).join(', ')}`);
102
+
103
+ const nullFields = orders.filter(o => !o.product || !o.customer);
104
+ if (nullFields.length) bugs.push(`Null fields: ${nullFields.map(o => o.id).join(', ')}`);
105
+
106
+ console.log(`${orders.length} orders, ${bugs.length} bugs found:`);
107
+ bugs.forEach(b => console.log(`- ${b}`));
91
108
  ```
92
- > summary_prompt: "Report service health, any degraded components, and error rates"
93
109
 
94
- ### Python: Log analysis
95
- ```python
96
- import re
97
- with open('/var/log/app.log') as f:
98
- errors = [l for l in f if 'ERROR' in l]
99
- for e in errors[-50:]:
100
- print(e.strip())
101
- print(f"\nTotal errors: {len(errors)}")
110
+ ### Analyze test output
111
+ ```shell
112
+ npm test 2>&1
113
+ echo "EXIT=$?"
102
114
  ```
103
- > summary_prompt: "Categorize errors by type and report frequency of each"
104
115
 
105
- ### Shell: Build output filtering
116
+ ### Check GitHub PRs
106
117
  ```shell
107
- npm run build 2>&1
108
- echo "EXIT_CODE=$?"
118
+ gh pr list --json number,title,state,reviewDecision --jq '.[] | "\(.number) [\(.state)] \(.title) — \(.reviewDecision // "no review")"'
119
+ ```
120
+
121
+ ### Read and analyze a large file
122
+ ```python
123
+ # FILE_CONTENT is pre-loaded by execute_file
124
+ import json
125
+ data = json.loads(FILE_CONTENT)
126
+ print(f"Records: {len(data)}")
127
+ # ... analyze and print findings
109
128
  ```
110
- > summary_prompt: "Report success/failure, list any errors or warnings with file locations"
111
129
 
112
- ## Anti-Patterns (Avoid These)
130
+ ## Anti-Patterns
113
131
 
114
- - Using `execute` for `git status` (small output use Bash)
115
- - Forgetting `console.log()` / `print()` (produces empty summary)
116
- - Setting `timeout_ms: 5000` for network requests (will timeout)
117
- - Loading a 10K-line file into context then asking to summarize (use execute instead)
132
+ - Using `curl http://api/endpoint` via Bash 50KB floods context. Use `execute` with fetch instead.
133
+ - Using `cat large-file.json` via Bash → entire file in context. Use `execute_file` instead.
134
+ - Using `gh pr list` via Bash raw JSON in context. Use `execute` with `--jq` filter instead.
135
+ - Piping Bash output through `| head -20` you lose the rest. Use `execute` to analyze ALL data and print summary.
136
+ - Running `npm test` via Bash → full test output in context. Use `execute` to capture and summarize.
118
137
 
119
138
  ## Reference Files
120
139