hmem — Humanlike Memory for AI Agents

AI 与智能体

by bumblebiber

为 AI agents 提供持久化的 5 层分级记忆,基于 SQLite 存储,并支持 lazy-loaded 按需加载。

什么是 hmem — Humanlike Memory for AI Agents

为 AI agents 提供持久化的 5 层分级记忆,基于 SQLite 存储,并支持 lazy-loaded 按需加载。

README

hmem — Humanlike Memory for AI Agents

Your AI forgets everything between sessions. hmem fixes that.

One read_memory() call. 5k tokens. Your agent knows every project, every past mistake, every decision you ever made together — across sessions, devices, and AI providers. No setup per conversation. No "let me re-read the codebase." It just remembers.


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.

The Solution

code
You:    "Load project hmem"
Agent:  [calls load_project("P0048") — 700 tokens]
Agent:  "Got it. v5.0.0, TypeScript/SQLite/npm, 10 source files,
         3 open tasks, 9 ideas. Last session you implemented
         auto-checkpoints via Haiku. What's next?"

That's it. 700 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 700.

Nothing is summarized away. Level 1 is a summary, but Levels 2-5 hold the complete original text, word for word, accessible on demand.


What Makes v5 Different

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 PC? The next agent sees every exchange from every device — the conversation never dies.

Haiku Background Checkpoints

Every 20 exchanges, 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
  • 10 messages on your laptop + 10 on your server = checkpoint fires on message 20
  • load_project shows recent conversations with full context — across all devices

Key Features

FeatureWhat it does
5-level lazy loadingTokens scale with need, not memory size
Smart bulk readsExpands newest + most-accessed; compresses the rest to titles
Project gateActivate a project — only relevant memories are expanded
Duplicate detectionWarns before creating entries that already exist
Encrypted syncAES-256-GCM, zero-knowledge server, multi-server redundancy
Auto-loggingEvery exchange recorded via Stop hook (O-prefix)
Auto-checkpointHaiku extracts L/D/E entries every N exchanges
Project handoffBackground agent maintains "current state" in Protocol section
User skill trackingAgents track your expertise (1-10) and adapt communication
HashtagsCross-cutting tags for discovery across all categories
Obsolete chainsMark entries wrong with correction reference — auto-follows
Cross-providerClaude, Gemini, GPT, DeepSeek, local models — same memory
Cross-toolClaude Code, Gemini CLI, Cursor, Windsurf, OpenCode, Cline
Import/ExportShare memories between agents or back up as Markdown

Categories

PrefixCategoryExample
PProjecthmem-mcp | Active | TS/SQLite/npm | Persistent AI memory
LLessonHMEM_AGENT_ID must be set in hooks — resolveHmemPath falls back to wrong DB
EError158 spurious O-entries created when Haiku MCP lacked HMEM_NO_SESSION guard
DDecisionProject-based O-entries over session-based — sessions are meaningless
HHumanUser Skill: TypeScript 9, Architecture 9, React 3
RRuleMax one npm publish per day — batch changes
OOriginalAuto-recorded conversation history (every exchange, every device)
IInfraStrato Server | Active | Linux | 87.106.22.11

Quick Start

1. Install

bash
npm install -g hmem-mcp

2. Run the interactive installer

bash
npx hmem init

This detects your AI tools, creates the memory directory, configures MCP, and installs all 4 hooks:

HookWhenWhat
UserPromptSubmitEvery messageFirst message: load memory. Every Nth: checkpoint reminder
Stop (sync)Every responseLog exchange to active O-entry
Stop (async)Every responseHaiku auto-titles untitled sessions
SessionStart[clear]After /clearRe-inject project context

3. Verify

Restart your AI tool, then:

code
read_memory()

Empty response = working (first run). Error = check the troubleshooting section.

Manual setup

If you prefer manual configuration over hmem init:

<details> <summary>Claude Code — edit ~/.claude/.mcp.json</summary>
json
{
  "mcpServers": {
    "hmem": {
      "command": "/absolute/path/to/node",
      "args": ["/absolute/path/to/hmem-mcp/dist/mcp-server.js"],
      "env": {
        "HMEM_PROJECT_DIR": "/home/yourname/.hmem",
        "HMEM_AGENT_ID": "DEVELOPER"
      }
    }
  }
}

Find the paths:

bash
echo "Node: $(which node)"
echo "Server: $(npm root -g)/hmem-mcp/dist/mcp-server.js"
</details> <details> <summary>OpenCode — edit ~/.config/opencode/opencode.json</summary>
json
{
  "mcp": {
    "hmem": {
      "type": "local",
      "command": ["/absolute/path/to/node", "/absolute/path/to/hmem-mcp/dist/mcp-server.js"],
      "environment": { "HMEM_PROJECT_DIR": "/home/yourname/.hmem" },
      "enabled": true
    }
  }
}
</details> <details> <summary>Cursor / Windsurf / Cline</summary>

Edit ~/.cursor/mcp.json, ~/.codeium/windsurf/mcp_config.json, or .vscode/mcp.json:

