Skip to main content
Glama
Agent Memory

Agent Memory

by Masikomoore

🧠 Agent Memory

One memory. Every agent.

A self-hosted long-term memory layer shared by Claude Code, Codex CLI, WorkBuddy, Cursor, Gemini CLI, Grok Build, VS Code agents, OpenClaw, and any MCP-capable client β€” combining on-demand MCP tools with zero-friction Session/Turn Hooks.

CI License: MIT MCP LanceDB GitHub stars

Quick Start Β· Connect Agents Β· Architecture Β· Roadmap Β· Contributing Β· Discussions Β· δΈ­ζ–‡


TIP

If you use more than one AI coding agent, Agent Memory is for you. Star the repository if you want an open, self-hosted memory layer that stays with you instead of one vendor, IDE, or model.

Why I built this

Agent Memory started with a painful lesson: my Codex Pro account was suspended, and I discovered that I had never kept a complete copy of my history. The local Codex project files were still on my machine, but some browser conversations, planning discussions, and the back-and-forth that shaped development decisions were simply gone.

It was the first time I had personally experienced what losing access to an AI account could mean. I use products from nearly every major AI companyβ€”Claude, Codex, Grok, Gemini, and othersβ€”and that immediately made the problem feel much bigger than one account. If each agent keeps the only copy of part of my working memory, then changing tools, losing an account, or having a service disappear can also erase part of the history behind my projects.

So I built Agent Memory as an independent memory layer that does not belong to any of those agent IDEs or CLIs. Today I use it across Claude Code, Codex CLI, Grok Build, and Gemini CLI, with one shared memory service behind them. The experience has been smooth enough that I am publishing it for other people who regularly use two or more agents and want their long-term working memory to stay under their own control.

Related MCP server: Engram

Your agents should not have separate memories

Most AI tools remember in isolation. Claude Code learns something, Codex starts from zero. Cursor discovers a project convention, Gemini CLI never sees it. Switching tools means repeating yourself.

Agent Memory gives them one private, continuously maintained memory service:

Claude Code ───┐  MCP (/mcp) + Hooks (UserPromptSubmit / Stop / PreCompact / SessionEnd)
Codex CLI ──────  MCP (/mcp) + Hooks (UserPromptSubmit / Stop)
WorkBuddy ──────  MCP (/mcp) + Hooks (~/.workbuddy/settings.json)
Cursor ────────┼──► Agent Memory Server ─► Memory Core ─► LanceDB
Gemini CLI ─────       MCP + REST           β”‚
Grok Build ─────                            β”œβ”€ SmartExtractor + transient retry
VS Code ────────                            β”œβ”€ Hybrid retrieval (Vector + full-layer BM25)
OpenClaw β”€β”€β”€β”€β”€β”€β”˜                            β”œβ”€ decay / reinforcement / dedup / compaction
                                            └─ scopes / lifecycle

Your agents call the memory service. The memory serviceβ€”not a specific IDE or agentβ€”owns the long-term memory.

The 30-second version

Today

With Agent Memory

Every agent starts with a different history

Agents recall from one authoritative memory plane

Important decisions live in chat transcripts

Durable facts are extracted into retrievable memory

Switching tools means repeating context

Claude Code, Codex, WorkBuddy, Cursor, Gemini CLI, Grok Build, VS Code, and OpenClaw can share it

Memory is tied to a vendor or local plugin

Memory runs as your own MCP/REST service

"Remember everything" becomes noisy over time

Decay, reinforcement, deduplication, tiers, and scopes manage lifecycle

Who should try it now? Developers and small teams who already switch between multiple AI agents, prefer self-hosting, and want shared memory without maintaining a knowledge graph.

Why Agent Memory?

Agent Memory

Shared across tools

One memory backend for independent agents and IDEs

Dual-track automatic

Session/Turn Hooks (agent-memory-hook) auto-recall before every turn and async-capture in the background, coexisting with MCP for explicit search/capture

Self-hosted

Run locally, on a homelab, LAN, VPN, or private server

Protocol-first

