Token导航 LogoToken导航TokenDH.com
Lossless Context Management logo
搜索检索stdio官方级别未说明来源级核验

Lossless Context Management

MCP Server

为Claude Code提供无损内存检索、自动上下文保存和并行数据处理的增强层服务。

工具数

6

提示词数

0

GitHub Stars

1

资源数

0
PythonClaude数据分析Claude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

dpalmqvist

提供方

dpalmqvist

最后核验

2026/5/17 20:21

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uv run lcm status [session_id]

详细介绍

Claude代码的无损上下文管理

MCP服务器+挂钩增强层,提供无损内存检索、跨压缩事件的自动上下文保存和并行数据处理运算符。

根据论文 *远程代码代理的无损上下文管理* Ehrlich&Blackman(2025)描述了一种确定性架构,该架构通过维护不可变的消息存储、分层摘要DAG和运算符级递归工具,在长上下文基准测试中优于Claude Code。

特性

  • 不可变消息存储 --SQLite+FTS5全文搜索,仅可追加
  • 层次化摘要DAG --三级升级压缩(preserve_details、bullet_points、确定性截断)
  • 自动上下文恢复 --钩子捕获消息并在压缩后注入摘要
  • MCP工具lcm_status, lcm_grep, lcm_describe, lcm_expand 用于记忆检索
  • 并行数据运算符llm_mapagentic_map 用于处理具有并发Haiku调用的JSONL文件

先决条件

  • 紫外线 (Python包管理器)
  • 克劳德代码 命令行界面
  • ANTHROPIC_API_KEY 环境变量(用于摘要和运算符)

安装

1.克隆存储库

git clone https://github.com/dpalmqvist/lossless-context-management.git
cd lossless-context-management

2.安装依赖项

uv sync

3.使用Claude Code注册MCP服务器

claude mcp add --transport stdio lcm -- \
  uv --directory /path/to/lossless-context-management run python -m lcm.server

替换 /path/to/lossless-context-management 使用克隆仓库的实际路径。

4.配置挂钩

将以下内容添加到您的项目中 .claude/settings.json (或合并到现有的):

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume",
        "hooks": [
          {
            "type": "command",
            "command": "/path/to/lossless-context-management/hooks/session_start.sh",
            "timeout": 10
          }
        ]
      },
      {
        "matcher": "compact",
        "hooks": [
          {
            "type": "command",
            "command": "echo '{\"type\":\"compact\"}' | /path/to/lossless-context-management/hooks/session_start.sh",
            "timeout": 30
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Bash|Edit|Write|Read",
        "hooks": [
          {
            "type": "command",
            "command": "/path/to/lossless-context-management/hooks/post_tool_use.sh",
            "timeout": 10,
            "async": true
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "/path/to/lossless-context-management/hooks/user_prompt_submit.sh",
            "timeout": 10,
            "async": true
          }
        ]
      }
    ]
  }
}

替换 /path/to/lossless-context-management 与实际路径。

5.设置API密钥

export ANTHROPIC_API_KEY="your-key-here"

用法

安装后,LCM工具在Claude Code中可用:

工具说明
lcm_status会话统计:消息计数、摘要计数、令牌、DAG深度
lcm_grep使用FTS5或正则表达式搜索消息历史记录,按覆盖摘要分组
lcm_describe查找任何LCM ID(消息、摘要或文件)的元数据
lcm_expand将摘要展开到其组成消息
llm_map与无状态Haiku调用并行处理JSONL项
agentic_map使用多轮代理循环处理JSONL项目

命令行界面

# Check session status
uv run lcm status [session_id]

# Manual hook operations
uv run lcm hook capture
uv run lcm hook inject
uv run lcm hook init

发展

# Install with dev dependencies
uv sync --dev

# Run tests (75 tests, ~0.5s)
uv run pytest tests/ -v

# Test with MCP Inspector
npx @modelcontextprotocol/inspector uv --directory . run python -m lcm.server

运作原理

  1. 钩子 自动将Claude Code的转录中的消息捕获到仅可追加的SQLite存储中
  2. 当令牌计数超过 τ_软 (50K令牌),最旧的未汇总消息被分组到块中并汇总为 叶节点 在DAG中
  3. 当5+个未密集的叶节点累积时,它们是 浓缩的 进入更高级别的摘要节点
  4. τ_卡片 (20万个令牌),所有未概括的消息都被压缩
  5. 压实后 会话开始钩子 注入一个包含顶级摘要和LCM ID的上下文恢复块
  6. 然后,Claude Code可以使用 lcm_expandlcm_grep 深入了解对话历史的任何部分

参考

埃利希,N.和布莱克曼,S.(2025)。 *远程代码代理的无损上下文管理*.arXiv:2506.18655。https://arxiv.org/abs/2506.18655

许可证

麻省理工学院

目录标签

目录标签

PythonClaude数据分析无损内存检索本地部署自动上下文保存并行数据处理SQLite存储DAG摘要

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

session

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

6

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiosession部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP