Skip to content
/

agentmemory

agentmemory · rohitg00/agentmemory · ★ 18k · last commit 2026-05-26

Primitive shape 73 total
Skills 8 Hooks 12 MCP tools 53
00

Summary

agentmemory — Summary

agentmemory (rohitg00/agentmemory) is a persistent memory system for AI coding agents built on the iii-engine (a WebSocket-based function/trigger runtime by iii-hq). It runs as a local Node.js server on port 3111, exposes 53 MCP tools and a REST API, and integrates via 12 Claude Code lifecycle hooks. The npm global package (@agentmemory/agentmemory) starts the memory server, connects to your agent via agentmemory connect claude-code, and automatically captures tool usage, compresses it via LLM, and injects relevant context into future sessions. An optional real-time viewer shows memory as it accumulates. An iii Console provides database inspection. The design is explicitly inspired by Karpathy's LLM Wiki pattern, extended with confidence scoring, lifecycle management, knowledge graphs, and hybrid search. 18,016 stars — the most popular framework in this batch.

Differs from seeds: closest to ccmemory (persistent memory, MCP-anchored, Claude Code plugin, graph-aware) but agentmemory operates as a standalone npm server (not just a plugin), uses iii-engine's Worker/Function/Trigger primitives (not raw Neo4j), ships 12 hooks (vs ccmemory's 4), 53 MCP tools (vs ~10), and targets 16+ agent platforms simultaneously. It is the most comprehensive memory system in the entire corpus.

01

Overview

agentmemory — Origin and Philosophy

Origin

Author: Rohit Ghumare (rohitg00). 18,016 stars, 1,472 forks. Apache-2.0 license. TypeScript. Created February 2026. 30 contributors. Website: agent-memory.dev.

The project description: "#1 Persistent memory for AI coding agents based on real-world benchmarks."

The Karpathy Connection

From README:

"The gist extends Karpathy's LLM Wiki pattern with confidence scoring, lifecycle, knowledge graphs, and hybrid search: agentmemory is the implementation."

The design gist (1200 stars / 172 forks on GitHub Gist) is the intellectual foundation. agentmemory adds:

  • Confidence scoring (memories are weighted by reliability)
  • Lifecycle management (memories age, get promoted or evicted)
  • Knowledge graphs (relationships between memory entries)
  • Hybrid search (dense vector + BM25 + graph traversal)

Philosophy

"Session 1 you set up JWT auth. Session 2 you ask for rate limiting. The agent already knows your auth uses jose middleware in src/middleware/auth.ts, your tests cover token validation, and you chose jose over jsonwebtoken for Edge compatibility. No re-explaining. No copy-pasting. The agent just knows."

"Built-in memory (CLAUDE.md, .cursorrules) caps out at 200 lines and goes stale. agentmemory fixes this."

Key Design Decisions (AGENTS.md verbatim)

"Everything goes through registerFunction/registerTrigger/sdk.trigger() — never bypass iii-engine with standalone SQLite or in-process alternatives."

"When adding or removing MCP tools, you MUST update ALL of the following: src/mcp/tools-registry.ts, src/mcp/server.ts, src/triggers/api.ts, src/index.ts, test/mcp-standalone.test.ts, README.md, plugin/.claude-plugin/plugin.json"

This consistency rule enforcement is unusual — most frameworks don't have explicit cross-file update contracts.

02

Architecture

agentmemory — Architecture

Distribution

npm global package:

npm install -g @agentmemory/agentmemory
agentmemory                              # start memory server on :3111
agentmemory demo                         # seed sample sessions + prove recall
agentmemory connect claude-code          # wire Claude Code

Or npx: npx @agentmemory/agentmemory

Required Runtime

  • Node.js (npm package)
  • iii-engine (WebSocket runtime on port 49134 — auto-started or external)

Server Architecture

agentmemory npm binary
      ↓ starts
iii-engine (port 49134) — WebSocket-based Function/Trigger/Worker runtime
      ↓
Memory server
  ├── src/mcp/server.ts     — MCP server (stdio protocol, 53 tools)
  ├── src/triggers/api.ts   — REST API endpoints (port 3111)
  ├── src/state/schema.ts   — KV schema via iii-engine StateModule
  └── src/hooks/            — Claude Code hook scripts (standalone Node.js, no iii-sdk)

State: SQLite via iii-engine StateModule → ./data/state_store.db

Repository Structure

