Skip to content

[good first issue-platform adapt-Claude Code] Add native Memory plugin for Claude Code (hooks + MCP, no proxy) - #1268

Open
plainwuatlig wants to merge 1 commit into
TencentCloud:feat/server_teamfrom
plainwuatlig:feat/claude-code-plugin
Open

[good first issue-platform adapt-Claude Code] Add native Memory plugin for Claude Code (hooks + MCP, no proxy)#1268
plainwuatlig wants to merge 1 commit into
TencentCloud:feat/server_teamfrom
plainwuatlig:feat/claude-code-plugin

Conversation

@plainwuatlig

Copy link
Copy Markdown

Description | 描述

Adds MemoryCore/claude-code-plugin/: a native Claude Code client for Memory Gateway /v3/*, in the same shape as the OpenClaw client adapter (MemoryCore/openclaw-plugin/): a pure client over @tencentdb-agent-memory/memory-sdk-ts-v2, no extraction or storage, and no LLM-traffic proxy. Claude Code keeps talking to Anthropic directly; memory arrives through Claude Code's own lifecycle hooks and a stdio MCP server. It sits beside the existing proxy route (agents/claude-code/) as the choice for teams that do not want to move model traffic, keys, or billing to the proxy.

新增 MemoryCore/claude-code-plugin/:Memory Gateway /v3/*原生 Claude Code 客户端,形态与 OpenClaw 客户端适配器一致——基于 @tencentdb-agent-memory/memory-sdk-ts-v2 的纯客户端,不做抽取和存储,不经过 LLM 流量代理。Claude Code 仍直连 Anthropic;记忆通过 Claude Code 自身的生命周期 Hook 与一个 stdio MCP server 接入。与现有代理路线(agents/claude-code/)并列,供不希望把模型流量、密钥与计费转到代理的团队选用。

Hooks (one process per event; state shared via hashed files in a state dir)

  • UserPromptSubmit: searchAtomic for the prompt on every turn; readCore + listScenarios once per session; injected as additionalContext (<user-persona>, <scene-navigation>, <relevant-memories>, tool guide). A total Gateway outage injects nothing.
  • Stop: the finished turn is read from the transcript named by transcript_path (fallback: the Claude Code projects directory) and sent as one addConversation: prompt, tool calls, tool results, intermediate and final text. Thinking/images dropped; tool traffic quoted with size caps; 8192-char chunks; 100 messages per batch. Credential-shaped substrings are redacted before sending (tool traffic carries env dumps and config files). Falls back to prompt + reply when no transcript can be read. Skipped while background_tasks / session_crons are present.
  • SessionEnd: whatever transcript remains unsent. A failed batch leaves the marker at the last batch that landed and the turn unclaimed, so a later hook sends the rest.

MCP server (stdio): tdai_memory_search, tdai_conversation_search, tdai_scenario_read, tdai_memory_capture (a milestone in the agent's own words), and, when TDAI_KNOWLEDGE_URL is set, tdai_wiki_list / search / pages / read / write against the Knowledge Service /v3/wiki API. Wiki ids are always tool parameters; identity comes from TDAI_* env; the plugin carries no organisation-specific content.

Docs: bilingual README.md / README_CN.md, integrations/hooks.json, integrations/mcp.json.example; one row added to the agent tables in INSTALL.md / INSTALL_CN.md.

Related Issue | 关联 Issue

#926 (Adapters Wanted, Claude Code native route). Complements #1126's proxy route for Pi and agents/claude-code/ for Claude Code rather than replacing them.

Change Type | 修改类型

  • Bug fix | Bug 修复
  • New feature | 新功能
  • Documentation update | 文档更新
  • Code optimization | 代码优化

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过 — npm run typecheck, npm run build, npm test (17 vitest tests: transcript normalisation and redaction, hook flows incl. partial failure and retry, MCP round-trips, Knowledge client envelopes). Live against a running Gateway + Knowledge Service: first-prompt recall 178 ms with persona/guide/L1, second prompt L1 only; Stop sent the turn in 346 ms with the secret redacted; queryConversation read back all four messages; MCP server lists 9 tools and returns real wiki and memory hits.
  • No existing features affected | 无影响现有功能 — new directory only; two table rows in the install guides.

Additional Notes | 其他说明

Design choices worth a reviewer's eye: (1) per-turn capture at Stop rather than only at SessionEnd, because a 100-message batch costs the Gateway a few seconds and a session's SessionEnd fires once, so end-only capture loses the tail of long sessions; (2) redaction on the client, because the Gateway records what it is sent; (3) the MCP wiki tools include wiki_write, which MemoryKnowledge's own MCP server does not yet expose — happy to move that there instead if preferred.

Commit is DCO signed-off.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EkVfNqVBnTAHnc62NUieKj

… no proxy)

Adds MemoryCore/claude-code-plugin, a pure v3 client for Claude Code in the
shape of the OpenClaw client adapter: lifecycle hooks plus a stdio MCP server
over @tencentdb-agent-memory/memory-sdk-ts-v2. Claude Code keeps talking to
Anthropic directly; nothing is routed through the proxy.

Hooks (one process per event, state shared via hashed files):
- UserPromptSubmit: searchAtomic for the prompt every time; readCore and
  listScenarios once per session; injected as additionalContext with a short
  guide to the MCP tools. A total Gateway outage injects nothing.
- Stop: the finished turn is read from the transcript named by transcript_path
  (fallback: the Claude Code projects directory) and sent as one
  addConversation: prompt, tool calls, tool results, intermediate and final
  text. Thinking and images dropped, tool traffic quoted with size caps,
  8192-char chunks, 100 messages per batch. Credential-shaped substrings are
  redacted before sending. Falls back to prompt + reply when no transcript
  can be read. Skipped while background tasks or session crons are present.
- SessionEnd: whatever transcript remains unsent. A failed batch leaves the
  marker at the last batch that landed and the turn unclaimed, so a later
  hook sends the rest.

MCP server: tdai_memory_search, tdai_conversation_search, tdai_scenario_read,
tdai_memory_capture (a milestone in the agent's own words), and, when
TDAI_KNOWLEDGE_URL is set, tdai_wiki_list/search/pages/read/write against the
Knowledge Service /v3/wiki API. Wiki ids are always parameters; identity
comes from TDAI_* env; the plugin carries no organisation content.

Verified against a running Gateway and Knowledge Service: first-prompt
recall 178 ms, Stop turn capture 346 ms with the secret redacted, L0 read-back
shows all four messages; MCP server lists 9 tools and returns real hits.
17 vitest tests. Bilingual README; rows added to INSTALL.md / INSTALL_CN.md.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EkVfNqVBnTAHnc62NUieKj
Signed-off-by: Plain Wu <plain.wu@lig.com.tw>
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you so much for your attention and contribution! We will arrange an internal review for this PR shortly, and all feedback will be shared right here in the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants