Skip to main content
Glama

codex-lcm

面向 OpenAI Codex CLI 的本地、无损上下文管理。

codex-lcm 通过 SQLite 捕获 Codex 对话事件,将较旧的上下文压缩为层级摘要(不删除源消息),在会话启动时恢复相关上下文,并通过本地 MCP 服务器提供词汇召回。

“无损”的含义: 源内容在按配置进行机密信息脱敏后予以保留。可搜索的工具预览有界,而完整脱敏后的工具输入和输出可通过分页展开获得。

状态与平台

codex-lcm 是适用于 macOS 的测试版软件。它依赖 Codex hooks 和 POSIX flock;目前不支持也不声称支持 Windows 和 Linux。

Related MCP server: ClaudeX

功能

  • 实时捕获: 通过 Codex hooks 捕获用户提示、助手响应和工具活动。

  • 持久本地存储: WAL 模式下的 SQLite 存储原始消息、结构化消息部件、摘要和 FTS5 索引。

  • 层级压缩: 较旧的消息变为叶摘要;符合条件的摘要运行可被浓缩为更深的 DAG 节点。源行永远不会被自动删除。

  • 上下文恢复: 在会话启动时,在严格的大小限制内注入活动摘要和最新的未摘要消息。

  • 本地召回: 六个 stdio MCP 工具提供词汇搜索、最近会话查找、元数据检查和分页源展开。

  • 故障开放 hooks: 捕获或压缩失败不会阻塞 Codex 回合。

  • 安全控制: 机密信息脱敏、每会话压缩锁、原子消息/FTS 写入、提供方调用预留、进度检查和默认私有文件权限。

从仓库检出安装

python3 -m venv ~/.codex-lcm/venv
~/.codex-lcm/venv/bin/python -m pip install .
~/.codex-lcm/venv/bin/codex-lcm install
~/.codex-lcm/venv/bin/codex-lcm doctor

安装后重启 Codex。在 Codex 中使用 /hooks 检查并信任已安装的 hooks。

安装程序会将 codex-lcm 条目合并到 ~/.codex/hooks.json~/.codex/config.toml。在修改现有文件之前,它会创建带时间戳的备份。再次运行安装程序是幂等的。

源码检出还包含 scripts/install.sh,它执行相同的隔离安装和验证。

可选的 LLM 摘要

在 Python 3.11+ 上,核心包没有第三方运行时依赖。Python 3.10 会安装 tomli 兼容性反向移植,以安全处理 TOML 配置。如果没有 LLM 客户端,压缩将使用确定性的头部/尾部截断。

要启用 OpenAI 兼容的摘要,请安装可选附加组件并配置凭据:

~/.codex-lcm/venv/bin/python -m pip install ".[llm]"
export CODEX_LCM_API_KEY="..."

OPENAI_API_KEY 也被识别。使用 CODEX_LCM_BASE_URLOPENAI_BASE_URL 作为 OpenAI 兼容端点。CODEX_LCM_* 提供方设置被视为一对,并作为一对优先,因此全局密钥永远不会发送到作用域端点。当设置了 CODEX_LCM_BASE_URL 时,也请配置 CODEX_LCM_API_KEY

CLI

codex-lcm install                       Wire hooks and the MCP server into Codex
codex-lcm uninstall                     Remove codex-lcm wiring and keep stored data
codex-lcm status                        Show database statistics
codex-lcm doctor                        Verify package, database, hooks, and MCP wiring
codex-lcm compact --session <id>        Compact one session synchronously
codex-lcm compact --all                 Compact every recorded session synchronously

卸载不会删除 ~/.codex-lcm/ 或其数据库。

MCP 工具

工具

用途

lcm_status

数据库和活动会话统计

lcm_grep

对消息和摘要进行字面量和 FTS5 词汇搜索

lcm_recall

带有限结果计数的排名词汇召回

lcm_expand

摘要源检查或分页原始消息恢复

lcm_recent

在 UTC 回看窗口内更新的会话

lcm_describe

会话或摘要元数据

召回是词汇性的,而非语义性的:此版本不包含嵌入或向量相似性声明。

配置

配置从环境变量读取。

变量

默认值

用途

CODEX_LCM_DB_PATH

~/.codex-lcm/codex-lcm.db

SQLite 数据库路径

CODEX_LCM_FRESH_TAIL

25

受压缩保护的最新原始消息数

