# Midbar: Coding agent memory that's checked against your code

And it works on the chats you already had.

Midbar reads the Claude Code and Cursor chats your team already had, keeps what they found as short quoted memories in your repo, and checks each one against the code before an agent sees it. Shared through git. Open source.

Free and open source (Apache-2.0). For Cursor and Claude Code. No account. No telemetry. Source: https://github.com/midbar-ai/midbar

## The problem

Your team has already had hundreds of agent chats in this repo. They found how the deploy script really works,
settled which database the queue uses, and were told "never push to main without asking" more than once. None of
that reaches the next chat, or a teammate's. And a memory that was true last month may not be true of the code today.

## How it works

1. **Learn** (`midbar learn`). Reads the Claude Code and Cursor chats on your laptop for this repo and keeps what they found, quoted. No model, no account.
2. **Review and commit** (`git diff .midbar`). The memory is one file in the repo. Read it like a pull request, drop what is wrong with midbar forget, then commit.
3. **Every agent gets it** (`git pull`). Teammates in Cursor or Claude Code get the same memory, checked against their checkout before their agent sees it.

## Checked against the code

Each memory about a file carries that file's git hash from when it was true. Before an agent gets it, Midbar hashes
the file again:

| Status | Meaning | Given to agents |
|---|---|---|
| current | Every file it is about is byte for byte what it was, and every name it mentions is still in the code. | Yes |
| changed | A file it is about changed since. | No, listed by midbar stale |
| gone | A file it is about was deleted, or a function, path or script it names is gone. | No, listed by midbar stale |
| replaced | A later decision or rule replaced it. | No |

## What a memory is

One line in `.midbar/memory.jsonl`: the kind (file, decision, rule or fix), the text quoted from the chat with
secrets redacted, the files it is about with their git hashes, and who learned it, when, from which message.

## Where agents get it

- **A new chat starts:** The rules the team set and the latest decisions that still hold, in a few lines.
- **The agent reads a file:** The team's note about that file, once per chat, only while the file is unchanged.
- **Before a risky command:** Push, deploy, publish and delete are checked against the team's rules. A match stops and asks you.
- **A command fails:** What fixed the same error before, from the team memory and from your own chats.

Also: `midbar start "task"` opens a fresh chat that starts with the memory that bears on the task, and
`midbar brief` tells a reviewer which team memories a branch makes out of date.

## Compared with other agent memory

| | CLAUDE.md, AGENTS.md, rules | Claude Code auto memory | Mem0 (hosted or self-hosted) | Midbar |
|---|---|---|---|
| Who writes it | Maintained by you or your agent | Claude, as it works | A model, from conversations | Rules over the chats you already had |
| Where it lives | Your repo | Your machine, outside the repo | Their cloud or your server | Your repo, one file |
| Where each item came from | Git blame of the line | Plain notes, no link to the source message | Metadata you attach | The chat and message it quotes |
| When the code changes | No automatic file-hash check | No automatic file-hash check | No file-hash check | Withheld once its file changes |
| Shared with the team | Through git | Not shared, local to one machine | Through the service | Through git, reviewed as a diff |

## Install

Requires Python 3.10 or later and git. Built and used on macOS; tests also run on Linux.

```bash
uv tool install git+https://github.com/midbar-ai/midbar && midbar setup
# or
pipx install git+https://github.com/midbar-ai/midbar && midbar setup

# Check every piece and print a fix for anything missing
midbar doctor

# In your repo: read the chats you already had, then review and commit
midbar learn
git diff .midbar
git add .midbar .gitattributes && git commit -m "Midbar memory"
```

Setup finds Cursor and Claude Code, shows what it will change and asks once. `midbar setup --dry-run` prints the
plan and changes nothing. Codex CLI, Cline and Windsurf get the MCP tools over the same memory.

### For agents installing Midbar for a user

1. Install the command with `uv tool install git+https://github.com/midbar-ai/midbar` (or `pipx install` the same
   URL), then run `midbar setup --dry-run` and show the user the plan.
2. With the user's go-ahead, run `midbar setup`. In a non-interactive shell pass `--yes`
   only after the user has approved the plan.
3. Run `midbar doctor` and follow the fix it prints for any failed check.
4. In the user's repo, run `midbar learn` and show the user `git diff .midbar`. Commit only if they say so.