Streamable HTTP MCP for agents + REST for hooks and native adapters

Durable & full-layer BM25

LanceDB persistence indexing text + L0/L1/L2 summary layers (search_text), duplicate-ID write safety, and redacted LLM error diagnostics

Memory lifecycle

Smart extraction with transient retry, deduplication, decay, reinforcement, scope-isolated compaction, tiering, and scope controls

Provider-flexible

OpenAI-compatible embedding/LLM APIs or local Ollama

No knowledge graph required

Deliberately focused on durable agent memory, not graph administration

Real cross-agent proof

This is not only an MCP configuration demo. A real acceptance test has already verified the core promise:

Real acceptance has verified Claude Code β†’ Codex recall, and a separate Codex capture β†’ Claude Code + Grok recall through the same shared memory service.

Current integration status:

Client

MCP

Session/Turn Hooks (agent-memory-hook)

Status

Claude Code

Streamable HTTP /mcp

~/.claude/settings.json (UserPromptSubmit, async Stop, PreCompact, SessionEnd)

βœ… real-environment verified (MCP + Hooks)

Codex CLI

Streamable HTTP /mcp

~/.codex/hooks.json (UserPromptSubmit, Stop + detached async worker)

βœ… real-environment verified (MCP + Hooks)

WorkBuddy

Streamable HTTP /mcp

~/.workbuddy/settings.json (UserPromptSubmit, Stop, PreCompact, SessionEnd)

βœ… hook installer, templates & E2E verified

Grok Build

Streamable HTTP /mcp

~/.grok/hooks/agent-memory.json (UserPromptSubmit, Stop, PreCompact, SessionEnd)

βœ… MCP verified + hook installer & tests ready

Antigravity CLI

Streamable HTTP /mcp

~/.gemini/config/hooks.json (SessionStart, PreInvocation, Stop)

βœ… hook installer, templates & tests ready

Cursor

Streamable HTTP /mcp

~/.cursor/hooks.json (sessionStart, beforeSubmitPrompt, stop, preCompact, sessionEnd)

βœ… MCP template + hook installer & tests ready

Hermes Agent

Streamable HTTP /mcp

~/.hermes/config.yaml (pre_llm_call, post_llm_call, on_session_finalize)

βœ… hook installer, YAML merge & tests ready

OpenClaw

REST remote-memory mode

Native lifecycle plugin (memory.mode: "remote")

βœ… automated integration coverage

Gemini CLI

Streamable HTTP /mcp

β€”

βœ… authenticated MCP transport verified

VS Code agents

Streamable HTTP /mcp

β€”

🧩 config template ready

Any MCP / Hook client

/mcp

agent-memory-hook recall/capture/health

🧩 protocol-compatible

Magpie Gateway (all routed agents)

β€”

Async Gateway Hook Plugin (integrations/magpie)

βœ… real-environment verified (magpie plugin add)

See docs/AGENT_CLIENTS.md for full MCP and Session/Turn Hook setup guides.

Dual-track integration: MCP + Session/Turn Hooks

MCP alone gives an agent tools, but still relies on the model remembering to call them. agent-memory-hook closes that gap for Claude Code, Codex CLI, WorkBuddy, Grok Build, Antigravity CLI, Cursor, and Hermes Agent without replacing MCP:

  • Automatic pre-turn recall: skips trivial greetings/slash commands locally, suppresses recently injected memories for 8 turns, enforces a strict fail-open timeout, and injects bounded <relevant-memories> using each host's native hook reply format (hookSpecificOutput.additionalContext, Antigravity injectSteps, Cursor additional_context / continue: true, Hermes {"context": ...}).

  • Non-blocking incremental capture: spawns a detached background worker (parent hook returns in ~50ms), parses only newly added turns from Claude/WorkBuddy/Grok/Cursor JSONL, Codex rollout JSONL, or Antigravity USER_INPUT/PLANNER_RESPONSE transcripts (plus cached-prompt / Hermes extra.user_message + assistant_response fallback), strips <relevant-memories> and tool_use/tool_result blocks so MCP and Hooks never loop, and never persists secrets to temp task files.

  • Desktop GUI friendly: loads ~/.config/agent-memory/hook.env (chmod 600) when process env vars are absent, so GUI clients work without inheriting .zshrc exports.

  • Non-destructive install & diagnostics: agent-memory-hook install <claude-code|codex|workbuddy|grok|antigravity-cli|cursor|hermes> merges idempotently while keeping existing settings, comments, and sibling hooks untouched; agent-memory-hook doctor verifies server health, env loading, cache dir, and installed hooks in one command.

