Engram: Adding memory to your AI agents (Claude Code, OpenCode)
Abdiel Martí
·
2026-04-27
·
via Artificial Intelligence in Plain English - Medium
Do your AI agents lose context? Learn how to use Engram to give persistent memory to Claude Code and OpenCode across all your sessions. 🚀 Generated by Chatgpt If you prefer to read this article in Spanish, you can find it at: abdiel.dev TL;DR: Engram is an MCP-based persistent memory system that automatically saves summaries of your findings, decisions, and configurations. It works agnostically across different AI agents. I have to admit, I was quite reluctant to fall for the charms of agentic development. I preferred doing things the old-fashioned way: a solid IDE and, at most, GitHub Copilot suggesting changes. But I finally caved and started experimenting with the most popular options: Claude Code and OpenCode. Personally, I lean towards OpenCode (I might dive into my reasons in a future article). For now, I want to focus on a pain point I began hitting constantly: the lack of persistent memory in AI agents. The scenario is this: when you start taking agentic development seriously, you fire up a work session, make key discoveries, and reach multiple architectural decisions. You wrap up for the day, and when you open a new session the next morning, your agent remembers absolutely nothing about what you decided or discovered. You’re probably thinking the most practical thing is simply to resume the previous session. However, that approach ignores a crucial technical detail: you’d be dragging along a bloated, “spent” context filled with information irrelevant to your new tasks. The most optimal approach is to persist only those snippets of information that are actually useful, so you can retrieve them from fresh, clean sessions. This is where the tool I want to introduce today comes in: Engram . 🛠️ What is Engram? Engram is a persistent memory system specifically designed for AI coding agents. Among the features that stand out compared to other alternatives, I find the following: Agent-Agnostic: It isn’t locked into a single specific agent. Since it operates as an MCP (Model Context Protocol) server, you can use Engram with any compatible tool: Claude Code, OpenCode, Gemini CLI, Codex, VS Code (Copilot), Antigravity, or Cursor. Optimized Memory: It doesn’t save the entire work session; instead, it generates and stores structured summaries as you progress through development. Interoperability: Because it doesn’t depend on a single client, you can switch between tools and keep the same “brain.” Say you work in Claude Code one day and feel like using OpenCode the next; your agents will always have access to the same memories. Cloud/Local Sync: You can sync learned memories across multiple machines. This is a lifesaver when switching between your desktop and laptop, or when you need to share context with other team members. Automatic Logging: You don’t need to manually tell it to remember information every five minutes. The agent takes notes automatically upon reaching significant milestones (though you can always force it to remember something specific via a prompt). (If you already have experience with alternatives like claude-mem, I recommend checking out their detailed comparison in the official documentation ). How does it work? ⚙️ When you and the agent complete a meaningful task, such as: 🐛 A completed bug fix . 🏗️ An architectural decision. 🔍 A non-obvious discovery about the codebase . ⚙️ A configuration or environment change. 🧩 An established pattern (naming, structure, conventions). 👤 A learned user preference or constraint. The agent will call Engram’s MCP save tool to persist a memory using the following standard format: title: "Verb + what" (e.g., "Fixed N+1 query in UserList") type: bugfix | decision | architecture | discovery | pattern | config | preference scope: project (default) | personal topic_key: stable key for evolving topics (e.g., architecture/auth-model) content: **What**: A clear sentence on what was done. **Why**: The motivation (user request, bug, performance, etc.). **Where**: Affected files or paths. **Learned**: Gotchas, edge cases, things that surprised you (omitted if none). Example of a real-world memory: **Observation #242** ────────────────── **Type:** pattern **Title:** cache invalidations: create/update/delete **Session:** manual-save-personal-app **Created:** 2026-04-23 22:39:03 **Project:** personal-app **Content** **What**: Completed the set of graphcache `updates.Mutation` entries for waitlist mutations in `src/utils/graphClient.ts`, plus added RefreshControl on WaitListDetails screen. **Registered invalidations**: - `createWaitList` → invalidates `Query.findAllActiveWaitLists` (pre-existing) - `updateWaitList` → invalidates `Query.findWaitListByUuid` **Why**: Details screen showed stale data after updates; list screen showed deleted items until network round-trip after deleteWaitList (previously no invalidation existed, analogous to the `deleteAutoBooking` pattern that already existed). **Where**: - `src/utils/graphClient.ts` — `offlineExchange.updates.Mutation` block - `src/screens/logged/bookings/WaitListDetails/index.tsx` — RefreshControl + `refetchWaitList` from `useQuery` tuple **Decision**: Chose Option B (urql `cacheExchange.updates`) over navigation callback or event listener registry. Rationale: graphcache `updates` is the canonical urql pattern. **Learned**: - Project uses `offlineExchange` from `@urql/exchange-graphcache` (not default `cacheExchange`), which supports `updates`. - Existing convention: `cache.invalidate('Query', 'fieldName')` with NO args. Additionally, Engram also saves a memory dump when closing a work session . In that case, the structure captures the global state: ## Goal [What we were working on] ## Instructions [Discovered preferences or constraints] ## Discoveries - [Technical findings, gotchas] ## Accomplished - [Completed items with details] ## Next Steps - [What is left to do] ## Relevant Files - path/to/file - [what it does or what changed] When does the agent look into the memory? 🕵️♂️ Memory access happens in two ways: Reactive (Explicit): When you ask a direct question, such as: “Do you remember how we solved X?” . Some questions I’ve found particularly useful for my Dailies are: What were we working on yesterday? What did we achieve this week? What do we have left to implement? Proactive (Implicit): The agent will consult the memories on its own if it detects that: It starts working on something that might have been done/resolved before. A topic is mentioned for which the current agent lacks context in its current window. In these cases, the agent searches the Engram history to inject relevant information into the active session. How to install it 💻 If you are on macOS or Linux, you can use Homebrew directly: brew install gentleman-programming/tap/engram For Windows, the official documentation recommends installing via Go: go install github.com/Gentleman-Programming/engram/cmd/engram@latest # The binary will be saved in %GOPATH%\bin\engram.exe (usually %USERPROFILE%\go\bin\) Once installed, you must configure it for your preferred agent. For example: # For OpenCode engram setup opencode # For Claude Code engram setup claude-code (This will install a plugin with everything needed. If you use a different agent, check the details in their GitHub repository ). And that’s it! When you open your agent, you’ll see that the Engram MCP tool has been added. From now on, it will start generating memories of your sessions, categorized by project (the folder where you’re running the terminal). How to sync Engram across different computers? 🔄 Engram allows you to export all global memories or isolate those of a specific project: # Export absolutely all memories engram sync --all # Export memories from a specific project engram sync --project=project-name # Export memories from the current working directory engram sync This will generate an .engram/ folder with the memory compressed into chunks . Just make sure to include this folder in your Git repository. Then, to import the memories on another machine, simply clone the repo and run: engram sync --import 💡 Tip: To verify they were imported correctly, you can run engram stats before and after importing to watch your memory metrics grow. For my use cases, these CLI commands are more than enough. But if you plan to use Engram with a large team, you might be interested in Engram Cloud . The idea is to set up a self-hosted Engram server on a VPS using Docker, serving as a centralized brain for your entire team. BONUS: Graphical Interface (TUI) 🎁 Engram includes a TUI (Terminal User Interface) in case you prefer to manage, search, or delete your memories manually. Just run: engram tui You’ll see an interactive interface similar to this: From here, you can browse through your sessions, explore technical discoveries, and configure your agent integrations. Engram has completely changed my workflow now that I’ve embraced agentic development, allowing me to optimize token consumption while efficiently persisting information. Are you using a memory system for your agents yet? Let me know what you think in the comments. And if you enjoy discovering tools and tricks to boost your Developer Experience (like automating or cleaning up repetitive processes), I invite you to read my article: Practical Guide: How to Patch an NPM Dependency with yarn patch Engram: Adding memory to your AI agents (Claude Code, OpenCode) was originally published in Artificial Intelligence in Plain English on Medium, where people are continuing the conversation by highlighting and responding to this story.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。