The memory we recommend for your agents is Glen, shared memory for coding agents.Go to tryglen.com →
How it works3 min read

Glen, shared memory for coding agents

Capture, store, recall: how memory for AI agents works

Agent memory works in three stages. Capture records each turn, ideally through the agent's hooks so nothing depends on the model choosing to save. Store keeps those records for the organization alongside other sources, and recall returns the relevant memories, either injected before the model reads a prompt or on demand through a search.

Get Glen for your agents
On this page
  1. 1. Capture: hooks, not save tools
  2. 2. Store: one organization memory
  3. 3. Recall: injected or searched
  4. The same pipeline over MCP
  5. Frequently asked questions

1. Capture: hooks, not save tools

Most memory tools expose a save call and hope the model uses it. Glen's plugins attach to lifecycle hooks the agent fires anyway, and each hook runs one glen CLI command. The model never has to think about memory for capture to happen.

What Glen hooks into, per agent
AgentHooks Glen usesWhat gets recorded
Claude CodeSessionStart, UserPromptSubmit, Stop, PostToolUse on BashPrompt, reply, tool calls and results, thinking blocks, repo, branch, commits
CodexThe same four, in ~/.codex/hooks.jsonPrompt and final reply
CursorsessionStart, beforeSubmitPrompt, afterAgentResponse, afterShellExecutionEach prompt and response
Grok BuildPlugin installed by glen install --agent grokSessions, with recall through glen search
PiPackage installed by pi install npm:@tryglen/piSessions, with recall each turn

The PostToolUse hook on Bash links every git commit to the session that made it. That link is what later lets glen code-search go from a line of code back to the conversation behind it.

2. Store: one organization memory

Captured turns go to a hosted memory owned by your organization. Integrations add public Slack channels, GitHub (which can include private repos), tickets, docs and meeting transcripts. You don't manage an index or a schema; you install plugins and connect sources.

Two things happen to the store over time. Decisions get reversed, and Glen aims to follow the one that stuck. And some memories turn out wrong: glen forget stops one being recalled, and glen restore reverses that.

3. Recall: injected or searched

  • Injected. In Claude Code and Codex, UserPromptSubmit sends the prompt with repo and branch, and matching memories join the context before the model reads it. Pi recalls at the start of every turn.
  • Searched. Cursor and Grok Build can't add context from a hook, so a rule tells the agent to run glen search. Any agent or person can do the same.
  • Traced. glen code-search <path:start-end> "<question>" follows git blame to the agent sessions that wrote those lines.

The same pipeline over MCP

Agents without a Glen plugin can reach the memory through the remote MCP server at https://mcp.tryglen.com/mcp (Streamable HTTP, OAuth 2.1 or a personal API key). It exposes 22 tools, among them glen_search, glen_code_search, glen_forget and glen_import, with a 60 second request limit and a 4.5 MB request size limit. Setup per client is covered on memorymcp.dev.

Does the pipeline pay for its round trips? Glen's replay of 100 merged PRs found 29% fewer tokens and 21% faster runs with memory, quality at parity or better. Recall in that test was injected before the first turn.

Frequently asked questions

How does an AI agent retrieve memories?

Either the memory is injected into context before the model reads the prompt, or the agent calls a search tool when it decides it needs past context. Glen does injection where the agent's hooks allow it and search everywhere.

Does agent memory slow every prompt down?

Each hook is a network round trip. In Glen's PR replay, runs with memory were still 21% faster overall with that time counted.

What does Glen record from Codex?

The prompt and the final reply for each turn, plus repo and branch, through hooks that glen install registers in ~/.codex/hooks.json.

Can I delete a wrong memory?

Run glen forget on it and it stops being recalled. It is reversible with glen restore, so a mistaken forget can be undone.

More in this guide

Related guides on agent memory

Fix your agents’ amnesia.

Glen gives your agents the memory of every session your team has run. Start on your own or with up to two teammates. Your first 15,000 memories are free, no credit card.

Start free at tryglen.com