Architecture

flowchart LR
    CC[Claude Code] --> MCP[MCP /mcp]
    CX[Codex CLI] --> MCP
    CU[Cursor] --> MCP
    GM[Gemini CLI] --> MCP
    GR[Grok Build] --> MCP
    WB[WorkBuddy] --> MCP
    VS[VS Code] --> MCP
    OC[OpenClaw] --> REST[REST /v1]

    MCP --> S[Agent Memory Server]
    REST --> S
    S --> C[Memory Core]
    C --> EX[Smart Extraction]
    C --> RT[Hybrid Retrieval]
    C --> LC[Lifecycle + Scopes]
    C --> DB[(LanceDB)]
    EX --> LLM[LLM Provider / Ollama]
    RT --> EMB[Embedding Provider / Ollama]

The important boundary is the server: clients never open their own competing databases. They share one authoritative memory plane.

Quick Start

Already using Claude Code, Codex CLI, WorkBuddy, Grok Build, Gemini CLI, or Cursor? Paste this one-line request into your agent (or copy the full checklist from examples/mcp-clients/agent-install-prompt.md):

Install or update Agent Memory from https://github.com/Masikomoore/agent-memory: inspect my installed clients and existing configs/hooks without overwriting them, connect MCP, set up ~/.config/agent-memory/hook.env (chmod 600) and agent-memory-hook for any supported client I have installed (Claude Code, Codex, WorkBuddy, Grok, Antigravity CLI, Cursor, Hermes), and verify everything with `agent-memory-hook doctor` plus a real recall/capture check.

What the agent automatically checks, installs, and verifies for you:

  1. Client & Hook inspection: detects installed clients (~/.claude/settings.json, ~/.codex/hooks.json, ~/.workbuddy/settings.json, ~/.grok/hooks/agent-memory.json, ~/.gemini/config/hooks.json, ~/.cursor/hooks.json, ~/.hermes/config.yaml), preserves unrelated settings and existing hooks, and picks a stable Node path + compiled dist/src/client/memory-hook-cli.js.

  2. Non-destructive MCP + Hook setup & updates: connects /mcp, configures ~/.config/agent-memory/hook.env (chmod 600, zero secrets printed), previews via agent-memory-hook install <host> (dry-run), and applies idempotently with --apply (safe to re-run on updates).

  3. End-to-end verification: runs agent-memory-hook doctor, validates live UserPromptSubmit hook recall, and verifies authenticated MCP capture-then-recall before reporting done.

Option 2 β€” Manual Install (Server + Client Hooks)

Step A β€” Start the Memory Server (Docker Compose or Direct)

Requirements: Docker Compose and an x86_64/arm64 host supported by LanceDB.

git clone https://github.com/Masikomoore/agent-memory.git
cd agent-memory
cp .env.example .env

# Put a long random value in MEMORY_SERVER_TOKEN.
openssl rand -hex 32

docker compose up -d
curl http://127.0.0.1:7337/health

The default compose stack uses your configured OpenAI-compatible embedding & SmartExtractor LLM providers, a persistent LanceDB volume, and loopback-only host publishing. For an all-local Ollama stack, layer docker-compose.ollama.yaml:

docker compose -f docker-compose.yaml -f docker-compose.ollama.yaml up -d

Or run the server directly without Docker:

