claude-code-substrate-memory

claude-code-substrate-memory

MCP server that connects Claude Code to Substrate organizational memory, providing tools for searching, reading, querying, and writing memory, with automatic capture of conversation turns.

Category
访问服务器

README

Claude Code Substrate Memory

claude-code-substrate-memory connects Claude Code to Substrate organizational memory. It provides seven MCP tools for reading and writing memory, captures new transcript turns through Claude Code lifecycle hooks, and keeps failed deliveries in a bounded local spool.

Version 0.1.0 uses only the Python standard library at runtime.

Install

Clone the repository and load it as a Claude Code plugin:

git clone https://github.com/Substrate-memory/claude-code-substrate-memory.git
claude --plugin-dir /absolute/path/to/claude-code-substrate-memory

For development or direct CLI use, install the package into a Python 3.11+ environment:

python -m pip install -e .
substrate-claude-code status

The plugin manifests provide the MCP server, lifecycle hooks, and slash commands. The MCP server can also be run directly with python -m claude_code_memory.server when src/ is on PYTHONPATH.

Configuration

Credentials are accepted from environment variables only:

SUBSTRATE_API_URL=https://your-substrate-server.example
SUBSTRATE_API_KEY=your-profile-scoped-bearer-key

Set them in the environment that launches Claude Code. Never write SUBSTRATE_API_KEY to .mcp.json, hooks/hooks.json, a project settings file, or another plaintext configuration file. Run substrate-claude-code configure to print the required wiring without writing any secret.

If the variables are absent or the API is temporarily unreachable, capture remains enabled and new events are placed in the local spool beneath ~/.substrate/claude_code_memory/. Set SUBSTRATE_STATE_HOME to relocate the state root, which is particularly useful for isolated tests.

MCP tools

Tool Purpose
substrate_search Search organizational memory and return cited memory cards.
substrate_read Read one wiki page by repository-relative path.
substrate_query Ask a cited question over Substrate memory.
substrate_ingest Submit text for asynchronous wiki ingestion.
substrate_remember Record a durable fact or decision requested by the user.
substrate_sync Retry delivery of locally spooled capture events.
substrate_status Show content-free configuration and spool counters.

The repository also adds /substrate-status and /substrate-recall slash commands.

Hook capture

Claude Code invokes four command hooks from hooks/hooks.json:

  • Stop captures only user and assistant messages not previously checkpointed and emits a turn event.
  • PreCompact captures the same incremental transcript window as pre_compress before Claude Code compacts its context.
  • SessionEnd emits a content-free session_end event containing only the normalized message count and session boundary. A persistent marker ensures it is emitted at most once.
  • SessionStart performs a bounded Substrate search and prints a compact Markdown recall block when relevant memory is available.

Each hook is a fresh process, so per-session message digests and one-shot markers are persisted under the plugin state directory. Capture events are durably spooled before network delivery.

Privacy boundary

The transcript reader keeps only top-level user and assistant records. It excludes sidechain records produced by subagents and ignores system, attachment, mode, permission-mode, and last-prompt records.

For captured user and assistant messages, the plugin may send:

  • visible text from string content and text, input_text, or output_text blocks;
  • short markers such as [tool_use: Read] and [tool_result];
  • role, message index, bounded message identifier, session boundary, and capture metadata.

It does not intentionally send:

  • raw tool inputs or raw tool-result payloads;
  • hidden reasoning, token usage, billing fields, or arbitrary provider metadata;
  • attachment bodies, binary media, data URLs, or sidechain transcript text;
  • SUBSTRATE_API_KEY or other recognized credential-shaped values.

The shared capture core redacts recognized secrets before persistence and transfer. Redaction is defense in depth, not proof that arbitrary sensitive prose is absent. Visible prompts and assistant output can themselves contain confidential material, so configure only a trusted Substrate server and review its access and retention policy. Failed deliveries remain in a bounded owner-private local spool until delivered, evicted by the bound, quarantined, or removed by the operator.

Fail-open behavior

Hooks always exit with status 0. API failures, malformed hook input, unreadable or truncated transcripts, corrupt local state, and recall failures do not block or annotate a Claude Code session. Normal capture hooks write nothing to stdout; optional diagnostics go only to stderr when SUBSTRATE_DEBUG is set. Session-start recall is the sole intentional hook output.

Repository map

  • src/claude_code_memory/ — Claude Code runtime, transcript reader, hooks, recall, MCP server, and CLI.
  • src/substrate_capture/ — frozen shared capture core used by all host plugins.
  • .claude-plugin/ — plugin and self-listing marketplace metadata.
  • .mcp.json — stdio MCP server registration.
  • hooks/hooks.json — Claude Code lifecycle hook registration.
  • commands/ — /substrate-status and /substrate-recall command prompts.
  • tests/ — shared-core and Claude Code host contract tests with synthetic fixtures.
  • scripts/ — shared-core provenance and publication verification tooling.

Development

python -m pip install -e '.[dev]'
python -m pytest tests/ -q
ruff check .

Do not edit src/substrate_capture/ directly. Its digests are shared across host repositories and verified by the test suite.

License

MIT © 2026 Sightline Technologies Inc. See LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选