文章摘要
文章介绍了Context Mode这一创新工具,它能将Claude Code中的上下文消耗减少98%(从315KB降至5.4KB),解决了MCP工具调用时大量原始数据占用上下文窗口的问题。该工具作为MCP服务器运行,有效缓解了AI代理使用外部工具时上下文窗口被快速耗尽的情况。
文章总结
停止浪费你的上下文窗口——我们开发了Context Mode
作者:Mert Köseoğlu 发布日期:2025年2月20日 标签:MCP、Claude Code、开发者工具、开源
核心内容: 1. 问题背景 - Claude Code中每个MCP工具调用都会向20万token的上下文窗口注入原始数据 - 例如:一个Playwright快照占用56KB,20个GitHub问题占用59KB,访问日志占用45KB - 30分钟后,40%的上下文空间就会被耗尽
- 解决方案:Context Mode
- 作为MCP服务器,位于Claude Code和工具输出之间
- 能将315KB的原始数据压缩至5.4KB,减少98%的占用
- 通过沙盒机制隔离执行环境,仅返回处理后的stdout
- 支持10种语言运行时,包括自动检测Bun加速JS/TS执行
- 知识库功能
- 使用SQLite FTS5进行全文搜索
- 采用BM25排名算法和Porter词干提取技术
- 直接返回精确的代码块和标题层级结构
- 实际效果
- 测试场景包括测试分类、TypeScript错误诊断等11种实际用例
- 典型压缩效果:
- Playwright快照:56KB→299B
- GitHub问题:59KB→1.1KB
- 访问日志:45KB→155B
- 完整会话中,上下文剩余量从60%提升到99%
- 有效工作时间从30分钟延长至3小时
- 安装方式
- 通过插件市场安装:
/plugin marketplace add mksglu/claude-context-mode /plugin install context-mode@claude-context-mode - 或通过MCP直接安装:
claude mcp add context-mode -- npx -y context-mode
- 开发动机
- 作者运营MCP目录中心,发现现有工具普遍存在原始数据转储问题
- 受Cloudflare的Code Mode启发,专注于解决工具输出端的压缩问题
- 项目已开源(MIT协议):github.com/mksglu/claude-context-mode
(注:保留了核心技术细节和关键数据,删减了社交媒体链接和个人介绍等次要信息)
评论总结
以下是评论内容的总结:
项目核心价值
- 作者介绍项目通过隔离子进程(stdout-only)和算法过滤(SQLite FTS5+BM25),有效减少98%的上下文污染
- 关键引用:"The core idea: every MCP tool call dumps raw data into your 200K context window... No LLM calls, purely algorithmic"
- 关键引用:"The 98% reduction is the real story here... subprocess isolation is smart - stdout-only is the right constraint"
技术优势
- 预处理过滤优于传统grep/LLM排序,解决多步骤工作流中的上下文膨胀问题
- 关键引用:"BM25 + FTS5 means you're pre-filtering at index time... difference between usable and unusable context"
- 关键引用:"It's made a sizable reduction in my token use" (用户实际反馈)
延伸讨论
- 与类似项目(rkt)的比较,认为本方案走得更远
- 关键引用:"This sounds a little bit like rkt?... This looks like it goes a little further"
- 关键引用:"AFAIK Claude Code doesn't inject all the MCP output into the context" (现有方案对比)
质疑与建议
- 可能遗漏相关函数(边缘情况)和凭证传递问题
- 关键引用:"how does credential passthrough work with MCP's protocol boundaries?"
- 关键引用:"Are there edge cases where it is unaware of... a utility function"
未来方向
- 建议结合回溯修剪等更多上下文优化手段
- 关键引用:"Backtracking strikes me as another promising direction to avoid context bloat"
- 关键引用:"why not use sub agents for areas of focus?... Context is gold"
幽默评论
- 戏称可能影响AI经济
- 关键引用:"this is going to crash the AI economy. nvda down 20 percent"