rohitg00/agentmemory/
├── src/
│   ├── index.ts           # Entry point; registerFunction/registerTrigger calls
│   ├── mcp/
│   │   ├── server.ts      # MCP handler (switch cases for 53 tools)
│   │   └── tools-registry.ts # Tool definitions + getAllTools()
│   ├── triggers/api.ts    # REST endpoint registration
│   ├── state/schema.ts    # KV object schema
│   ├── functions/         # Memory operations (store, search, compress, etc.)
│   └── hooks/             # Standalone Node.js hook scripts (HTTP to REST API)
├── plugin/
│   ├── .claude-plugin/
│   │   └── plugin.json    # agentmemory v0.9.21; 51 MCP tools, 4 skills
│   ├── hooks/
│   │   ├── hooks.json     # 12 Claude Code hook events
│   │   └── hooks.codex.json # 6 Codex hook events
│   ├── skills/            # 8 skills: commit-context, commit-history, forget,
│   │                        handoff, recall, recap, remember, session-history
│   └── scripts/           # Hook script implementations (Node.js .mjs)
├── packages/              # npm workspace packages
├── integrations/          # Per-agent integration guides
├── benchmark/             # Memory benchmark suite
├── deploy/                # Docker/compose deployment
└── website/               # Marketing site

Target AI Tools (16+)

Claude Code (native plugin + 12 hooks + MCP), Codex CLI (native plugin + 6 hooks + MCP), OpenClaw (native plugin + MCP), Hermes (native plugin + MCP), pi (native plugin + MCP), OpenHuman (native Memory trait), Cursor (MCP), Gemini CLI (MCP), OpenCode (22 hooks + MCP + plugin), Cline (MCP), Goose (MCP), Kilo Code (MCP), Aider (REST API), Claude Desktop (MCP), Windsurf (MCP), Roo Code (MCP).

03

Components

agentmemory — Components

12 Claude Code Hooks

All hooks are Node.js .mjs scripts in plugin/scripts/, invoked via plugin/hooks/hooks.json:

Event Script What it does
SessionStart session-start.mjs Registers session; if AGENTMEMORY_INJECT_CONTEXT=true, fetches and writes context to stdout
UserPromptSubmit prompt-submit.mjs Intercepts user prompt for pre-processing / context injection
PreToolUse pre-tool-use.mjs Matcher: Edit|Write|Read|Glob|Grep — captures intent before file ops
PostToolUse post-tool-use.mjs Captures tool output as observation
PostToolUseFailure post-tool-failure.mjs Records failure events for pattern detection
PreCompact pre-compact.mjs Claude-bridge sync + injects compressed context to survive compaction
SubagentStart subagent-start.mjs Registers sub-agent spawning in session graph
SubagentStop subagent-stop.mjs Captures sub-agent completion
Notification notification.mjs Handles async agent notifications
TaskCompleted task-completed.mjs Records task completion observations
Stop stop.mjs Session close — triggers compression and summarization
SessionEnd session-end.mjs Final cleanup and state flush

Pre-compaction hook pattern (from pre-compact.mjs): fetches /agentmemory/context from REST API and writes compressed context to stdout so Claude Code injects it as the first message of the new compacted context.

8 Claude Code Skills

All skills are invokable via /skill-name [args] in Claude Code:

Skill Description
recall Invokes memory_smart_search MCP tool (hybrid BM25+vector+graph search); returns results grouped by session with importance scoring
handoff Resumes most recent session; directory-boundary cwd matching; surfaces unanswered questions first
remember Invokes memory_save to persist an explicit insight, decision, or pattern
forget Deletes a memory by ID or matching query; requires confirmation
recap Summarizes current session observations to date
commit-context Recalls memory observations related to files touched in recent git commits
commit-history Looks up past session context associated with a specific commit SHA or branch
session-history Lists all sessions for the current project directory with dates and summaries

53 MCP Tools (stdio protocol)

Full tool list extracted from src/mcp/tools-registry.ts:

Core recall/search: memory_recall, memory_smart_search, memory_vision_search, memory_timeline, memory_patterns, memory_sessions, memory_file_history, memory_profile

Storage/save: memory_save, memory_compress_file, memory_export, memory_snapshot_create, memory_checkpoint, memory_crystallize

Graph/relations: memory_relations, memory_graph_query, memory_commit_lookup, memory_commits, memory_claude_bridge_sync

Team/sharing: memory_team_share, memory_team_feed

Governance: memory_audit, memory_governance_delete, memory_verify, memory_diagnose, memory_heal

Workflow/automation: memory_action_create, memory_action_update, memory_frontier, memory_next, memory_lease, memory_routine_run

Signals/comms: memory_signal_send, memory_signal_read, memory_mesh_sync

Sentinels/watchers: memory_sentinel_create, memory_sentinel_trigger

