feat: add Claude Code memory hooks example#247
Open
ZaynJarvis wants to merge 4 commits intovolcengine:mainfrom
Open
feat: add Claude Code memory hooks example#247ZaynJarvis wants to merge 4 commits intovolcengine:mainfrom
ZaynJarvis wants to merge 4 commits intovolcengine:mainfrom
Conversation
Add example showing how to auto-extract memories from Claude Code sessions into OpenViking using Claude Code's hook system. Three hooks capture conversation transcripts at strategic lifecycle points: - SubagentStop: when subagents finish focused work - PreCompact: before context window compaction loses details - SessionEnd: full session archival with structured ov session workflow All hooks run async to avoid blocking Claude Code responses.
Claude Code kills async hook processes when the session ends. ov add-memory and ov session commit take ~30s (LLM extraction), so they need to be backgrounded with nohup to complete. Also removed set -euo pipefail to avoid silent failures.
Collaborator
Author
|
if use session add-message for each message, there might be too much C-S overhead, hence using add-memory with all message is the method i use for pre-compact and subagent-end. while ov session add-message is still a way, hence, keeping it as a reference. |
…ode headers, and Hooks.md reference - Add OV_HOOK_DEBUG=1 gating — all logging is silent by default, opt-in via env var - Consolidate logs to single /tmp/ov.log (was split between ov-hooks.log and hooks.md) - Add pseudocode + special cases comment block to each hook script - Add _log/_logcmd/_trunc helpers; truncate message content to 120 chars (unicode-safe) in logs only - Add Hooks.md: quick reference for all 17 Claude Code hook events and their stdin params - Rewrite README: how hooks work (stdin JSON), add-memory vs session workflow rationale, debug instructions, extending guide Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Add example showing how to auto-extract memories from Claude Code sessions into OpenViking using Claude Code hooks.
What's included
Three hook scripts that capture conversation transcripts at strategic lifecycle points:
SubagentStopov add-memory(one-shot)PreCompactov add-memory(one-shot)SessionEndov session new→add-message× N →commitAll hooks run
async: trueso they don't block Claude Code responses.Files
examples/claude-code-hooks/README.md— Setup guide and documentationexamples/claude-code-hooks/hooks/ov-memory-subagent-stop.shexamples/claude-code-hooks/hooks/ov-memory-pre-compact.shexamples/claude-code-hooks/hooks/ov-memory-session-end.shTesting
Tested all three hooks locally with mock Claude Code JSONL transcripts. Memory extraction confirmed working via
ov add-memoryandov sessionworkflow.