npm ci && npm run build
export MEMORY_EMBEDDING_API_KEY="..."
export MEMORY_EMBEDDING_MODEL="text-embedding-3-small"
export MEMORY_LLM_API_KEY="..."
export MEMORY_LLM_MODEL="your-model"
export MEMORY_SERVER_TOKEN="replace-with-a-long-random-secret"
npm run memory-server

Connect MCP clients to http://127.0.0.1:7337/mcp with Authorization: Bearer <MEMORY_SERVER_TOKEN>. For LAN/WAN binding, Host/Origin allowlists, and Coolify deployment, see docs/MEMORY_SERVER.md and docs/DEPLOY_COOLIFY.md.

Step B β€” Enable Session/Turn Hooks for supported clients

# 1. Build the compiled hook CLI (fast startup, no runtime transpiler needed)
npm ci && npm run build

# 2. Save server URL & token once (works for both terminal CLIs and desktop GUI clients)
mkdir -p ~/.config/agent-memory
cat > ~/.config/agent-memory/hook.env <<'EOF'
MEMORY_SERVER_URL=http://127.0.0.1:7337
MEMORY_SERVER_TOKEN=replace-with-your-memory-server-token
EOF
chmod 600 ~/.config/agent-memory/hook.env

# 3. Preview (dry-run by default), then apply idempotently (preserves existing hooks)
node dist/src/client/memory-hook-cli.js install claude-code --apply
node dist/src/client/memory-hook-cli.js install codex --apply
node dist/src/client/memory-hook-cli.js install workbuddy --apply
node dist/src/client/memory-hook-cli.js install grok --apply
node dist/src/client/memory-hook-cli.js install antigravity-cli --apply   # alias: agy
node dist/src/client/memory-hook-cli.js install cursor --apply
node dist/src/client/memory-hook-cli.js install hermes --apply

# 4. Verify server health, env loading, state dir, and installed hooks
node dist/src/client/memory-hook-cli.js doctor

Seamless updates

  • Server: git pull && docker compose up -d --build (or click Redeploy in Coolify). Existing LanceDB tables migrate automatically on startup (including search_text column creation, summary-layer backfill, and FTS index cutover) with zero manual database migration.

  • Client hooks: git pull && npm run build && node dist/src/client/memory-hook-cli.js doctor (re-run install <host> --apply only when new hook events are added; existing hooks are updated in place without duplicates).

How agents should use it

Giving an agent MCP access is only half the integration. The agent also needs a durable behavior rule:

  1. Recall before answering when prior decisions, preferences, project state, people, recurring entities, or historical context may matter.

  2. Capture after a durable preference, decision, constraint, fact, or project state is established.

  3. Send a stable logical agentId such as claude-code, codex, or cursor.

  4. Never store passwords, API keys, auth tokens, or transient command output.

  5. Current user instructions always override recalled memory.

Reusable instructions and client examples live in examples/mcp-clients.

Memory model

Agent Memory is designed around a simple idea: memory is infrastructure, not a chat transcript archive.

The server combines:

  • semantic embeddings + full-layer BM25 (search_text indexing text, l0_abstract, l1_overview, and l2_content)

  • retrieval fusion and reranking

  • smart extraction with transient retry and llmUnavailable deferral

  • deduplication, supersession, and duplicate-ID-safe metadata updates

  • redacted LLM JSON error diagnostics (no conversation text leaked to logs)

  • time decay, access reinforcement, and scope-isolated compaction

  • memory tiers and global / agent / user / project scopes

  • canonical-memory compatibility for OpenClaw adapters

The standalone server keeps those capabilities independent from any one host application's lifecycle.

Deployment

Agent Memory is intended to run as a small private service. Common deployment targets:

  • local workstation

  • home server / NAS

  • private LAN or VPN

  • Coolify / Docker host

  • small cloud VM behind TLS and authentication

See docs/DEPLOY_COOLIFY.md for Coolify guidance.

Security default: the server listens on loopback unless configured otherwise. Non-loopback mode requires a Bearer token and explicit Host allowlisting.

Project status

Alpha / early community release. The shared-memory architecture and Claude Code ↔ Codex interoperability have been proven, but the public project is still being separated into cleaner server/core/adapter packages.

