- बाहरी टूल कॉल के दौरान बनने वाले बड़े raw data को context window को तेज़ी से खत्म करने की समस्या का समाधान
- Claude Code और टूल आउटपुट के बीच स्थित होकर डेटा को compress और filter करता है, 315KB को घटाकर 5.4KB करता है (98% कमी)
- sandbox संरचना के ज़रिए हर execution को isolate करता है, और सिर्फ stdout को context में शामिल करके logs, snapshots जैसे मूल डेटा के leak को रोकता है
- SQLite FTS5 आधारित knowledge base से Markdown content को index करता है, और BM25 ranking व Porter stemming लागू कर सटीक code block search को support करता है
- उसी 200K token सीमा में session duration 30 मिनट से बढ़कर 3 घंटे हो जाता है, जिससे AI agent का efficient context management संभव होता है
समस्या
- Claude Code की MCP tool calls हर कॉल पर raw data को सीधे 200K context window में dump कर देती हैं
- Playwright snapshot 56KB, GitHub issues 20 items 59KB, access logs 45KB आदि
- लगभग 30 मिनट इस्तेमाल पर पूरे context का 40% खर्च हो जाता है
- MCP बाहरी टूल इस्तेमाल का standard बन चुका है, लेकिन input definitions और output data दोनों context भर देते हैं, यह एक संरचनात्मक सीमा है
- 81 से अधिक tools active होने पर पहला message भेजने से पहले ही 72% (143K tokens) खर्च हो जाते हैं
Context Mode की संरचना
- Claude Code और टूल आउटपुट के बीच मौजूद MCP server, जो raw data को न्यूनतम करके आगे भेजता है
- 315KB output घटकर 5.4KB हो जाता है (98% कमी)
- हर
execute कॉल isolated subprocess में चलती है, इसलिए memory या state share किए बिना स्वतंत्र execution होता है
- सिर्फ stdout ही context में शामिल होता है, जबकि logs, API responses, snapshots आदि sandbox के भीतर रहते हैं
- 10 language runtimes का support: JavaScript, TypeScript, Python, Shell, Ruby, Go, Rust, PHP, Perl, R
- Bun auto-detection से JS/TS execution speed 3~5 गुना तेज़
- authenticated CLI (
gh, aws, gcloud, kubectl, docker) में environment variable inheritance के ज़रिए credentials सुरक्षित रूप से pass किए जाते हैं
Knowledge base
index टूल Markdown को heading units में split करता है और code blocks को जस का तस रखते हुए SQLite FTS5 virtual table में store करता है
- search के समय BM25 ranking algorithm का इस्तेमाल कर word frequency, inverse document frequency, और document length normalization के आधार पर relevance निकाली जाती है
- Porter stemming लागू होने से “running”, “runs”, “ran” एक ही root के रूप में match होते हैं
search कॉल पर summary नहीं, बल्कि सटीक code blocks और heading hierarchy लौटाई जाती है
fetch_and_index URL को fetch कर HTML को Markdown में बदलकर index करता है, और original page context में शामिल नहीं होता
प्रदर्शन के आँकड़े
- 11 वास्तविक scenarios (test triage, TypeScript error diagnosis, git diff review आदि) में सभी जगह output 1KB से कम रखा गया
- Playwright snapshot: 56KB → 299B
- GitHub issues (20): 59KB → 1.1KB
- access logs (500 entries): 45KB → 155B
- CSV analysis (500 rows): 85KB → 222B
- Git logs (153 commits): 11.6KB → 107B
- repository investigation (subagent): 986KB → 62KB (5 calls vs 37 calls)
- पूरे session में 315KB → 5.4KB, session duration 30 मिनट → 3 घंटे
- 45 मिनट बाद बचा हुआ context: पहले 60% → अब 99%
इंस्टॉलेशन और उपयोग
- Plugin Marketplace के ज़रिए automatic routing hooks और slash commands का support
- सिर्फ MCP के लिए अलग installation भी संभव
- Claude Code restart करने के बाद तुरंत इस्तेमाल किया जा सकता है
वास्तविक बदलाव
- इस्तेमाल के तरीके में बदलाव किए बिना PreToolUse hook अपने आप output routing करता है
- subagents डिफ़ॉल्ट टूल के रूप में
batch_execute इस्तेमाल करते हैं
- Bash subagent को
general-purpose में upgrade किया गया है, जिससे MCP tools तक access मिलता है
- नतीजतन context window अब इतनी जल्दी नहीं भरती, और वही tokens लेकर लंबे sessions चलाए जा सकते हैं
विकास पृष्ठभूमि
- MCP Directory & Hub चलाते समय यह common pattern मिला कि सभी MCP servers raw data को context में dump कर रहे थे
- Cloudflare के Code Mode से प्रेरणा मिली, जिसने tool definitions को compress किया था; इसे आगे बढ़ाकर output data compression की दिशा में विकसित किया गया
- Claude Code sessions में 6 गुना लंबे समय तक काम कर पाना verify होने के बाद इसे MIT license के तहत open source जारी किया गया
- GitHub: mksglu/claude-context-mode
अभी कोई टिप्पणी नहीं है.