Sketches (scratch to crystal pipeline): memory_sketch_create, memory_sketch_promote

Facets (tagging): memory_facet_tag, memory_facet_query

Learning: memory_lesson_save, memory_lesson_recall

Reflection/insights: memory_reflect, memory_insight_list, memory_consolidate

Slots (scoped storage): memory_slot_list, memory_slot_get, memory_slot_create, memory_slot_append, memory_slot_replace, memory_slot_delete

Integrations: memory_obsidian_export

REST API (port 3111)

Key endpoints (from src/triggers/api.ts):

  • POST /agentmemory/session/start — registers session, optionally returns injected context
  • POST /agentmemory/context — returns compressed context for pre-compaction injection
  • GET /agentmemory/sessions — list sessions (used by handoff skill fallback)
  • POST /agentmemory/recall — search (fallback when MCP unavailable)
  • GET /agentmemory/health — server health and config flags

Bearer token authentication via AGENTMEMORY_SECRET env var.

State Schema (iii-engine KV keys)

Key namespaces in src/state/schema.ts:

  • mem:sessions — session registry
  • mem:obs:{sessionId} — observations per session
  • mem:memories — long-term memories
  • mem:graph:nodes / mem:graph:edges — knowledge graph
  • mem:slots / mem:slots:global — scoped storage slots
  • mem:audit — governance audit log
  • mem:lessons / mem:insights — learned lessons
  • mem:team:{teamId}:shared — team-shared memory
  • mem:signals — cross-agent signal bus
  • mem:mesh — agent mesh topology
  • mem:crystals — crystallized permanent memories
  • mem:sentinels — trigger watchers
  • mem-live stream — real-time viewer feed

65+ Function Files

src/functions/ contains 65+ TypeScript modules: observe.ts, search.ts, smart-search.ts, graph.ts, graph-retrieval.ts, temporal-graph.ts, compress.ts, compress-file.ts, consolidate.ts, crystallize.ts, evict.ts, auto-forget.ts, signals.ts, mesh.ts, sentinels.ts, sketches.ts, facets.ts, lessons.ts, reflect.ts, slots.ts, snapshot.ts, checkpoints.ts, leases.ts, routines.ts, team.ts, audit.ts, governance.ts, vision-search.ts, obsidian-export.ts, working-memory.ts, timeline.ts, profile.ts, patterns.ts, relations.ts, export-import.ts, verify.ts, diagnostics.ts, enrich.ts, dedup.ts, retention.ts, access-tracker.ts, and more.

05

Prompts

agentmemory — Prompts and Instructions

AGENTS.md — Architecture Mandate (verbatim)

"Everything goes through registerFunction/registerTrigger/sdk.trigger() — never bypass iii-engine with standalone SQLite or in-process alternatives."

AGENTS.md — Consistency Rules (verbatim)

"When adding or removing MCP tools, you MUST update ALL of the following:

  1. src/mcp/tools-registry.ts — tool definition + getAllTools() array
  2. src/mcp/server.ts — handler case in the mcp::tools::call switch
  3. src/triggers/api.ts — REST endpoint registration
  4. src/index.ts — function registration + endpoint count in the log line
  5. test/mcp-standalone.test.ts — tool count assertion
  6. README.md — tool counts (search for "MCP tools")
  7. plugin/.claude-plugin/plugin.json — tool count in description"

Version bump similarly requires updating 6 files simultaneously. This enforces cross-file contract consistency that most frameworks leave to convention.

skill: recall — Instructions (verbatim excerpts)

Use the `memory_smart_search` MCP tool with the user's query as the `query` argument and `limit: 10`.
The tool runs hybrid BM25 + vector + graph-expanded search over captured observations and returns ranked results.

Present the returned results to the user in a readable format:
- Group by session
- For each observation show its type, title, and narrative
- Highlight the most important observations (importance >= 7)
- If no results come back, suggest 2-3 alternative search terms the user could try