Good areas for contributors right now:

  • more real-client acceptance tests

  • memory inspection / administration UI

  • stronger multi-user authentication and ACLs

  • backup / restore UX

  • observability and metrics

  • deployment templates

  • additional agent adapters

  • benchmark and memory-quality evaluation

See the full Roadmap.

What we want help with right now

You do not need to understand the memory engine to contribute. The highest-value community work today is concrete and testable:

Area

Good contribution

Agent integrations

Verify Cursor/VS Code against a real server, or complete Gemini's model-authenticated agent-level acceptance path

Operations

Improve backup/restore, diagnostics, metrics, Docker, NAS, or Coolify workflows

Memory quality

Reproduce a bad recall/capture case with a small fixture and expected behavior

Security

Improve client identity, ACLs, token rotation, and safe remote deployment

UX

Prototype a small memory inspection/search/admin interface

Docs

Make one setup path reproducible for someone who has never used the project

Look for good first issue and help wanted, or start a Discussion before a larger design change.

Contributing

This project is intentionally being opened early. If the idea of a personal memory layer that survives agent switching is useful to you, there are several valuable ways to help:

  • ⭐ Star the project so other agent-tool users can find it

  • πŸ§ͺ Test it with your agent stack and report what breaks

  • πŸ”Œ Add an adapter or verified client recipe

  • 🧠 Improve memory quality, retrieval, or lifecycle behavior

  • πŸ” Improve authentication, tenancy, backup, or operations

  • πŸ“– Fix docs where setup is confusing

Start with CONTRIBUTING.md. Small, focused pull requests are welcome.

Consistent contributors are also welcome to help with issue triage, client verification, documentation review, and roadmap shaping. The goal is to grow Agent Memory as a community-maintained interoperability layer, not a one-person integration dump.

Philosophy

  • One owner for memory. Agents are clients; the memory service is authoritative.

  • Automatic by default. Humans should not need to curate every memory manually.

  • Private first. Self-hosting and local-network deployment are first-class use cases.

  • Interoperable. MCP and REST are boundaries; no single agent vendor owns the data plane.

  • Useful forgetting matters. Long-term memory needs lifecycle management, not infinite accumulation.

  • No graph ceremony. A knowledge graph should not be required just to remember what matters.

License & provenance

Agent Memory is released under the MIT License.

The independent server, remote-client architecture, MCP integration, deployment work, and public project organization in this repository are maintained as Agent Memory. Portions of the underlying memory engine were adapted from the MIT-declared memory-lancedb-pro codebase. See THIRD_PARTY_NOTICES.md for provenance and attribution.

This repository is published as an independent project with its own history and release process; it is not a GitHub fork and does not depend on an upstream Git remote.


If you switch between AI agents, your memory shouldn't reset with the tool.

⭐ Star Β· πŸ› Report Β· πŸ”§ Contribute Β· 🧠 Remember

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Provides AI agents and teams with self-hosted adaptive memory, combining hybrid search and a self-improving neural memory graph to enable precise recall and serendipitous discovery across MCP-compatible clients.
      15
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Provides a single self-hosted memory service that any AI assistant can write to and recall from over MCP or REST, storing episodic, semantic, procedural, reflective and session memories in one shared store. Enables agents to remember events as they happen and receive a ranked, token-budgeted brief of relevant history, counts, lessons and procedures before they act.
      2
      MIT
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables AI coding agents to store, search, and recall persistent project and cross-project memories locally over MCP, keeping architectural decisions, conventions, and error patterns available across sessions. Also optionally exposes a task server for autonomous task execution driven by that same memory store.
      -
    • A
      license
      A
      quality
      B
      maintenance
      A self-hosted MCP memory server that gives every MCP-compatible agent a shared, persistent memory layer, so preferences, project conventions, and past decisions carry across sessions and across different agents and vendors. It combines hybrid keyword-plus-vector retrieval with automatic context injection, zero-config sync, and selective injection of memories by agent and priority.
      23
      3
      MIT