← Back to Plugins
Tools

Openviking Hooks

benediktkraus By benediktkraus 👁 86 views ▲ 0 votes

Production-grade memory hooks for all AI CLI clients (Claude Code, Codex, Gemini CLI, OpenClaw). Hybrid search, 5-scope system, content merge, auto-linking. Fork of Castor6/openviking-plugins.

Homepage GitHub

README

# OpenViking Memory Hooks

Auto-recall + auto-capture hooks for [OpenViking](https://github.com/volcengine/OpenViking). Works with Claude Code, Codex CLI, Gemini CLI, and OpenClaw.

Fork of [Castor6/openviking-plugins](https://github.com/Castor6/openviking-plugins). Added scoping, hybrid search, dedup, and multi-CLI support.

## CLIs

| CLI | Recall | Capture |
|-----|--------|---------|
| Claude Code | UserPromptSubmit | Stop |
| Codex CLI | UserPromptSubmit | Stop |
| Gemini CLI | BeforeAgent | AfterAgent |
| OpenClaw | before_prompt_build | afterTurn |

All share one OV instance, one user, one memory pool. Agent-ID is just a tag.

## How it works

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Claude Code โ”‚  โ”‚  Codex CLI  โ”‚  โ”‚ Gemini CLI  โ”‚  โ”‚  OpenClaw   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                โ”‚                โ”‚                โ”‚
       โ”‚  UserPrompt    โ”‚  UserPrompt    โ”‚  BeforeAgent   โ”‚  before_prompt
       โ–ผ                โ–ผ                โ–ผ                โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     auto-recall.mjs                              โ”‚
โ”‚                                                                  โ”‚
โ”‚  CWD โ”€โ”€โ–บ scope-resolver โ”€โ”€โ–บ 5 target URIs                       โ”‚
โ”‚          โ”‚                                                       โ”‚
โ”‚          โ”œโ”€โ”€โ–บ /search/find (semantic, per scope)  โ”€โ”€โ”            โ”‚
โ”‚          โ””โ”€โ”€โ–บ /search/grep (keywords)             โ”€โ”€โ”ค            โ”‚
โ”‚                                                     โ–ผ            โ”‚
โ”‚                                              RRF Merge           โ”‚
โ”‚                                                     โ”‚            โ”‚
โ”‚                              ranking.mjs โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                              (source authority + backlinks)      โ”‚
โ”‚                                     โ”‚                            โ”‚
โ”‚                              compaction.mjs                      โ”‚
โ”‚                              (~30% token reduction)              โ”‚
โ”‚                                     โ”‚                            โ”‚
โ”‚                              scope hints                         โ”‚
โ”‚                                     โ–ผ                            โ”‚
โ”‚                          <relevant-memories>                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ–ผ                   โ–ผ
              Agent works         On session end
                    โ”‚                   โ”‚
                    โ”‚                   โ–ผ
                    โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚     โ”‚    auto-capture.mjs      โ”‚
                    โ”‚     โ”‚                          โ”‚
                    โ”‚     โ”‚  Content Merge (>0.85?)  โ”‚
                    โ”‚     โ”‚    โ”œโ”€ yes: append         โ”‚
                    โ”‚     โ”‚    โ””โ”€ no: extract new     โ”‚
                    โ”‚     โ”‚                          โ”‚
                    โ”‚     โ”‚  Record Used (feedback)  โ”‚
                    โ”‚     โ”‚  Auto-Link (project)     โ”‚
                    โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚                  โ”‚
                    โ–ผ                  โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚     OpenViking Server        โ”‚
              โ”‚     (localhost:1933)          โ”‚
              โ”‚                              โ”‚
              โ”‚  viking://resources/         โ”‚
              โ”‚    โ”œโ”€โ”€ system/               โ”‚
              โ”‚    โ”œโ”€โ”€ infra/                โ”‚
              โ”‚    โ”œโ”€โ”€ projects/<slug>/      โ”‚
              โ”‚    โ”œโ”€โ”€ knowledge/            โ”‚
              โ”‚    โ””โ”€โ”€ tool-docs/            โ”‚
              โ”‚  viking://user/memories/     โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## What this adds over Castor6

- **Scoping** โ€” 5 scopes (project, system, infra, knowledge, personal), CWD-based
- **Hybrid Search** โ€” semantic + grep + RRF merge
- **Content Merge** โ€” score >0.85 โ†’ append to existing memory instead of duplicate
- **Record Used** โ€” tracks which recalls were useful, ranking improves over time
- **Auto-Linking** โ€” new memories get linked to active project
- **Compaction** โ€” regex-based, ~30% fewer tokens
- **Source Authority** โ€” verified memories rank higher
- **2 extra MCP tools** โ€” `memory_search` (glob/grep), `convert_to_markdown` (markitdown)
- **Session-Start Check** โ€” syncs project context to OV on first visit

## vs Castor6 Original

| | Castor6 | This fork |
|---|---|---|
| CLIs | Claude Code | + Codex, Gemini, OpenClaw |
| Search | Semantic only | + grep + RRF merge |
| Scoping | None | 5 scopes, CWD-based |
| Dedup | None | Content merge (>0.85) |
| Ranking | Score only | + source authority + backlinks |
| Compaction | None | Caveman (~30% reduction) |
| Relations | None | Auto-link to projects |
| Feedback | None | Record Used |
| MCP Tools | 4 | 6 |

## Install

```bash
./install.sh all          # all CLIs
./install.sh claude-code  # just Claude Code
./install.sh codex        # just Codex
./install.sh gemini       # just Gemini
./install.sh openclaw     # just OpenClaw
```

Then edit `~/.openviking/<cli>-memory-plugin/config.json` โ€” set API key, account, user.

## Scopes

| Scope | URI | Active when |
|-------|-----|-------------|
| system | `viking://resources/system/` | Always |
| infra | `viking://resources/infra/` | No project, or infra CWD |
| project | `viking://resources/projects/<slug>/` | CWD in project dir |
| knowledge | `viking://resources/knowledge/` | Always |
| personal | `viking://user/memories/personal/` | Personal projects only |

Config: `shared/scope-config.json`

## Repo structure

```
shared/    โ€” scope-resolver, compaction, scope-config (all CLIs import these)
scripts/   โ€” hook scripts (auto-recall, auto-capture, bootstrap, config, debug)
servers/   โ€” MCP server (6 tools)
hooks/     โ€” hook definitions per CLI
config/    โ€” config templates per CLI (placeholder keys)
src/       โ€” TypeScript source
```

## Config

`~/.openviking/<cli>-memory-plugin/config.json`:

| Field | Default | What |
|-------|---------|------|
| `mode` | `local` | `local` or `remote` |
| `agentId` | `claude-code` | Tag, not namespace |
| `recallLimit` | `10` | Max memories per recall |
| `captureMode` | `semantic` | `semantic` or `keyword` |
| `debug` | `false` | Hook debug logging |

Override shared module path: `export OPENVIKING_HOME=/path/to/.openviking`

## License

Apache-2.0
tools

Comments

Sign in to leave a comment

Loading comments...