Three tools, three memories
In this setup three AI tools work on the same projects: Claude Code, Codex and a Hermes agent. Codex reads instruction files such as AGENTS.md, which its project site describes as a README for agents, and was already connected to the shared memory service. Claude Code kept its own small Markdown memory files per project, so decisions recorded there stayed invisible to the other tools.
The goal was simple to state: one current memory that every tool reads at the start and writes to when something durable is decided.
One store, two kinds of bank
The shared store is Hindsight, an open-source memory service for agents released under the MIT licence. It runs on a private server and exposes its operations, such as recall and retain, as an MCP server. Codex and Hermes already used it that way.
Memories are split into banks: one personal bank for preferences that apply everywhere, and one bank per project, named project-<slug>. A few rules keep the store useful across tools: facts are written in English with their source and date, never secrets, never whole transcripts.
Why the hooks talk HTTP
Claude Code can run hooks on events, and a hook can even call an MCP tool directly. But the hooks reference notes that SessionStart fires before the session’s MCP servers are available to hooks. The moment we most needed the memory, at the start of a session, the MCP connection was not there yet.
So the hook script speaks to the memory service itself. The MCP specification defines a Streamable HTTP transport with JSON-RPC messages: initialise, confirm, then call a tool, carrying the session ID the server returns. That is about twenty lines of fetch.
// Simplified: response parsing and error handling omitted.
async function callTool(endpoint, token, name, args) {
let session = null;
let id = 0;
const post = async (body) => {
const headers = {
'content-type': 'application/json',
accept: 'application/json, text/event-stream',
authorization: `Bearer ${token}`,
};
if (session) headers['mcp-session-id'] = session;
const res = await fetch(endpoint, {method: 'POST', headers, body: JSON.stringify(body)});
session ??= res.headers.get('mcp-session-id');
return res;
};
await post({jsonrpc: '2.0', id: ++id, method: 'initialize', params: {
protocolVersion: '2025-03-26', capabilities: {},
clientInfo: {name: 'memory-hook', version: '1.0.0'},
}});
await post({jsonrpc: '2.0', method: 'notifications/initialized'});
return post({jsonrpc: '2.0', id: ++id, method: 'tools/call', params: {name, arguments: args}});
}Two hooks
The SessionStart hook recalls from the personal bank and from the project bank mapped to the current folder, and returns the result as additionalContext, the field the hooks reference describes for passing text into Claude’s context window.
The PostToolUse hook runs after every Write or Edit and ignores everything except Claude Code’s memory files. It is marked async, so a slow write never holds up the session.
{
"hooks": {
"SessionStart": [
{"hooks": [{"type": "command", "timeout": 60,
"command": "node \"$HOME/.claude/hooks/hindsight-sync.mjs\" recall"}]}
],
"PostToolUse": [
{"matcher": "Write|Edit",
"hooks": [{"type": "command", "timeout": 180, "async": true,
"command": "node \"$HOME/.claude/hooks/hindsight-sync.mjs\" retain"}]}
]
}
}Writing without duplicates
Each memory file becomes one document in the store, with a document ID built from the project and the file name. When the file changes, the same document is replaced instead of a new copy being added. User facts go to the personal bank; project decisions go to the project bank.
After writing, the result was checked by reading the document back from the store, not by trusting the hook’s message.
// Called after a write to ~/.claude/projects/<project>/memory/<name>.md
await client.call('sync_retain', {
bank_id: type === 'user' || !projectBank ? 'personal' : projectBank,
content, // the file's description and body, plus a provenance line
document_id: `claude-code-memory:${project}:${name}`, // a rewrite replaces it
tags: ['source:claude-code', `memory-type:${type}`],
metadata: {harness: 'claude-code', memory_name: name, memory_type: type},
});What broke on the first day
The first live write timed out. Retaining in Hindsight waits for the service to extract facts from the text, and that took longer than the 25 seconds the script allowed. Reads stayed fast. The fix was a separate, much longer timeout for writes and running the write hook in the background.
The other mistake was in testing, not in the hook: a hand-written test input passed through the shell turned a Windows path’s backslashes into invalid JSON, and the script quietly fell back to the wrong folder. Feeding real hook payloads, or at least forward-slash paths, made the tests honest.
# first live write, 25-second timeout
Hindsight retain failed: The operation was aborted due to timeout
# after raising the write timeout to 150 s and making the hook async
Hindsight: "feedback-no-ai-sounding-content" -> project-semihekiz-websitesLimits worth knowing
Deleting a memory file does not delete it from the store, and files changed by shell commands rather than the Write or Edit tools are not synced. Recalled memories are evidence, not instructions: anything that may have changed is checked against the current source. And when the store cannot be reached, the hook says so in the session instead of pretending the memory was loaded.
This closes the AI builds series: search over our own writing, a harness that tells us whether changes help, and a memory that every tool shares.