ctx-manager
ctx-manager
一个与提供商无关的上下文工程 CLI + MCP 服务器,用于多语言智能体开发。
ctx-manager 位于你的 Docs/ 文件夹(PRD、架构文档、阶段计划、API 规范)与 AI 编码智能体(Claude Code、Cursor、Windsurf)之间,从两个方面削减 token 开销:
确定性、基于标题的文档切片 — 从蓝图文件中精确提取你需要的部分,而不是整个文件。基于结构(对 Markdown 标题做正则匹配),而非 RAG/嵌入。
只追加、经 git 验证的
Memory_Ledger.md— 准确的会话状态,让智能体不会重新推导或幻觉化已经构建的内容。每条记录在标记为已验证之前,都会与真实的git status输出进行核对。
在 Rust、Go、TypeScript、Python 或任何其他技术栈上都能以相同方式工作 — ctx-manager 从不触碰你的应用程序源代码,只处理 Docs/。
安装
uvx --from ctx-manager ctx --help无需 virtualenv 配置,无需全局安装。
Related MCP server: Claude Session MCP
用法
按标题切片蓝图文件:
ctx build --slice "PRD.md > 5. Feature List"将匹配到的章节内容打印到 stdout — 可将其管道输入到 CLAUDE.md 或你的智能体读取上下文的任何位置。
基于账本历史自动切片下一阶段:
ctx build --auto-phase读取 Memory_Ledger.md 获取最近完成的阶段,并自动从 Phase_file.md 中切出下一个阶段的章节 — 无需手动指定 --slice 目标。如果账本中还没有已完成的阶段记录,则回退到阶段 0 并发出警告。
向会话账本追加一条已验证的记录:
ctx append-ledger --summary "Implemented the login endpoint" --category completed在写入之前对照你的项目检查 git status,并根据检查结果给记录加上 [Verified: N files changed]、[Reasoning/State Only] 或 [Unverified: not a git repo] 前缀 — 这样智能体自称的"已完成"声明就会与磁盘上实际发生的情况进行核对。
作为 MCP stdio 服务器运行(适用于 Cursor、Windsurf、Claude Desktop):
ctx mcp将 query_slice、append_ledger_entry 和 get_current_phase 作为 MCP 工具暴露,调用与上述 CLI 命令完全相同的代码路径。
配置
ctx-manager 从当前目录向上搜索 .context/config.toml。如果找不到,则使用合理的默认值(Docs/ 文件夹、Memory_Ledger.md 等)并警告一次。
[project]
docs_dir = "Docs/"
ledger_file = "Memory_Ledger.md"
phase_file = "Phase_file.md"
[blueprint_files]
files = ["PRD.md", "Architecture.md", "API_Spec.md"]
[git]
scope = "docs_dir" # or "repo_root"使用 --project-root 完全覆盖搜索路径。
Claude Code 集成
示例 SessionStart/SessionEnd 钩子(通过 --auto-phase 在会话前自动刷新 CLAUDE.md,会话后自动记录到账本)位于 examples/claude_code_hooks/。
设计原则
Docs/进,Docs/出 — 绝不触碰任何语言的应用程序源代码。先轻后重 — 先用标准库
re而非嵌入,先用subprocess git而非 git 库,先用本地 stdio 而非任何网络服务。只追加的账本 — 没有任何代码路径会整体覆盖
Memory_Ledger.md。永远没有。响亮失败,而非静默 — 缺少标题或文件时返回明确的错误,绝不返回智能体可能产生幻觉的空内容。
完整的设计文档请参阅 Docs/Architecture.md 和 Docs/PRD.md(本项目自食其果 — 在自身开发过程中,它自己的 Docs/ 文件夹就是由 ctx-manager 切片和跟踪的)。
局限性
ctx-manager 无法阻止智能体绕过它。 这里没有任何机制能阻止拥有原始文件系统访问权限的智能体直接读取 Docs/PRD.md,而不是通过 ctx build。这是一个结构性限制,而非缺失的功能 — 基于子进程的 CLI 无法挂钩到另一个进程的文件读取工具调用。
如果你需要真正的强制执行(而不仅仅是约定),那必须来自智能体运行时本身:
Claude Code:在
.claude/settings.json中使用permissions.deny规则阻止 Read 工具直接触碰Docs/*.md,强制依赖ctx build --auto-phase生成的CLAUDE.md。请参阅 Claude Code 自己的权限文档 — 这不是ctx-manager为你配置的内容。MCP 客户端(Cursor、Windsurf 等):该客户端暴露的任何文件系统访问控制(如果有的话)— 不在
ctx-manager的控制范围内。
如果没有上述任何一种机制,ctx-manager 就是一种期望智能体遵守的约定,以经过验证的会话历史(账本)为支撑 — 而非沙箱。
开发
git clone <this-repo>
cd ctx-manager
uv sync
uv run pytest许可证
MIT — 参见 LICENSE。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Versioned documentation registry and semantic search for AI tools and coding assistants.
Shared project context for AI agents and teams: docs, tasks, and messages that stay current.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Provide your AI coding tools with token-efficient access to up-to-date technical documentation for…
Related MCP Servers
- FlicenseNot gradedqualityBmaintenanceEnables maintaining consistent project documentation and progress logs across development workflows. Provides tools for logging changes, tracking project phases, and keeping architecture docs synchronized with day-to-day development work.1
- AlicenseAqualityDmaintenanceProvides Claude Code with programmatic session awareness to track context usage, session history, and task progress. It enables intelligent context reset recommendations and automatic synchronization of project planning documentation.5MIT
- AlicenseNot gradedqualityFmaintenanceProvides AI coding assistants with persistent project memory by capturing development checkpoints during git commits, branch switches, and inactivity. It enables seamless task resumption through tools that retrieve session history, momentum, and synthesized re-entry briefings.213MIT
- AlicenseNot gradedqualityAmaintenanceProvides persistent memory for AI coding agents across sessions by saving and loading session context like tasks, decisions, and blockers.286MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/saturnarians/ctx-manager'
If you have feedback or need assistance with the MCP directory API, please join our Discord server