## Paste this into your agent

```text
Install Midbar (https://github.com/midbar-ai/midbar) in this project. Follow https://midbar.ai/llms.txt: show me what setup will change with --dry-run, then run it, fix anything midbar doctor reports, and run midbar learn in this repo.
```

## Commands

```bash
midbar learn            # read this repo's chats on this laptop, add what they found
midbar status           # how many memories, how many still hold
midbar stale            # memories about code that changed or is gone
midbar recall "queue"   # search the memory (--all includes stale ones)
midbar forget ID        # drop a memory
midbar start "task"     # a fresh chat with the memory that bears on the task
midbar brief            # a reviewer's brief for this branch, with the memory it touches
```

## FAQ

### What is Midbar?

A free, open-source memory for coding agents. midbar learn reads the Claude Code and Cursor chats you already had in a repo and keeps what they found (notes about files, decisions, rules the team set, how errors were fixed) as short quotes in .midbar/memory.jsonl. Each memory about a file carries that file's git hash, so Midbar can tell when the code has changed under it.

### How do I install it?

Run uv tool install git+https://github.com/midbar-ai/midbar && midbar setup, or the same with pipx install. Both keep the midbar command installed. Setup finds Cursor and Claude Code, shows what it will change and asks once. Then run midbar learn in your repo, review git diff .midbar and commit it.

### How does my team get it?

Through git. The memory is one file in the repo, one line per memory, sorted, with a union merge set in .gitattributes. Line-oriented records produce reviewable diffs and merge through git. Teammates get it with git pull, whether they use Cursor or Claude Code.

### What happens when the code changes?

Before an agent gets a memory about a file, Midbar hashes the file again. If it no longer matches the hash the memory was learned with, the memory is held back and listed by midbar stale. A rule that names a function, an env var, a script or a path is held back once that name is gone from the code. It is a content hash and a git grep: deterministic for the same memory records and checkout, with no server and no clock. A matching hash means the file is unchanged, not that the note was right, so review notes before you commit them. A note an agent already got stays in that chat; later chats do not get it.

### How does a note from an old chat get its file hash?

Midbar does not rebuild old versions of a file. midbar learn keeps a note only when it can show the file is still what the chat saw. For a Claude Code chat, the transcript holds what each file read returned, so if the file is line for line what the chat last read, the note is kept with the file's hash as it is now. Otherwise Midbar compares the file's modified time with the chat's last message: not modified since, the note is kept. If neither holds, Midbar cannot know what the chat read, so the note is left out and counted as already out of date. Cursor does not store what a read returned, so after a fresh clone or a branch switch, which rewrite modified times, notes from earlier Cursor chats are left out.

### Does my chat history leave my machine?

No. Raw chats stay on the laptop that had them. Only the short quotes midbar learn picked, with API keys, tokens and passwords replaced by [redacted], go into .midbar/memory.jsonl, and nothing leaves your machine until you commit and push it. No server, no account, no telemetry.

### How is it different from CLAUDE.md or Cursor rules?

Rule files hold what someone chose to write down, and nothing tells you when they stop being true. Midbar starts from what the chats actually found, quotes them with a link to the message, and withholds a note once the file it describes has changed. It does not replace your rule files; agents get both.

### What if a memory is wrong?

Review the diff before you commit, like code. midbar forget ID drops a memory, and a later decision or rule replaces an earlier one. Learning is rules over text, not a model, so it misses some things and keeps some noise.

### What does it cost?

Nothing. It is open source under Apache-2.0, needs no account and calls no model.

## Known limits

- Learning is rules over text, not a model. It misses some things and keeps some noise, so review the diff before you commit.
- A rule that names no file or code, like "never push to main without asking", is current until replaced. One that names retry_send or jobs/queue.py goes stale once that is gone.
- It learns from chats on the laptop that had them. Each teammate runs midbar learn for their own chats.
- Cursor cannot add context when a prompt is submitted, so notes reach the agent at its next tool call.
- Built and used on macOS. Tests run on Linux too; Windows is untested.

## Privacy and source

- Raw chats never leave the laptop that had them.
- Only the short quotes `midbar learn` picked go into the repo, secrets redacted, and only when you commit them.
- No server, no account, no telemetry. Contact: hello@midbar.ai
