Guides

Persistent memory for Claude Code and Codex CLI

memtrunk memory stores context from your coding sessions and returns relevant parts to the agent later. Once enabled, it works automatically for Claude traffic through the proxy. Codex CLI and other clients use the same memory through an MCP server. Memory is not on by default; it must be turned on and given a model.

Coding agents start each session without knowing what you decided yesterday. Memory is memtrunk's answer to that, kept per user and per project. This guide covers how it works, what has to be switched on, how to connect Codex CLI and other clients, and what you can export, delete and turn off. It also states what memory does not promise.

What memory does

memtrunk memory has four stages:

  1. Capture. With your opt-in and a per-project switch, conversation turns that pass through the proxy are written to a private inbox. Credentials are scrubbed first.
  2. Index. An embedding worker indexes each turn so it can be searched by text and by meaning.
  3. Distill (optional). With a model you connect, sessions can be consolidated into decisions, conventions and procedures. Consolidation is a separate instance setting that is off by default. Once a model is connected, recall injects synthesized knowledge rather than raw turns, whether or not consolidation is on.
  4. Recall. When a later request arrives, memtrunk looks for relevant memories and, if it finds something good enough, adds them to the request.

Memory is scoped to the signed-in user and to a project. Sharing with teammates in your organization is a per-project switch and is off by default.

Two ways to use it

Through the proxyThrough the MCP server
ClientsClaude Code, or any client sending Claude-shaped trafficCodex CLI and any other MCP client
How it worksMemory is captured and recalled automatically on the request pathThe agent calls memory tools when it chooses to
Client setupNone beyond pointing the client at memtrunkAdd memtrunk as an MCP server

Proxy memory covers requests on the Anthropic Messages route. Requests on Codex CLI's routes do not get proxy memory, because capture and recall are not wired into them. Recall is built when the Claude pool is predicted to serve the request first, so a request served by a different provider gets no recall. That is a prediction made before the call, not a guarantee about delivery.

Turning memory on

Memory is off by default, and several switches have to line up:

  1. The instance has memory enabled. Capture and injection are instance settings, both off by default. If they are off, an administrator of your instance has to turn them on first. There is nothing in your own console to flip instead.
  2. Memory is enabled for your account. The account-level setting is off by default, and it is not self-service: an administrator sets it on your user from the Users page.
  3. A model is connected. The Memory page shows "Connect a model to turn on memory" until you choose where memory gets its model access: a subscription account or a provider key. Injection uses synthesized knowledge, not raw turns, so it needs a model for that step.
  4. Projects are switched on. On the Memory page, Projects tab, each project has Collect, Share with team and Inject columns. Collect controls capture and is on for a project unless it has been turned off. Inject controls whether recall is added to requests; each project can set it on, off or inherit.

The Memory page has Overview, Projects, Models & tasks, Memories, Graph and Recall tabs. Use them to see what is stored and to test what recall returns.

What happens on Claude requests

When recall finds something relevant, memtrunk adds a <recalled_memory> block to the latest user message, on a copy of the request. By default the block goes into the user message rather than the system prompt, which keeps the start of the prompt unchanged for prompt caching. By default the block is capped at about 8,000 characters; an administrator can set that cap anywhere from 1 to 64,000. When confidence is low, memtrunk injects nothing.

memtrunk may also add a short note that explains the memory mechanism to the model. An administrator setting can move that note into the system prompt. If you see <recalled_memory> or <memory_search> text in a session and it looks unexplained, it comes from this layer and not from your client.

Credentials in captured text are scrubbed before storage. That is pattern-based, so it is not a guarantee against every secret written in ordinary prose. To stop capture for a project, turn off its Collect switch on the Memory page. To stop collection everywhere, use Turn off memory (see below).

Memory over MCP

