---
title: "Long-term memory for a coding agent"
description: "Give Claude Code, Codex or another MCP client long-term memory with one command: the agent reads context before a task and saves files and memories that are available in the next session."
url: https://mirabase.io/use-cases/coding-agent-memory
last_updated: 2026-11-26
lang: en
---

# Long-term memory for a coding agent

Connect the coding agent to Mirabase over MCP with one command. It then reads what is already known before a task, and saves documents as files and lasting statements as memories, so the next session starts from them.

## Set it up

1. Sign in to the [console](https://console.mirabase.io) and create an API key. Give the agent a key of its own, not your root key: see [Set up an Agent](https://mirabase.io/developers/permissions#agents).
2. Add the MCP server.

```sh
export MIRABASE_API_KEY="mb_live_..."

# Claude Code
claude mcp add --transport http mirabase https://api.mirabase.io/mcp \
  --header "Authorization: Bearer $MIRABASE_API_KEY"

# Codex
codex mcp add mirabase --url https://api.mirabase.io/mcp \
  --bearer-token-env-var MIRABASE_API_KEY
```

3. Check the key.

```sh
curl https://api.mirabase.io/v2/whoami \
  -H "Authorization: Bearer $MIRABASE_API_KEY"
```

The response lists the key's capabilities and the Spaces it can read and write. Any other MCP client that supports Streamable HTTP and can send a header connects the same way: see [Connect an Agent](https://mirabase.io/developers/agents#connect).

## What the agent does with it

| When | Tool | Effect |
| --- | --- | --- |
| Before a task | `mira.context` | Returns a pack of relevant files and memories within a token budget |
| Looking for something specific | `mira.search` | Returns passages that match by words and by meaning |
| Saving a document, notes or a plan | `mira.files.write` | Writes a file at a path; every write keeps a version |
| Recording a statement that stays true | `mira.memory.remember` | Stores a memory, such as a decision or a preference |
| Fixing a wrong memory | `mira.memory.correct` | Replaces the memory and keeps the old statement as history |

The server tells the model what each tool is for in the `instructions` of its handshake. The recommended order is in [Recommended call order](https://mirabase.io/developers/agents#loop).

## Limits

- `https://api.mirabase.io/mcp/lean` offers six tools for agents that only need memory and files. See [Toolsets](https://mirabase.io/developers/agents#toolsets).
- Writing a project memory requires the `memory:confirm` capability. Without it, use files, or ask the Space owner to grant it.
- `mira.memory.forget` erases a memory permanently. Use `mira.memory.correct` to fix one.
- A tool call counts as two requests against the rate limit: the MCP call and the API request it makes.
- An agent that changes a file it does not own creates a proposal for review unless the Space owner has set its write mode to `direct`. See [Agent write mode](https://mirabase.io/developers/permissions#write-mode).