CODEX_LCM_LEAF_CHUNK_TOKENS

20000

叶块中的最大估计令牌数

CODEX_LCM_LEAF_MIN_FANOUT

3

浓缩所需的活动叶摘要数

CODEX_LCM_CONDENSED_MIN_FANOUT

3

浓缩所需的活动更深摘要数

CODEX_LCM_MAX_ROUNDS

5

每次工作进程运行的压缩轮数

CODEX_LCM_MAX_SUMMARY_CALLS

12

每个会话和调用窗口允许的提供方尝试次数

CODEX_LCM_SUMMARY_CALL_WINDOW_MS

600000

提供方尝试记账窗口

CODEX_LCM_SUMMARY_TIMEOUT_MS

60000

提供方请求超时

CODEX_LCM_PROGRESS_THRESHOLD

0.10

将低于此节省比率的压缩运行标记为停滞

CODEX_LCM_ADDITIONAL_CONTEXT_LIMIT

5000

恢复上下文预算(估计令牌数)

CODEX_LCM_COMPACTION_BACKLOG

5

Stop 启动工作进程之前允许的额外未摘要消息数

CODEX_LCM_COMPACTION_MODEL

gpt-4.1-mini

叶摘要模型

CODEX_LCM_CONDENSATION_MODEL

gpt-4.1

浓缩模型

CODEX_LCM_API_KEY / OPENAI_API_KEY

可选的提供方凭据

CODEX_LCM_BASE_URL / OPENAI_BASE_URL

可选的 OpenAI 兼容端点

CODEX_LCM_CAPTURE_TOOLS

1

设置为 0 以禁用工具捕获

CODEX_LCM_TOOL_INPUT_MAX_CHARS

2000

可搜索工具输入预览长度

CODEX_LCM_TOOL_RESULT_MAX_CHARS

2000

可搜索工具输出预览长度

默认数据目录模式为 0700;在 POSIX 系统上,数据库、WAL 侧车文件、锁文件和压缩日志模式为 0600

数据与安全边界

  • 在持久化之前,对已知 API 密钥、令牌、授权头、密码/机密赋值、JWT 和 PEM 私钥进行脱敏。

  • 包含凭据的 Git 远程 URL 在存储时不包含用户信息、查询参数或片段。

  • 脱敏是纵深防御,而非保证能识别所有可能的机密格式。

  • 完整脱敏后的工具负载仍可能包含私有对话或项目数据。请相应保护本地账户和数据库备份。

  • 除非安装了可选客户端并配置了提供方凭据或基础 URL,否则不会向 LLM 提供方发送任何数据。

  • 有意不提供自动保留和删除功能。应用程序不会静默丢弃源历史。

开发

使用项目本地环境;测试永远不需要实时 Codex 配置文件或数据库。

python3 -m venv .venv
.venv/bin/python -m pip install -e ".[dev]"
.venv/bin/python -m pytest -q
.venv/bin/python tests/smoke_test.py
.venv/bin/python tests/reliability_test.py
.venv/bin/python tests/package_test.py
.venv/bin/ruff check .
.venv/bin/bandit -q -r codex_lcm

包测试构建并安装到一次性主目录和虚拟环境中。冒烟和可靠性脚本也使用临时数据库。

有关存储模型、不变量、hook 流程和失败行为,请参阅 DESIGN.md

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI coding agents to maintain persistent, cross-session memory of codebase architecture, naming conventions, and decisions through MCP tools. Eliminates repetitive project re-explanation by automatically injecting stored context into every session with local-first SQLite storage and optional team sharing capabilities.
    4
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Persistent memory + FTS5 full-text search for Claude Code conversation history. Indexes ~/.claude/projects/ JSONL into SQLite, exposes 10 MCP tools (store/recall/search memories, browse sessions, get summaries) plus prompts. Includes a web UI for visual exploration
    10
    89
    92
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Collects session JSONL from Codex and Claude Code into local SQLite memory, exposed through MCP with tools for memory context, search, get, put, forget, sleep, and status.

View all related MCP servers

Related MCP Connectors

  • A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log

  • Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).

  • Hosted MCP memory: save sessions/decisions once, search from Claude, Cursor, ChatGPT. EU-hosted FTS.

View all MCP Connectors

Latest Blog Posts

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/Mallet-Dev/codex-lcm'

If you have feedback or need assistance with the MCP directory API, please join our Discord server