For Codex CLI and other clients without the proxy in their path, memtrunk serves memory as an MCP server.

  • Endpoint: https://memtrunk.your-host.dev/mcp, using MCP's Streamable HTTP transport. It is stateless: each POST is answered inline, and a GET returns 405.
  • Authentication: the API key you already created, sent as Authorization: Bearer <your memtrunk API key> or as x-api-key. Failed authentication is an HTTP 401 or 403, not a protocol error. If memory is not enabled for your account, the response is 403 "Memory is disabled for this user".
  • Scope: every tool works on the authenticated user's own memory. Arguments cannot name another user.
  • Spend limits: the MCP route does not run the spend check, so a key at its cap can still use memory. See spend caps.

There are five tools:

ToolWhat it doesNotable arguments
memory_recallSearches memory for relevant facts, procedures and contextquery (required), project, tiers, k (1 to 50), session_id
memory_rememberStores a durable memory that can be recalled right awaycontent (required), project, kind, summary, concepts, entities
memory_entitiesBrowses entities extracted from your memoryproject, query, entity_type, limit (up to 200)
memory_graphReturns the one-hop subgraph around a named entityentity (required), project, limit
memory_statusReports memory health, project consent and scope state, and item countsproject

A tool that runs but is refused for a domain reason, such as a consent opt-out, returns a normal result with isError: true so the model can read why.

Connecting a client

Both clients support remote HTTP MCP servers. For Claude Code, using its documented claude mcp add syntax:

bash
claude mcp add --transport http memtrunk-memory https://memtrunk.your-host.dev/mcp \
  --header 'Authorization: Bearer ${MEMTRUNK_API_KEY}'

The single quotes keep your shell from expanding ${MEMTRUNK_API_KEY}, so the key stays out of your shell history. Claude Code's MCP documentation describes ${VAR} expansion in the headers of .mcp.json; check that your version also expands it for a server added from the command line. If it does not, the literal text is sent and memtrunk rejects the request with a 401 or 403.

For Codex CLI, in config.toml, with the key in an environment variable of your choosing:

toml
[mcp_servers.memtrunk-memory]
url = "https://memtrunk.your-host.dev/mcp"
bearer_token_env_var = "MEMTRUNK_API_KEY"

The Claude Code form follows its MCP documentation. The Codex CLI form uses the [mcp_servers] settings in its config.toml (url and bearer_token_env_var for a remote HTTP server), as defined in its open-source repository. Client syntax changes between versions, and memtrunk has not run these snippets against a live client, so check your client's MCP documentation for the exact form. Because the agent decides when to call the tools, MCP memory does not inject anything on its own the way proxy memory does.

Export, delete and turn off

  • Export. On Profile, Export my memories downloads a JSON file of your own stored memories. It is bounded to 5,000 rows and 10 MiB and either completes or fails, never a partial file. Strings are scrubbed again. It is not a full account archive.
  • Delete a project's memories. On the Memory page, Projects tab, Delete & stop collecting permanently deletes all stored memories for that project and turns Collect off. The sibling Delete all deletes the memories but leaves Collect on, so new turns keep being captured. Neither can be undone.
  • Turn off. On the Memory overview, Turn off memory stops collection and injection for every project. Stored memories are kept.

Retention windows are instance settings. The defaults are 30 days for the capture inbox and 30 active days for stored verbatim memory.

Where your data goes

Embedding and reranking run on the deployment's own embedder service, so no third-party embedding API sees your content. That is a separate service in the deployment, and it can be run on another host. The optional distillation step sends text to the model you connected, through the gateway, and its spend is metered with a per-user daily soft cap that defaults to 5 USD. Session content capture is off by default.

What memory does not promise

  • No benchmark numbers. memtrunk does not publish scores here. Results depend on your projects.
  • No guaranteed deletion. Deleting by project or session is a database cleanup. A capture or indexing pass already in flight may write rows after it, and durable markers to prevent that are not decided yet.
  • No automatic learning of what is useful. Recall ranks by relevance. It does not learn which memories helped.
  • Distilled knowledge is not assured. Consolidation is off by default, so with it off there may be little distilled content to recall.
  • Not every client, not every request. The proxy path covers Claude-served requests. Everything else goes through MCP.

For the capability list, see the features page. For how access and credentials are handled, see security.