**Do NOT make up or hallucinate observations.** Only present what the MCP tool actually returned.
If `memory_smart_search` isn't available, the stdio MCP shim didn't start — tell the user to:
1. Run `/plugin list` in Claude Code and confirm `agentmemory` shows as enabled.
2. Restart Claude Code (the plugin's `.mcp.json` is only read on startup).
3. Check `/mcp` to see whether the `agentmemory` MCP server is connected.

skill: handoff — Instructions (verbatim excerpts)

Determine the current project path: if `$ARGUMENTS` is provided, resolve it to an absolute, normalized path
(accept relative inputs, e.g. `path.resolve(process.cwd(), $ARGUMENTS)`); otherwise use the current working directory.

Call the `memory_sessions` MCP tool. From the result, pick the most recent session whose normalized `cwd`
matches the project path with a directory-boundary check — equality OR `session.cwd.startsWith(projectPath + path.sep)`
OR `projectPath.startsWith(session.cwd + path.sep)`.
Do NOT use a raw string prefix match: it produces false positives across unrelated repos that share a path prefix
(e.g. `/repo-a` vs `/repo-a-staging`).

Once a session is selected:
1. If the session ended on an unanswered user-facing question, surface that question FIRST as the lead.
2. Then summarize the session: title/summary, key files touched, key decisions or errors.
3. End with a short "next step?" pointer the user can act on.

plugin.json Description (verbatim)

"Persistent memory for AI coding agents -- captures tool usage, compresses via LLM, injects context into future sessions. 12 hooks, 51 MCP tools, 4 skills, real-time viewer."

(Note: plugin.json version 0.9.22 says "51 MCP tools"; tools-registry.ts contains 53 tool definitions — a version skew documented as transient during tool addition.)

README Positioning Statement (verbatim)

"Session 1 you set up JWT auth. Session 2 you ask for rate limiting. The agent already knows your auth uses jose middleware in src/middleware/auth.ts, your tests cover token validation, and you chose jose over jsonwebtoken for Edge compatibility. No re-explaining. No copy-pasting. The agent just knows."

"Built-in memory (CLAUDE.md, .cursorrules) caps out at 200 lines and goes stale. agentmemory fixes this."

Design Gist — Karpathy Connection (verbatim from README)

"The gist extends Karpathy's LLM Wiki pattern with confidence scoring, lifecycle, knowledge graphs, and hybrid search: agentmemory is the implementation."

(The design gist has 1,200 stars / 172 forks as a standalone GitHub Gist.)

session-start.mjs — Hook Logic Pattern

The session-start hook demonstrates the opt-in context injection model:

const INJECT_CONTEXT = process.env["AGENTMEMORY_INJECT_CONTEXT"] === "true";

if (!INJECT_CONTEXT) {
  // fire-and-forget: register only, don't block on response
  fetch(url, { ...init, signal: AbortSignal.timeout(800) }).catch(() => {});
  return;
}
// blocking path: fetch context and write to stdout for Claude Code injection
const res = await fetch(url, { signal: AbortSignal.timeout(1500) });
if (res.ok) {
  const result = await res.json();
  if (result.context) process.stdout.write(result.context);
}

The non-injecting path has an 800ms timeout (REGISTER_TIMEOUT_MS); the injecting path has a 1500ms timeout (INJECT_TIMEOUT_MS). This prevents hook latency from slowing Claude Code startup.

09

Uniqueness

agentmemory — Uniqueness and Positioning

Differs from Seeds

Closest to ccmemory (persistent memory, MCP-anchored, Claude Code plugin, graph awareness) but agentmemory is categorically more comprehensive:

  1. Server architecture vs plugin-only: ccmemory is a Claude Code plugin with ~10 MCP tools. agentmemory runs as a standalone npm server (iii-engine process on port 49134 + REST API on port 3111), exposes 53 MCP tools, and serves 16+ agent platforms simultaneously.

  2. Hook coverage: ccmemory has 4 hooks. agentmemory has 12 — every Claude Code lifecycle event covered including SubagentStart/Stop, Notification, TaskCompleted, PostToolUseFailure, and PreCompact (the compaction-survival hook that no minimal plugin implements).

  3. iii-engine runtime: Unlike any other framework in this corpus, agentmemory is built on iii-engine's Worker/Function/Trigger primitives. Every operation is a registered function that routes through the WebSocket runtime — no raw SQLite access, no direct file I/O. This is a principled constraint: AGENTS.md says "never bypass iii-engine with standalone SQLite or in-process alternatives."

  4. 53-tool MCP surface: The tool surface goes far beyond recall/save into: team sharing, cross-agent signals, mesh topology sync, sentinel watchers, sketch→crystal promotion pipeline, facet tagging, Obsidian export, vision search, governance/audit, routine automation, and more.

  5. Benchmark-driven: 95.2% R@5 on LongMemEval-S (500 questions); 96.7% on internal coding-agent-life-v1; 950+ tests. Competitor comparison table vs mem0, Letta, Khoj, claude-mem, Hippo.

  6. Knowledge graph: When enabled, LLM-extracted entity/relation graph with temporal validity windows and graph-expanded search. ccmemory has graph awareness; agentmemory has a full temporal knowledge graph pipeline.

  7. Cross-consistency enforcement: AGENTS.md specifies 7 files that must be updated simultaneously when adding any MCP tool. This cross-file contract is unusual among all frameworks in the corpus.

Karpathy Connection

The design is grounded in Andrej Karpathy's LLM Wiki pattern — a mental model for how agents should maintain persistent, updateable knowledge. agentmemory extends this with: confidence scoring (importance 1–10), lifecycle management (eviction, crystallization), knowledge graphs (temporal entity-relation), and hybrid search (BM25 + vector + graph traversal). The design gist has 1,200 stars / 172 forks as a standalone document.

Market Position

18,016 stars — the most-starred framework in the entire Phase B corpus. This is not a research tool; it is production infrastructure claiming the "persistent memory for AI coding agents" category.

Observable Failure Modes

  1. iii-engine dependency: The WebSocket runtime on port 49134 must be running. If iii-engine crashes, the entire memory system is unavailable — every hook fires and silently fails. No fallback storage path.

  2. LLM cost leakage: Graph extraction (GRAPH_EXTRACTION_ENABLED=true) and auto-compress (AUTO_COMPRESS_ENABLED=true) make LLM API calls on every observation. High-frequency tool use (100+ observations/session) generates unexpected API bills.

  3. Hook path version lock: Using ~/.claude.json direct wiring instead of /plugin install embeds the versioned script path (issue #508). Upgrades silently break all hooks.

  4. Port 3111 / 3113 / 49134 occupancy: Three listening sockets. Conflicts with existing services cause silent memory loss — hooks call fire-and-forget with 800ms timeouts.

  5. Plugin version skew: plugin.json v0.9.22 says "51 MCP tools" while tools-registry.ts contains 53 definitions. The README consistency rule (7-file update requirement) apparently drifted during rapid tool addition.

  6. Compaction dependency: The PreCompact hook injects context by writing to stdout. If the hook process times out (>1500ms), the context injection fails silently and the compacted session loses all prior memory.

04

Workflow

agentmemory — Workflow

Phase Overview

agentmemory's workflow is event-driven rather than task-phase-driven. The system operates as a background capture-and-recall loop, not a sequential planning pipeline.

Session Start
    ↓
[SessionStart hook] → register session, optionally inject prior context
    ↓
Active Work Loop:
  [UserPromptSubmit hook] → pre-process prompt
  [PreToolUse hook] → capture intent (Edit|Write|Read|Glob|Grep)
  [PostToolUse hook] → observe tool output → mem::observe
  [PostToolUseFailure hook] → record errors for pattern detection
    ↓
[SubagentStart/Stop] → track sub-agent spawning in session graph
[TaskCompleted hook] → record task milestones
[Notification hook] → handle async agent notifications
    ↓
Pre-Compaction Gate:
  [PreCompact hook] → claude-bridge sync + inject compressed context
    ↓
Session End:
  [Stop hook] → trigger compression + summarization
  [SessionEnd hook] → final state flush

Observation Pipeline

Raw events from hooks flow into mem::observe (registered via registerObserveFunction):

  1. Hook fires → sends HookPayload to REST API at POST /agentmemory/observe
  2. Privacy stripping (stripPrivateData) removes credentials/secrets
  3. Dedup check via DedupMap — Jaccard similarity prevents near-duplicate observations
  4. Observation stored in mem:obs:{sessionId} (iii-engine KV)
  5. If AUTO_COMPRESS_ENABLED: async LLM compression → creates CompressedObservation
  6. BM25 index + vector embedding computed and stored
  7. Graph extraction (if GRAPH_EXTRACTION_ENABLED=true): entity/relation extraction via LLM

Context Injection

Two paths for injecting past context:

SessionStart injection (opt-in): set AGENTMEMORY_INJECT_CONTEXT=true. The session-start hook POSTs to /agentmemory/session/start and writes the returned context string to stdout — Claude Code reads it as the first system message of the session.

PreCompact injection: Before Claude Code compacts the context window, the hook POSTs to /agentmemory/context, which returns a compressed summary of the session's observations. This survives context window resets.

Recall Flow

When the /recall skill is invoked or the agent calls memory_smart_search:

  1. Query → hybrid search: BM25 (token overlap) + vector similarity (all-MiniLM-L6-v2 embeddings) + graph traversal (entity expansion)
  2. Results ranked by combined score
  3. Filtered by project cwd (unless AGENT_SCOPE_ISOLATED=false)
  4. Returned as observations grouped by session with importance scores
  5. Agent presents results; high-importance (≥7) observations highlighted

Compression / Crystallization Pipeline

Long-term memory consolidation:

  • Auto-compress: LLM-driven observation compression (background)
  • Consolidate (memory_consolidate): merge related observations
  • Crystallize (memory_crystallize): promote patterns into permanent mem:crystals entries
  • Sketch → Promote (memory_sketch_create / memory_sketch_promote): scratch-pad patterns promoted to crystals after validation

Handoff Protocol

Using the /handoff skill at session start:

  1. memory_sessions called → returns sessions with cwd metadata
  2. Directory-boundary matching: session.cwd equals projectPath OR one is prefix of the other with a separator boundary (prevents false positives like /repo-a matching /repo-a-staging)
  3. Most recent completed session preferred over abandoned
  4. Unanswered user-facing questions (observations with type conversation ending in ?) surfaced first
  5. Key files, decisions, errors summarized; memory_recall called for supporting observations

Team Memory Sharing

memory_team_share posts to mem:team:{teamId}:shared. memory_team_feed pulls the shared pool. All team members' observations merge into the team namespace — cross-agent recall without file sharing.

Configuration Flags

Key environment variables affecting workflow:

Variable Default Effect
AGENTMEMORY_URL http://localhost:3111 REST API URL
AGENTMEMORY_SECRET (empty) Bearer token for auth
AGENTMEMORY_INJECT_CONTEXT false Enable context injection at SessionStart
GRAPH_EXTRACTION_ENABLED false Enable LLM knowledge graph extraction (requires LLM key)
CONSOLIDATION_ENABLED false Background observation consolidation
AUTO_COMPRESS_ENABLED false Automatic LLM compression of observations
AGENTMEMORY_SDK_CHILD (unset) Set to 1 to suppress hook runs in SDK sub-contexts
CLAUDE_MEMORY_BRIDGE false Sync CLAUDE.md contents to memory on PreCompact
AGENT_SCOPE_ISOLATED true Scope recall to current project cwd
06

Memory Context

agentmemory — Memory and Context

Storage Architecture

All state is stored in SQLite via iii-engine's StateModule at ./data/state_store.db. There are no external database dependencies — the README badge reads "0 external DBs."

iii-engine wraps the SQLite as a KV store accessed through typed keys defined in src/state/schema.ts. The KV object has 45+ named keys.

Memory Layers

Observations (mem:obs:{sessionId}): Raw per-session records. Each observation has:

  • sessionId: session it belongs to
  • hookType: which hook captured it (PreToolUse, PostToolUse, etc.)
  • timestamp
  • narrative: LLM-compressed summary (if auto-compress enabled) or raw content
  • type: conversation | file_read | file_write | bash | error | task | pattern
  • importance: 1–10 score (higher = more likely to be recalled)
  • files: file paths involved
  • concepts: semantic tags

Long-term memories (mem:memories): Explicitly saved insights via memory_save or promoted from observations.

Crystals (mem:crystals): Permanently crystallized patterns. Created via memory_crystallize — the highest permanence tier; never evicted by lifecycle.

Semantic (mem:semantic) and Procedural (mem:procedural): Typed memory categories.

Slots (mem:slots, mem:slots:global): Scoped key-value storage for agents. Global slots persist across sessions; session slots are scoped.

Knowledge Graph

When GRAPH_EXTRACTION_ENABLED=true, an LLM extracts entities and relations from observations:

  • Nodes: mem:graph:nodes
  • Edges: mem:graph:edges
  • Edge history: mem:graph:edge-history

Graph retrieval (graph-retrieval.ts) expands search results by traversing entity relationships — a file node may link to an architecture decision node, which links to other files involved.

Temporal graph (temporal-graph.ts) tracks entity validity windows — "used jose from session 3, switched to jsonwebtoken in session 7."

Search Mechanism

Three-layer hybrid search (from smart-search.ts):

  1. BM25 (mem:index:bm25): token overlap over observation narratives
  2. Vector (mem:emb:{obsId}): cosine similarity via all-MiniLM-L6-v2 local embeddings (no API key required, runs via @xenova/transformers)
  3. Graph expansion: entity-linked observations pulled in by graph traversal

Benchmark: 95.2% R@5 on LongMemEval-S (500 questions); 96.7% R@5 on internal coding-agent-life-v1 corpus. BM25-only fallback achieves 86.2% R@5.

memory_vision_search and vision-search.ts / image-refs.ts / image-embeddings.ts: screenshots and image data captured in hook payloads are embedded and searchable. Image quota cleanup (image-quota-cleanup.ts) manages disk usage.

Context Injection Paths

SessionStart injection: AGENTMEMORY_INJECT_CONTEXT=true → hook writes compressed prior context to stdout → Claude Code prepends it to the first turn.

PreCompact injection: Before context window reset, hook fetches /agentmemory/context (which runs context.ts) → returns compressed observation summary → written to stdout → survives compaction.

Claude Bridge (mem:claude-bridge, claude-bridge.ts): When CLAUDE_MEMORY_BRIDGE=true, the PreCompact hook syncs CLAUDE.md contents into memory. /agentmemory/claude-bridge/sync endpoint.

Retention / Eviction

retention.ts + evict.ts + auto-forget.ts:

  • Retention scores computed per observation (mem:retention-scores)
  • Access frequency logged (mem:access)
  • Old, low-importance observations evicted to keep database size bounded
  • Disk size manager (disk-size-manager.ts) enforces a configurable size limit

Team Memory

mem:team:{teamId}:shared — team-scoped shared observations. mem:team:{teamId}:users:{userId} — per-user team profile. Multiple agents in a team share memory via memory_team_share / memory_team_feed.

Mesh / Multi-Agent

mem:mesh — distributed agent mesh topology. memory_mesh_sync — synchronizes memory state across mesh nodes. Used when multiple agentmemory instances run in a network.

Persistence Scope

Session observations: project-scoped by default (AGENT_SCOPE_ISOLATED=true). Long-term memories, crystals, lessons, and team memory: global (cross-project).

Obsidian export (memory_obsidian_export, obsidian-export.ts): export entire memory graph as Obsidian-compatible Markdown vault with bidirectional links.

07

Orchestration

agentmemory — Orchestration

Multi-Agent Pattern

agentmemory is not itself an orchestrator — it is the memory layer beneath any orchestrator. It supports multi-agent scenarios through three mechanisms:

1. SubagentStart/SubagentStop hooks: When Claude Code spawns a sub-agent, the SubagentStart hook registers the sub-agent in the parent session's observation graph. SubagentStop captures the sub-agent's completion. This creates a hierarchical session graph: parent session → sub-agent session → observations.

2. Shared memory namespace: All agents pointing at the same agentmemory server (via AGENTMEMORY_URL) share mem:memories, mem:crystals, mem:lessons, and mem:insights. Sub-agents can recall context from parent sessions and from other concurrent agents.

3. Mesh sync (memory_mesh_sync): For distributed setups where multiple agentmemory instances run on different machines, mem:mesh topology enables cross-instance memory synchronization.

Agent Scope Isolation

AGENT_SCOPE_ISOLATED=true (default): session observations are scoped to the project cwd — recall only returns results matching the current project path. Long-term memories (crystals, lessons) remain global.

AGENT_SCOPE_ISOLATED=false: all sessions share the same recall pool, useful in monorepo setups.

Signal Bus

mem:signals — cross-agent messaging. memory_signal_send / memory_signal_read allow agents to pass messages through the shared memory server without direct communication channels.

Lease Mechanism

mem:leases — distributed locking for concurrent agents. memory_lease acquires a named lease (TTL-based). Used internally by withKeyedLock to prevent concurrent writes to the same observation set.

Sentinel Watchers

memory_sentinel_create / memory_sentinel_trigger: agents can create watchers on memory conditions. When a condition is met (e.g., a specific pattern observed N times), the sentinel fires a trigger. Enables reactive multi-agent coordination: agent B watches for a signal from agent A before proceeding.

Team Memory Integration

memory_team_share: agent pushes an observation to mem:team:{teamId}:shared. memory_team_feed: agent pulls shared observations from other team members. The teamId can be a project identifier or a human-chosen team name. No explicit invitation/join protocol — any agent with the same teamId and AGENTMEMORY_SECRET can participate.

Cross-Platform Target

agentmemory positions as the universal memory layer for 16+ agent platforms simultaneously:

  • Claude Code: 12 hooks + native plugin + MCP + 8 skills
  • Codex CLI: 6 hooks + native plugin + MCP + 4 skills
  • OpenClaw, Hermes, pi: native plugin + MCP
  • OpenHuman: native Memory trait (Rust)
  • Cursor, Gemini CLI, Claude Desktop, Windsurf, Cline, Kilo Code, Roo Code, Goose: MCP only
  • OpenCode: 22 hooks + MCP + plugin
  • Aider: REST API only (no hook/MCP support)

All platforms share the same agentmemory server process and the same SQLite database. "All agents share the same memory server."

Isolation Mechanism

None between platform clients — a Cursor session and a Claude Code session on the same project share observations. Isolation is only at the project-cwd level.

No sandboxing, no container boundaries, no separate databases per platform.

Concurrency

withKeyedLock provides per-session mutex on observation writes. The iii-engine WebSocket runtime handles concurrent requests via its Worker/Function/Trigger primitives. The SQLite StateModule serializes writes.

08

Ui Cli Surface

agentmemory — UI and CLI Surface

CLI Binary: agentmemory

Global npm binary (@agentmemory/agentmemory).

Subcommands

agentmemory                    # start memory server on :3111
agentmemory demo               # seed sample sessions + prove recall
agentmemory connect <agent>    # wire the specified agent (claude-code, codex, cursor, gemini-cli, kiro, ...)
agentmemory connect codex --with-hooks   # explicit hook wiring for Codex Desktop

agentmemory connect <agent> writes the mcpServers config block to the agent's config file and, for agents with native plugin support, registers the plugin.

Also available as npx @agentmemory/agentmemory (no install). From v0.9.16+, the first npx run prompts to install globally.

Real-Time Viewer (port 3113)

A live dashboard that shows memory as it accumulates.

  • Served via src/viewer/server.ts on port 3113 (separate from the REST API on 3111)
  • HTML document generated by src/viewer/document.ts (renderViewerDocument)
  • CSP enforced: img-src 'self' — DNS rebinding protection via allowed-origins list
  • Allowed origins: http://localhost:3111,http://localhost:3113,http://127.0.0.1:3111,http://127.0.0.1:3113
  • Real-time updates via mem-live event stream (iii-engine stream)

The viewer shows observations flowing in as hooks fire, session timelines, and memory graph visualizations.

iii Console (database inspection)

The iii-engine console provides direct database inspection of all KV keys (mem:sessions, mem:obs:{sessionId}, mem:graph:nodes, etc.) without requiring SQL queries. Accessed via the iii-engine web interface.

REST API Surface (port 3111)

Used by hook scripts and fallback paths when MCP is unavailable:

  • GET /agentmemory/health — server health, config flags, version
  • POST /agentmemory/session/start — register session
  • POST /agentmemory/context — compressed context for pre-compaction
  • GET /agentmemory/sessions — list sessions
  • POST /agentmemory/recall — search fallback
  • POST /agentmemory/smart-search — hybrid search
  • POST /agentmemory/observe — manual observation submission
  • POST /agentmemory/claude-bridge/sync — CLAUDE.md sync

All endpoints require Authorization: Bearer {AGENTMEMORY_SECRET} when secret is configured (503 if required but missing).

MCP Server (stdio, @agentmemory/mcp)

Separate npm package @agentmemory/mcp — the stdio shim that proxies calls to the running agentmemory server. Added to mcpServers in agent config:

{
  "command": "npx",
  "args": ["-y", "@agentmemory/mcp"],
  "env": {
    "AGENTMEMORY_URL": "http://localhost:3111"
  }
}

Falls back to 7 local tools when no server is reachable; full 53 (or 51 per plugin.json v0.9.22) tools when server is up.

Claude Code Skills UI

8 skills accessible via /skill-name in Claude Code chat:

  • /recall [query]
  • /handoff [cwd]
  • /remember
  • /forget
  • /recap
  • /commit-context
  • /commit-history
  • /session-history

Issue Workaround for Hook Path Resolution

From README: wiring via ~/.claude.json directly instead of /plugin install causes hook scripts to embed the versioned install path (e.g., ~/.codex/plugins/cache/agentmemory/0.9.21/scripts/...). This breaks on upgrade. The plugin install path (${CLAUDE_PLUGIN_ROOT}) avoids this — tracked in issue #508.

Related frameworks

same archetype · same primary tool · same memory type

MemPalace ★ 53k

Verbatim local-first AI memory with 96.6% R@5 retrieval on LongMemEval using zero API calls — structured into a palace hierarchy…

Beads (Yegge) ★ 24k

Dolt-powered distributed graph issue tracker where AI agents track tasks with hierarchical IDs and dependency edges, claim work…

deepagents (LangChain) ★ 23k

Opinionated Python agent harness on top of LangGraph with sub-agents, filesystem, memory, and context compaction bundled in

Open Multi-Agent ★ 6.3k

Give a natural-language goal to a coordinator agent and get a dynamically decomposed, parallelized task DAG executed by…

Basic Memory ★ 3.1k

Gives AI agents a persistent, human-readable knowledge graph of project decisions, observations, and relations stored as plain…

Claude-Supermemory ★ 2.6k

Gives Claude Code team-level persistent memory via a cloud API, sharing project knowledge across developers and sessions without…