json
{
  "mcpServers": {
    "hmem": {
      "command": "/absolute/path/to/node",
      "args": ["/absolute/path/to/hmem-mcp/dist/mcp-server.js"],
      "env": { "HMEM_PROJECT_DIR": "/home/yourname/.hmem" }
    }
  }
}
</details>

Configuration

hmem.config.json in your HMEM_PROJECT_DIR (or Agents/NAME/):

json
{
  "memory": {
    "maxCharsPerLevel": [200, 2500, 10000, 25000, 50000],
    "maxDepth": 5,
    "checkpointMode": "auto",
    "checkpointInterval": 20,
    "recentOEntries": 10,
    "maxTitleChars": 50,
    "prefixes": { "X": "Custom" }
  },
  "sync": {
    "serverUrl": "https://your-server/hmem-sync",
    "userId": "yourname",
    "salt": "...",
    "token": "..."
  }
}
KeyDefaultWhat it does
checkpointMode"remind""auto" = Haiku writes L/D/E in background. "remind" = asks the main agent
checkpointInterval20Exchanges between checkpoints. Set 0 to disable
recentOEntries10How many recent sessions to show in load_project

All keys are optional. Missing keys use defaults.


Cross-Device Sync

Sync memories across all devices with zero-knowledge encryption.

bash
npm install -g hmem-sync
npx hmem-sync connect     # Interactive wizard — first device creates, others join

Add HMEM_SYNC_PASSPHRASE to your MCP config for automatic sync on every read/write.

Multi-server redundancy

json
{
  "sync": [
    { "name": "primary", "serverUrl": "https://server1/hmem-sync", "userId": "me", "salt": "...", "token": "..." },
    { "name": "backup",  "serverUrl": "https://server2/hmem-sync", "userId": "me", "salt": "...", "token": "..." }
  ]
}

Announcements

Broadcast to all synced agents across all devices:

bash
npx hmem-sync announce --message "Server URL changing — update your config!"

Troubleshooting

ProblemFix
read_memory() failsCheck HMEM_PROJECT_DIR is absolute path and directory exists
nvm: node not foundUse absolute path: which node → use as "command"
Hooks not firingRestart Claude Code. Check ~/.claude/settings.json has all 4 hooks
Exchanges not loggedCheck HMEM_AGENT_ID matches your Agents/ directory name
Sync failsRun npx hmem-sync connect to re-authenticate

Updating

bash
npm update -g hmem-mcp       # MCP server
npm update -g hmem-sync       # Sync (if installed)
npx hmem update-skills        # Refresh skill files

License

MIT

常见问题

hmem — Humanlike Memory for AI Agents 是什么?

为 AI agents 提供持久化的 5 层分级记忆,基于 SQLite 存储,并支持 lazy-loaded 按需加载。

相关 Skills

Claude接口

by anthropics

Universal
热门

面向接入 Claude API、Anthropic SDK 或 Agent SDK 的开发场景,自动识别项目语言并给出对应示例与默认配置,快速搭建 LLM 应用。

想把Claude能力接进应用或智能体,用claude-api上手快、兼容Anthropic与Agent SDK,集成路径清晰又省心

AI 与智能体
未扫描109.6k

提示工程专家

by alirezarezvani

Universal
热门

覆盖Prompt优化、Few-shot设计、结构化输出、RAG评测与Agent工作流编排,适合分析token成本、评估LLM输出质量,并搭建可落地的AI智能体系统。

把提示优化、LLM评测到RAG与智能体设计串成一套方法,适合想系统提升AI开发效率的人。

AI 与智能体
未扫描9.0k

智能体流程设计

by alirezarezvani

Universal
热门

面向生产级多 Agent 编排,梳理顺序、并行、分层、事件驱动、共识五种工作流设计,覆盖 handoff、状态管理、容错重试、上下文预算与成本优化,适合搭建复杂 AI 协作系统。

帮你把多智能体流程设计、编排和自动化统一起来,复杂工作流也能更稳地落地,适合追求强控制力的团队。

AI 与智能体
未扫描9.0k

相关 MCP Server

顺序思维

编辑精选

by Anthropic

热门

Sequential Thinking 是让 AI 通过动态思维链解决复杂问题的参考服务器。

这个服务器展示了如何让 Claude 像人类一样逐步推理,适合开发者学习 MCP 的思维链实现。但注意它只是个参考示例,别指望直接用在生产环境里。

AI 与智能体
82.9k

知识图谱记忆

编辑精选

by Anthropic

热门

Memory 是一个基于本地知识图谱的持久化记忆系统,让 AI 记住长期上下文。

帮 AI 和智能体补上“记不住”的短板,用本地知识图谱沉淀长期上下文,连续对话更聪明,数据也更可控。

AI 与智能体
82.9k

PraisonAI

编辑精选

by mervinpraison

热门

PraisonAI 是一个支持自反思和多 LLM 的低代码 AI 智能体框架。

如果你需要快速搭建一个能 24/7 运行的 AI 智能体团队来处理复杂任务(比如自动研究或代码生成),PraisonAI 的低代码设计和多平台集成(如 Telegram)让它上手极快。但作为非官方项目,它的生态成熟度可能不如 LangChain 等主流框架,适合愿意尝鲜的开发者。

AI 与智能体
6.4k

评论