Persistent 5-level hierarchical memory for AI agents. SQLite-backed, lazy-loaded.
io.github.Bumblebiber/hmem-mcp — Model Context Protocol (MCP) Server
This MCP server provides persistent, 5-level hierarchical memory for AI agents. It is SQLite-backed and lazy-loaded, and is designed to retain project-relevant information across sessions. The README describes a single load_project() call with an approximate ~3000-token footprint.
🛠️ Key Features
Persistent 5-level hierarchical memory
SQLite-backed storage
Lazy-loaded behavior
load_project() for loading project context
🚀 Use Cases
Maintaining knowledge about a project across sessions
Tracking past mistakes, decisions, and open tasks
Using the same context across devices and AI providers
⚡ Developer Benefits
Avoids re-reading project content per conversation
Reduces per-conversation setup (described as “No setup per conversation”)
⚠️ Limitations
README excerpt provides no further details on configuration options, supported operations, or token limits beyond the ~3000 tokens for load_project().
Your AI forgets everything between sessions. hmem fixes that.
One load_project() call. ~3000 tokens. Your agent knows everything important about a project — every past mistake, every decision, every open task — across sessions, devices, and AI providers. No setup per conversation. No "let me re-read the codebase." It just remembers.
AI agent? Skip this file. Read AGENT_SETUP.md — written for you, not for humans.
Naming note (v8.0): This package was briefly published as its-over-9k (1.x). It is now hmem again — pure memory framework, nothing else. The its-over-9k name lives on as a separate project: the o9k token-efficiency meta-framework, which combines skills/plugins like this one. Related: TIM — hmem's next-generation successor (hypergraph memory, CRDT sync).
What This Is
hmem is not a note-taking plugin. It's a memory framework for AI agents — a complete infrastructure layer for persistent, portable, token-efficient knowledge that survives session boundaries, device switches, and provider changes.
Four core guarantees:
Pillar
What it means
Token efficiency
5-level lazy loading — you pay for what you read, never more
Portability
Same memory across Claude, Gemini, GPT, local models, any MCP client
Efficient storage
Hierarchical tree structure — context scales with depth, not flat append
No context waste
Auto-session capture + project briefing = zero re-read overhead
The Problem
Every AI session starts from zero. Your agent asks the same questions, makes the same mistakes, contradicts last week's decisions, and wastes 50k tokens loading context it already processed yesterday.
You've tried workarounds — CLAUDE.md files, custom prompts, manually pasting context. They don't scale. You have 10 projects. You switch between 3 devices. You use different AI tools.
That's it. 3000 tokens for a complete project briefing. The agent knows the stack, the architecture, the open bugs, the recent decisions, and exactly where you left off — even if "you" was a different AI on a different machine yesterday.
How It Works
code
Level 1 ── One-line summary (always loaded — ~5k tokens for 300+ entries)
Level 2 ── Paragraph detail (loaded on demand)
Level 3 ── Full context (loaded on demand)
Level 4 ── Extended detail (loaded on demand)
Level 5 ── Raw/verbatim data (loaded on demand)
At session start, the agent loads Level 1 summaries — one line per memory. When it needs detail, it drills down. Your 300-entry memory costs 5k tokens to overview. A single project costs ~3000 tokens.
Nothing is summarized away. Level 1 is a compressed view, but Levels 2–5 hold the complete original text, word for word, accessible on demand.
Framework Features
Automatic Session Memory
Every conversation is recorded automatically. No "save your work" prompts. No manual checkpoints.
code
You type → Agent responds → Stop hook fires → Exchange saved to O-entry
→ Linked to active project
→ Haiku auto-titles the session
Switch projects mid-session? The O-entry switches too. Start a new session on a different device? The next agent sees every exchange from every device — the conversation never dies.
Haiku Background Checkpoints
Every N exchanges (configurable, default 5), a Haiku subagent wakes up in the background. It reads the recent conversation, extracts lessons learned, errors encountered, and decisions made, then writes them to long-term memory — with full MCP tool access. Your main agent is never interrupted.
The checkpoint also writes a handoff note to the project: "Here's what was done, here's what's in progress, here's the next step." The next agent — on any device, any provider — picks up exactly where you left off.
Project-Based, Not Session-Based
Sessions are meaningless. Projects are everything.
O-entries are linked to the active project, not the session
Checkpoint counters count project exchanges, not session messages
load_project shows recent conversations with full context — across all devices
Skills System
hmem ships with a complete skills layer — structured behavior files that agents load on demand. Skills define how an agent should do something (debug, write memory, curate entries, handle a session start) — separate from memory, separate from prompts.
bash
npx hmem update-skills # Pull latest skills to your AI tool's skill directory
Skills are versioned and updated independently. Your agents get smarter without reinstalling. 21 skills ship by default:
Skill
Triggers when…
hmem-session-start
Every session start — loads project + surfaces pending git work, open tasks, misrouted O-entries
hmem-using-hmem
Meta-skill loaded at session start; defines mandatory memory habits
hmem-read
Reading from long-term memory (search, prefix filter, find_related, cross-project read)
hmem-write
Writing to hmem — picks prefix, tree location, tags, detects duplicates
hmem-search
User references something without an ID ("the bug we had", "letzte Woche")
hmem-new-project
Creating a P-entry — handles schema, sections, O-entry linking
hmem-new-error
Creating an E-entry with the strict 5-level scaffold
hmem-activate
Switching active project mid-session, plus fixing misrouted exchanges
hmem-context
Loading specific context when load_project output isn't enough
hmem-recall
Dispatching a Haiku sub-agent to search hmem
hmem-dispatch
Dispatching an isolated sub-agent for any search/lookup/calculation
hmem-curate
Cleaning up an .hmem file (mark obsolete, fix titles, consolidate dupes)
hmem-migrate-o
Migrating O-entries to the project-bound 5-level structure
hmem-consolidate
Merging session checkpoint summaries into one final O-entry summary
hmem-wipe
Prep for /clear — save high-value knowledge, update Next Steps
Template for sub-agents dispatched by hmem-dispatch
Company Memory
Beyond personal memory, agents can maintain a shared company store — a separate company.hmem that multiple agents and team members can read from. Personal and company memory coexist; agents query both simultaneously.
typescript
import { openCompanyMemory } from'hmem';
const store = openCompanyMemory('/path/to/project');
Embeddable SDK
hmem ships as a fully documented TypeScript SDK — import HmemStore directly into your own agents, tools, or automation pipelines:
Import a JSON snapshot back into a .hmem (destructive)
update_many
Bulk-patch a set of entries (irrelevant, tags, body, etc.)
tag_bulk
Add/remove a tag across many entries
tag_rename
Rename a tag globally across all entries
move_memory
Move an entire entry to a new ID slot
move_nodes
Move a subtree under a different parent (also in main server)
rename_id
Rename an entry's ID; rewrites all inbound links
reset_memory_cache
Invalidate the in-memory L1 cache (after raw SQL writes)
The daily hmem server is registered automatically by hmem init. hmem-curate is opt-in because its tools are destructive — register it when you need to curate:
code
npx hmem mcp-add-curate # adds the curate server to Claude Code (user scope)
Then toggle it via /mcp only during curation sessions. For other MCP clients, see Manual setup.
CLI Commands
After npm install -g hmem-mcp, the hmem binary is on PATH.
158 spurious O-entries created when Haiku MCP lacked HMEM_NO_SESSION guard
D
Decision
Project-based O-entries over session-based — sessions are meaningless
M
Milestone
v1.0.0 — package renamed to hmem, npm rebrand complete
S
Skill
Skill: TypeScript debugging with source maps
N
Navigator
High-level navigation entry (table of contents for a topic)
H
Human
User Skill: TypeScript 9, Architecture 9, React 3
R
Rule
Max one npm publish per day — batch changes
O
Original
Auto-recorded conversation history (every exchange, every device)
I
Infrastructure
Strato Server | Active | Linux | Ubuntu 22.04
C
Convention
Tag scheme: lowercase, prefer existing tags before inventing
Add custom prefixes (e.g. A for App, F for Function reference) by listing them under prefixes in hmem.config.json — they show up in read_memory({ prefix: "X" }) filters automatically.
Quick Start
1. Install
bash
npm install -g hmem-mcp
2. Run the interactive installer
bash
npx hmem init
Detects your AI tools, creates the memory directory, configures MCP, and installs all hooks:
Hook
When
What
UserPromptSubmit
Every message
First message: load memory overview. Every Nth: checkpoint reminder
"auto" = background agent writes L/D/E. "remind" = prompts the main agent
checkpointInterval
5
Exchanges between checkpoints. 0 = disabled
checkpointProvider
"anthropic"
"anthropic" or "openai" (any OpenAI-compatible: DeepSeek, Groq, …)
checkpointModel
"claude-haiku-4-5-20251001"
Model name for the configured provider
checkpointBaseUrl
—
OpenAI-compatible base URL (e.g. https://api.deepseek.com/v1)
checkpointApiKeyEnv
provider default
Env var holding the API key. Defaults: ANTHROPIC_API_KEY or OPENAI_API_KEY
recentOEntries
10
How many recent sessions to show in load_project
prefixes
built-in
Add custom entry types
All keys are optional. Missing keys use defaults.
Checkpoint setup per harness
The auto-checkpoint agent runs in the background after every Nth exchange. It needs an LLM call — three paths, picked automatically:
API key in environment (any harness) → direct provider API loop. Configure checkpointProvider + checkpointModel + checkpointApiKeyEnv in hmem.config.json. Works from Pi, Hermes, OpenCode, and Claude Code.
No API key, but claude CLI in PATH → subprocess fallback (claude -p). Zero-config for Claude Code / Claude Max users.
Neither → checkpoint fails with a config-hint error.
Recommended cheap setup (DeepSeek, ~10× cheaper than Haiku):
Then export DEEPSEEK_API_KEY=sk-... in your shell profile. Works for any harness.
Claude Code / Claude Max (zero-config): no provider settings needed — the subprocess fallback uses your existing claude login.
Per-harness exchange logging: Claude Code uses Stop hooks (installed by npx hmem init). Pi uses the built-in extension (src/extensions/pi-hmem.ts). Hermes needs the hermes-hmem plugin (see plugins/hermes-hmem/README.md). OpenCode uses the same hook system as Claude Code.
⚠ Pi users: Hook-based exchange logging is currently not working in the Pi runtime. Exchanges are not saved to O-entries automatically. Manual checkpointing via hmem checkpoint is the workaround until this is resolved.
Cross-Device Sync
Sync memories across all devices with zero-knowledge AES-256-GCM encryption.
On Windows with Git for Windows, Claude Code routes hook and statusLine commands through Git Bash by default. Git Bash's MSYS2 runtime crashes transiently at startup, killing the command before it runs.
Fix: add "shell": "powershell" to every hook command and to statusLine in ~/.claude/settings.json.