Skip to content

docs: document Claude Code hook integration in the user guide - #78

Merged
imonroe merged 1 commit into
mainfrom
claude/github-issue-77-9p0rcp
Jul 8, 2026
Merged

docs: document Claude Code hook integration in the user guide#78
imonroe merged 1 commit into
mainfrom
claude/github-issue-77-9p0rcp

Conversation

@imonroe

@imonroe imonroe commented Jul 8, 2026

Copy link
Copy Markdown
Owner

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:

  • Recall — UserPromptSubmit hook (mem0-recall.sh): reads the submitted prompt, semantically searches memserv (POST /api/v1/memories/search), and injects the top matches into Claude's context via additionalContext. At the start of every request, Claude gets any relevant memories.
  • Capture — SessionEnd hook (mem0-capture.sh): flattens the transcript into a messages array and POSTs it to POST /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

  • Both hooks hit the REST API with the bearer token, independent of the MCP connector — they work with or without claude mcp add.
  • The recall hook never blocks the prompt: on missing config, no matches, or an unreachable server it exits 0 with no output. Verified against those edge cases.
  • The capture hook stays "dumb" — it hands the (last 40) turns to memserv and lets the server distill them; re-sends are cheap because memserv fingerprints and skips exact re-adds. Writes are tagged agent_id=claude-code:hook with metadata.source=agent, following the existing provenance convention.
  • Includes settings.json wiring, /hooks + --debug-file verification 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

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
@imonroe
imonroe merged commit 410eb8b into main Jul 8, 2026
1 check passed
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.

Documentation: Support for hooks in Claude Code, etc

2 participants