janbjorge/rekal
À propos
Long-term memory for LLMs. MCP server backed by hybrid search in a single SQLite file.
IA et apprentissage automatiqueWhat you can do
- rekal computes embeddings locally, so it needs no cloud service or API key. Its only network call is a one-time download of the embedding model.
- Each recall blends BM25 keyword match, vector similarity, and recency into one score, so exact identifiers and paraphrased questions both find the right memory.
- The MCP surface is three tools, which keeps tool schemas cheap in the agent's context. Admin tasks live in the CLI.
- Any MCP client works, including Claude Code, Codex CLI, OpenCode, and Cursor.
Progression mesurée des étoiles
- in 24h
- 0
- in 7 days
- Historique en cours
- in 15 days
- Historique en cours
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
Originalrekal
Long-term memory for AI coding agents, stored in one SQLite file on your machine.
rekal is an MCP server. As your agent works, it stores durable facts in rekal, such as your preferences, decisions about the project, and things it took effort to find out. In later sessions, rekal recalls the facts that match the current task.
Session 1 You: I prefer Ruff over Black.
Agent: memory_store("User prefers Ruff over Black for linting and formatting")
Session 47 You: Set up linting for this repo.
rekal: recalls "User prefers Ruff over Black for linting and formatting"
Agent: sets up Ruff without asking.
Highlights
- rekal computes embeddings locally, so it needs no cloud service or API key. Its only network call is a one-time download of the embedding model.
- Each recall blends BM25 keyword match, vector similarity, and recency into one score, so exact identifiers and paraphrased questions both find the right memory.
- The MCP surface is three tools, which keeps tool schemas cheap in the agent's context. Admin tasks live in the CLI.
- Any MCP client works, including Claude Code, Codex CLI, OpenCode, and Cursor.
- In Claude Code, a plugin injects matching memories into every prompt and saves durable facts before compaction and at session end.
Install
uv tool install rekal # or: pip install rekal
rekal needs Python 3.11 or newer. It creates ~/.rekal/memory.db on first run, and downloads the embedding model (about 67 MB) into ~/.rekal/models the first time it embeds text.
Set up Claude Code
claude mcp add --scope user rekal -- rekal mcp # register the MCP server for all projects
claude plugin marketplace add janbjorge/rekal # add the plugin marketplace
claude plugin install rekal-skills@rekal # install the plugin's hooks and skills
Then add "autoMemoryEnabled": false to ~/.claude/settings.json and restart Claude Code:
{
"autoMemoryEnabled": false
}
Without --scope user, Claude Code registers the server in local scope, which loads it only in the project where you ran the command (MCP scopes).
The plugin's hooks run rekal through uvx, so uv must be on your PATH even if you installed rekal with pip.
Claude Code's built-in auto memory (settings) loads its own notes into the context (context window), and the agent tends to favor them over rekal. Those notes are a flat file that cannot be searched, deduplicated, or ranked. The plugin cannot turn this setting off for you, because a plugin's settings can only set agent and subagentStatusLine (plugins). If you leave it on, the plugin's PreToolUse hooks still steer the agent back to rekal, but every redirect costs a turn.
What the plugin does
| Hook | What it does |
|---|---|
SessionStart |
Tells the agent that memory lives only in rekal. Injects no memories yet, because there is no prompt to match. |
UserPromptSubmit |
Recalls memories that match your prompt and injects the best hits under ## rekal memory. |
PreCompact |
Before an automatic compaction, runs an agent hook that saves durable facts from the conversation. |
SessionEnd |
Starts a detached, headless claude -p that saves durable facts from the transcript. It can read only the transcript's folder and call memory_build_context and memory_store, stops after 25 turns, and counts toward your Claude usage. |
PreToolUse |
Denies reads and writes of MEMORY.md, MEMORIES.md, and their .txt variants, and points the agent to rekal instead. |
The hooks run the released rekal from PyPI with uvx --from rekal==<version>, pinned to the version the plugin was released with. uvx caches that environment after the first fetch (uv tools), so later runs need no network. A failed fetch, for example when you are offline on first use, never blocks the session; the hook tries again on the next event. If the database is missing or no memory clears the relevance floor, the hook injects only the directive.
| Skill | What it does |
|---|---|
/rekal-init |
Scans the codebase and seeds rekal with project knowledge. |
/rekal-save |
Stores durable knowledge from the conversation, updating existing memories instead of adding duplicates. The PreCompact and SessionEnd hooks run the same procedure. |
/rekal-usage |
Explains when and how to call each rekal tool. |
/rekal-hygiene |
Finds conflicting, duplicate, and stale memories and proposes fixes. |
Set up Codex CLI, OpenCode, or Cursor
rekal ships hooks only for Claude Code, so with other agents nothing recalls memory automatically. Tell the agent to do it by adding this line to your project's AGENTS.md:
Call memory_build_context with your current task before exploring the codebase.
Then register the server with your agent. The examples set REKAL_PROJECT to scope memories to one project; leave it out for global memory.
Codex CLI
Add to ~/.codex/config.toml (Codex MCP docs):
[mcp_servers.rekal]
command = "rekal"
args = ["mcp"]
[mcp_servers.rekal.env]
REKAL_PROJECT = "my-project"
Codex memories are off by default (Codex memories). If you turned them on, turn them off so the two memory systems do not compete:
[features]
memories = false
OpenCode
Add to opencode.jsonc in your project root (OpenCode MCP docs):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"rekal": {
"type": "local",
"command": ["rekal", "mcp"],
"enabled": true,
"environment": {
"REKAL_PROJECT": "my-project"
}
}
}
}
OpenCode reads AGENTS.md from the project root without extra config (OpenCode rules), and it has no built-in memory to turn off.
Cursor
Add to ~/.cursor/mcp.json for all projects, or to .cursor/mcp.json for one project (Cursor MCP docs). The Cursor CLI reads the same file, so this sets up both the editor and the CLI (Cursor CLI MCP docs).
{
"mcpServers": {
"rekal": {
"command": "rekal",
"args": ["mcp"],
"env": {
"REKAL_PROJECT": "my-project"
}
}
}
}
Enable the server in the CLI and check that it loaded:
agent mcp enable rekal
agent mcp list
Cursor has no competing memory to turn off.
MCP tools
| Tool | What it does |
|---|---|
memory_build_context |
Searches stored memories with hybrid ranking and drops results below min_score (default 0.0625). The floor ignores age, so an old memory that matches the query still comes back. |
memory_store |
Stores one memory with optional tags, scoped to REKAL_PROJECT unless the agent passes project. Pass replaces=<old_id> to update a memory instead of adding a near-duplicate. |
memory_delete |
Deletes a memory by ID. |
The server registers only memory_build_context when REKAL_READONLY=1 is set or when the database file exists but is not writable. In that mode, the memory block the hook injects also points the agent to rekal recall --query, so it can recall more from the shell.
CLI
| Command | What it does |
|---|---|
rekal mcp |
Runs the stdio MCP server. Your agent starts it. |
rekal recall |
Prints memories in the form the hook injects: the best matches for --query, or the most recent ones without it. Also takes --project, --limit, and --format json. |
rekal health |
Prints database stats: total memories, counts per project, and the date range. |
rekal export |
Dumps all memories as JSON. |
rekal prune |
Deletes memories in bulk by project or age. |
rekal prune needs at least one filter: --project NAME, --older-than-days N, or --before "YYYY-MM-DD HH:MM:SS" (UTC unless you give an offset). Without --yes it only reports how many memories match.
The commands read $REKAL_DB_PATH, falling back to ~/.rekal/memory.db. To point recall, health, export, or prune at another file, run rekal --db PATH <command>.
Configuration
Environment variables
| Variable | Default | Effect |
|---|---|---|
REKAL_DB_PATH |
~/.rekal/memory.db |
Database file. |
REKAL_PROJECT |
unset | Default project scope for storing and recalling memories. |
REKAL_READONLY |
unset | 1 registers only memory_build_context. |
REKAL_MIN_RELEVANCE |
0.0625 |
Relevance floor for hook injection; 0 turns it off. Overrides min_relevance in .rekal/config.yml. |
FASTEMBED_CACHE_PATH |
~/.rekal/models |
Embedding model cache. |
In Claude Code, set REKAL_PROJECT and REKAL_DB_PATH in your shell or in the env block of Claude Code's settings.json. Values in the MCP server's env block reach only the server process. The hooks run as separate processes, so they would read a different database or project than the tools.
Ranking
rekal reads .rekal/config.yml from the working directory, normally your project root, so you can commit ranking settings with the project. Every key is optional, and a missing key keeps its default. The defaults are:
scoring:
w_fts: 0.4 # keyword (BM25) weight
w_vec: 0.4 # vector similarity weight
w_recency: 0.2 # recency weight
half_life: 30.0 # days until the recency signal halves; must be above 0
min_relevance: 0.0625 # floor for hook injection; 0 turns it off
If the file does not parse or a value is invalid, rekal ignores the whole file and uses the defaults.
min_relevance applies only to the keyword and vector part of the score, so recency cannot lift a weak match into your context. When the best match is below the floor, the hook injects no memories. CALIBRATION.md explains how the default was chosen. docs/scoring.md is the full ranking reference, with a tuning guide.
How it works
Everything lives in one SQLite file. Each memory is a row with its content, project, tags, and timestamps. rekal indexes it twice: in an FTS5 table for BM25 keyword search, and in a sqlite-vec table as a 384-dimension embedding. fastembed computes the embeddings locally with BAAI/bge-small-en-v1.5 on ONNX.
A recall runs a keyword lookup and a vector lookup, merges the candidates, and scores each one:
score = 0.4 × (1 - e^bm25) keyword match (FTS5 BM25, normalized to 0..1)
+ 0.4 × (1 - L2 distance) semantic similarity
+ 0.2 × exp(-0.693 × days / 30) recency, halving every 30 days
Keywords catch exact identifiers that embeddings blur, and embeddings catch paraphrases such as "deploy" and "ship to prod". The recency weight is low enough that an old memory still ranks when it matches well.
memory_store(replaces=<id>) writes the new memory and deletes the old one in one step, so each topic keeps a single current version.
SQLite runs inside the rekal process, and FTS5 and sqlite-vec search within it, so there is no database server or separate vector database to run. To back up your memory, copy the file. To start over, delete it, and rekal creates a new one on the next run.
docs/data-model.md describes the schema and the migration from older versions.
Updating
Upgrade rekal, then restart your agent so it starts the new server:
uv tool upgrade rekal # or: pip install -U rekal
The schema migrates in place on the next start and keeps your memories, so you never run a migration by hand.
Update the Claude Code plugin as well, since its hooks run the rekal version the plugin pins. Third-party marketplaces do not auto-update by default (auto-updates), so refresh it by hand:
claude plugin marketplace update rekal
claude plugin install rekal-skills@rekal
If hooks or skills are still missing afterwards, Claude Code is serving a stale plugin cache. Clear it, restart Claude Code, and install the plugin again (common issues):
rm -rf ~/.claude/plugins/cache
Troubleshooting
The agent still writes to MEMORY.md
Check that autoMemoryEnabled is false in ~/.claude/settings.json, and that claude plugin list shows rekal-skills.
No memories show up in Claude Code
Memories arrive with your first prompt, not at session start, and only when one clears the relevance floor. Run rekal recall --query "<your prompt>" to see what the hook would inject. If that prints memories but the session gets none, check that uv is on the PATH that Claude Code's hooks see, and that REKAL_PROJECT and REKAL_DB_PATH are set where the hooks can read them (see Environment variables).
Memories are not stored
claude mcp list should show rekal. If it does not, run the claude mcp add command from Set up Claude Code again.
Hooks or skills are missing after a plugin update
Clear the plugin cache as described in Updating.
Contributing
AGENTS.md covers the architecture, the code rules, and the checks CI runs. The token-savings benchmark lives in benchmarks/.
License
Explorer des projets similaires
Chargement…