docs: document Claude Code hook integration in the user guide - #78
Merged
Conversation
Adds a "Automating memory with Claude Code hooks" section to the User Guide covering deterministic memory recall and capture via Claude Code hooks: - UserPromptSubmit hook (mem0-recall.sh) that searches memserv for memories relevant to each prompt and injects them as additionalContext. Never blocks the prompt: exits quietly on missing config or an unreachable server. - SessionEnd hook (mem0-capture.sh) that flattens the transcript into a messages array and POSTs it to the REST add endpoint, letting memserv's LLM extract durable facts. Tagged agent_id=claude-code:hook, capped at 40 turns. - settings.json wiring, verification/debug steps, and a hooks-vs-prompting comparison that points at the existing auto-capture prompt pack. Closes #77. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XQXUARh5h5hRFg67toenEX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #77.
What
Adds a new "Automating memory with Claude Code hooks" section to
docs/USER_GUIDE.md(plus TOC entries), documenting how to wire memserv into Claude Code hooks so memory recall and capture happen deterministically instead of relying on the model to call a tool.The section covers the exact loop the issue asked for:
UserPromptSubmithook (mem0-recall.sh): reads the submitted prompt, semantically searches memserv (POST /api/v1/memories/search), and injects the top matches into Claude's context viaadditionalContext. At the start of every request, Claude gets any relevant memories.SessionEndhook (mem0-capture.sh): flattens the transcript into amessagesarray and POSTs it toPOST /api/v1/memories, letting memserv's own LLM extract the durable facts. At the end of a conversation, the memory store is updated.Design notes
claude mcp add.0with no output. Verified against those edge cases.agent_id=claude-code:hookwithmetadata.source=agent, following the existing provenance convention.settings.jsonwiring,/hooks+--debug-fileverification steps, and a hooks vs. prompting comparison table that points users at the existing auto-capture prompt pack for cleaner, model-selected capture.Verification
Docs-only change (no server/code behavior touched). The
jq/shell logic in both scripts was exercised locally against sample payloads: recall formatting, empty/absent results, no-config exit, unreachable-server exit, and transcript flattening (string vs. block content, dropping non-text/system turns).🤖 Generated with Claude Code
Generated by Claude Code