AI Agent 持续丢失上下文
每个AI编程Agent都面临同样的根本挑战:明明只需要一个函数签名却重新读取整个文件,解析本可压缩95%的原始Shell输出,会话结束的瞬间就忘记一切。结果是Token浪费、响应缓慢和不可靠的输出。
什么是Context OS?
Context OS控制AI上下文的整个生命周期:从读取文件和压缩Shell输出,通过智能路由和持久记忆,到验证输出和跨工具、团队和模型的无缝交付。
工作原理
每个上下文请求都通过LeanCTX的图驱动确定性管道。系统对意图进行分类,通过Multi-Edge BFS和RRF Fusion评估相关性,使用模式特定算法进行压缩,并在交付前验证输出。每个步骤都可复现、可审计。
输入
通过MCP或HTTP接收来自任何AI工具的文件读取、Shell命令和搜索查询。
意图
对任务类型进行分类,为每个请求选择最优处理策略。
相关性
使用AST分析、熵评分以及跨imports、calls、type references和test links的Multi-Edge图遍历,将内容过滤为仅任务相关的信息。
压缩
使用模式特定算法、缓存和增量编码进行智能压缩。
验证
检查输出中的幻觉路径、损坏的导入、密钥泄露和策略违规。
交付
通过MCP、HTTP API或SDK将压缩、验证后的上下文返回给AI工具。
一个工具,三种连接方式
lean-ctx 自动为每个代理选择最佳集成模式。CLI-Redirect 完全消除 MCP schema 开销,Hybrid 结合两者优势,Full MCP 提供最大工具访问。
lean-ctx read src/auth.ts -m map MCP cache + CLI shell/search 58 tools via MCP + lazy tool set 常驻上下文运行时
lean-ctx daemon 作为后台服务通过 Unix Domain Socket 运行。提供持久会话状态、即时缓存命中和 setup 时自动启动。更新时,daemon 会自动使用新 binary 重启。过期的 PID/socket 文件会被主动清理,所有连接都有内置 timeout — 无需手动管理。
29+ 代理,自动配置
lean-ctx 检测已安装的代理并为每个配置最佳集成模式。CLI-Redirect 用于有 shell 访问的代理,Hybrid 用于混合环境,Full MCP 用于仅协议代理。
| Agent | CLI-Redirect | Hybrid | MCP | Setup |
|---|---|---|---|---|
| Cursor | ● | – | – | lean-ctx init --agent cursor |
| Claude Code | – | ● | – | lean-ctx init --agent claude |
| Codex | – | ● | – | lean-ctx init --agent codex |
| OpenCode | – | ● | – | lean-ctx init --agent opencode |
| Gemini CLI | ● | – | – | lean-ctx init --agent gemini |
| CRUSH | – | ● | – | lean-ctx init --agent crush |
| Hermes | – | ● | – | lean-ctx init --agent hermes |
| Pi | – | ● | – | lean-ctx init --agent pi |
| Qoder | – | ● | – | lean-ctx init --agent qoder |
| Windsurf | – | ● | – | lean-ctx init --agent windsurf |
| Copilot | – | ● | – | lean-ctx init --agent copilot |
| Amp | – | ● | – | lean-ctx init --agent amp |
| Cline | – | ● | – | lean-ctx init --agent cline |
| Roo Code | – | ● | – | lean-ctx init --agent roo |
| Kiro | – | ● | – | lean-ctx init --agent kiro |
| Antigravity | – | ● | – | lean-ctx init --agent antigravity |
| Amazon Q | – | ● | – | lean-ctx init --agent amazonq |
| Qwen | – | ● | – | lean-ctx init --agent qwen |
| Trae | – | ● | – | lean-ctx init --agent trae |
| Verdent | – | ● | – | lean-ctx init --agent verdent |
| JetBrains | – | – | ● | lean-ctx init --agent jetbrains |
| QoderWork | – | – | ● | lean-ctx init --agent qoderwork |
| VS Code | – | – | ● | lean-ctx init --agent vscode |
| Zed | – | – | ● | lean-ctx init --agent zed |
| Neovim | – | – | ● | lean-ctx init --agent neovim |
| Emacs | – | – | ● | lean-ctx init --agent emacs |
| Sublime Text | – | – | ● | lean-ctx init --agent sublime |
| Aider | – | – | ● | lean-ctx init --agent aider |
| Continue | – | – | ● | lean-ctx init --agent continue |
数学基础的上下文选择
每个上下文元素都有可衡量的势值。LeanCTX使用上下文场理论(CFT)来计算哪些文件、函数和知识事实属于您的AI注意力窗口 — 哪些不属于。
上下文势 Φ
Phi函数实时评估每个上下文元素。相关性、时效性、图中心性、历史、成本和冗余被组合成单一的排名分数。
上下文句柄
对上下文元素的稀疏、惰性引用。代理不需要加载整个文件,而是使用像@F1或@K3这样的轻量级句柄,按需展开 — 在真正需要内容之前节省令牌。
上下文覆盖层
上下文状态的可逆变更。固定关键文件、抑制噪声、提升优先级或标记元素为过时 — 所有这些都不修改源。覆盖层可堆叠且可撤销。
上下文编译器
给定令牌预算和任务描述,编译器使用基于Φ排名的贪婪选择和冗余惩罚来选择最优的上下文元素子集。结果是一个最小化的、经过验证的上下文包。
上下文策略引擎
控制上下文行为的声明式规则。TDD期间自动固定测试文件、抑制vendor目录、按文件类型强制令牌限制或标记过时元素 — 所有这些都可按项目配置。
完整的CLI和MCP访问
每个CFT操作都可通过CLI命令和MCP工具使用。在终端中使用lean-ctx control、lean-ctx plan、lean-ctx compile,或通过MCP使用ctx_control、ctx_plan、ctx_compile。
Context Packages
打包、共享和复用积累的项目上下文。将知识、图数据、注意事项和会话发现导出为可移植的包。在会话启动时自动加载包以获得即时领域专业知识。
九大支柱。一个运行时。
代码和AI之间的一切,已处理。
智能 I/O
确定性读取、Shell压缩、搜索 - 节省99%的Token
智能
意图路由、模式选择、自适应管道
记忆
会话、项目知识、图谱、交接
治理
角色、预算、SLO、工作流门控、策略
验证
Lean4形式化证明、Claim-based Verification、Quality Levels 0-4
集成
MCP、HTTP、SDK、29+个IDE、云、团队服务器
Shared Sessions
基于工作区和频道的跨代理会话共享
Context Bus
通过SSE实现上下文变更的实时事件流
SDK & API
用于外部集成的TypeScript SDK和REST API
查看实际效果
LeanCTX位于AI工具与代码库之间。每次文件读取、Shell命令和搜索查询都流经Context Kernel——在到达模型之前经过压缩、缓存和验证。
每个输出都附带证明
LeanCTX为每个会话生成证明构件:读取了哪些文件、压缩了什么、哪些检查通过了、Token如何使用。这使AI工作可审计、可重放、值得信赖。
Ready to get started?
Install lean-ctx in 60 seconds, auto-configure your editor, and start saving tokens immediately. No cloud, no config files to write manually.
See how to get started