Skip to content

Comments

feat: add Claude Code memory hooks example#247

Open
ZaynJarvis wants to merge 4 commits intovolcengine:mainfrom
ZaynJarvis:example/claude-code-hooks
Open

feat: add Claude Code memory hooks example#247
ZaynJarvis wants to merge 4 commits intovolcengine:mainfrom
ZaynJarvis:example/claude-code-hooks

Conversation

@ZaynJarvis
Copy link
Collaborator

@ZaynJarvis ZaynJarvis commented Feb 22, 2026

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:

Hook Trigger Method
SubagentStop Subagent finishes ov add-memory (one-shot)
PreCompact Before context compaction ov add-memory (one-shot)
SessionEnd Session terminates ov session newadd-message × N → commit

All hooks run async: true so they don't block Claude Code responses.

Files

  • examples/claude-code-hooks/README.md — Setup guide and documentation
  • examples/claude-code-hooks/hooks/ov-memory-subagent-stop.sh
  • examples/claude-code-hooks/hooks/ov-memory-pre-compact.sh
  • examples/claude-code-hooks/hooks/ov-memory-session-end.sh

Testing

Tested all three hooks locally with mock Claude Code JSONL transcripts. Memory extraction confirmed working via ov add-memory and ov session workflow.

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.
@ZaynJarvis ZaynJarvis changed the title WIP: feat: add Claude Code memory hooks example feat: add Claude Code memory hooks example Feb 22, 2026
@ZaynJarvis
Copy link
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.

ZaynJarvis and others added 2 commits February 22, 2026 22:28
…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>
@ZaynJarvis ZaynJarvis marked this pull request as ready for review February 23, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant