CtxGuard — AI skill for Claude Code
面向 AI Agent 的高并发、低延迟上下文治理与 Prompt Cache 守护网关 (Tree-sitter AST / Tool Delta / 50%~80% Token 削减).
How to install CtxGuard
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open 255308153/CtxGuard and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
What CtxGuard does
面向 AI Agent 的高并发、低延迟上下文治理与 Prompt Cache 守护网关 (Tree-sitter AST / Tool Delta / 50%~80% Token 削减).
Alternatives in AI
- Codeburn — Free, local tool to track AI coding token usage and cost across 37 tools and agents (Claude Code, Cursor, Code 9.7k ★
- Model Update — 增量更新财务模型 — 用新财报/新指引/修正假设重算 DCF 内在价值、Comps 隐含价、投资逻辑与目标价,输出 before→after delta 6.6k ★
- Ccstatusline — by sirmalloc - A highly customizable status line formatter for Claude Code CLI that displays model info, git b 5.5k ★
README
CtxGuard
**高并发、低延迟的 AI Agent 上下文治理与智能缓存加速网关**
*毫秒级算子流水线 • 保证云端 KV Cache 稳定命中 • 长效时序记忆 • 零业务侵入*
[](LICENSE) [](https://www.python.org/downloads/) []() [](https://fastapi.tiangolo.com)
项目简介
在现代 AI Agent(如 Claude Code、Cursor、Pi Agent、Codex)的复杂编码与长链路自动化任务中,随着工具调用的频繁执行,请求上下文呈指数级膨胀:大段未修改的代码差异、冗长的构建日志、重复的状态探测输出以及历史思考链迅速消耗宝贵的上下文窗口,产生高昂的 Token 费用;与此同时,客户端工具定义的无序序列化与动态提示词拼接极易引发服务商前缀缓存(Prompt Cache)频繁失效。
**CtxGuard** 是一套部署在客户端与大模型服务商(OpenAI、Anthropic、DeepSeek 等)之间的透明反向代理网关。它在协议中转层对出向请求实施轻量级结构化优化、语法树骨架提取与字节级防抖,在完全不损耗模型推理能力与代码逻辑的前提下,显著降低通信负载与计算开销,并为多轮会话提供自动进化的项目级经验沉淀与知识图谱记忆能力。
控制面板预览 (Web Dashboard)
CtxGuard 提供了现代化的一体化监控控制台(默认访问 `http://127.0.0.1:8787/dashboard`),用于直观监控全局 Token 流向、会话压缩曲线、知识图谱与自动演进的规则库:
| 实时 Token 流量趋势与多轮压缩监控 | 跨 Agent 时序知识图谱拓扑 |
|---|---|
![]() |
![]() |
| 控制面板全局数据大盘概览 | 自进化避坑经验规则库 |
|---|---|
![]() |
![]() |
系统架构 (System Architecture)

核心设计与技术实现
1. 物理级前缀防抖与 Prompt Cache 保活
- 二进制切片透传:对多轮对话中未发生变更的历史消息,跳过 Python 运行时的反序列化与字典重构,直接提取并转发原始 HTTP 请求的底层二进制切片,从根本上杜绝空格、换行符及浮点格式漂移。
- Schema 确定性重构:在网关层递归遍历
tools列表及内部 JSON Schema 定义,统一按字母序进行确定性重排序,彻底解决各类客户端实现中字典无序导致的前缀缓存击穿。 - 生命周期冷热隔离与确定性执行:将上下文划分为静态系统区与动态交互区。会话建立后自动锁定头部提示词快照,动态注入项仅追加于末尾活跃窗口;采用纯粹确定性单向压缩,彻底消除运行时回滚抖动。
2. 工业级 Tree-sitter 多语言语法树引擎 (TreeSitterSkeletonizer)
- 9+ 门主流语言原生支持:采用官方预编译纯 C 语言 Tree-sitter 绑定(支持 Python, JavaScript, TypeScript, TSX, Go, Ru
Related Skills
Jcodemunch MCP
Cut AI token costs 95%+ on code exploration. The leading MCP server for precise, symbol-level GitHub code retr
Codesift
Token-efficient code intelligence for AI agents — 66 MCP tools via tree-sitter AST, BM25F search, semantic sea
Semble Rs
Fast, AI-agent-native code search in Rust — hybrid BM25 + semantic, Tree-sitter AST chunking, dependency & imp
Ast Outline
ast-outline lets AI coding agents pull exactly the code context they need — a repo skeleton, a file outline, o
Reporecall
Local codebase memory for Claude Code. Tree-sitter AST indexing (22 languages), hybrid keyword + vector search
Source To Prompt Tui
TUI for combining source code files into LLM-ready prompts: tree explorer, syntax preview, token estimation, a
Related Agents
Stats Analyzer
Analyzes ~/.claude/stats-cache.json and history.jsonl to produce a concise usage report with model token break
Usage Reporter
Reads real Claude Code usage from ~/.claude/stats-cache.json. Reports daily/weekly token usage by model, cache
Why Expander
Expands one node of a Five Whys tree into nested causal reasons and writes them as a JSON fragment file. Dispa



