Open source. Apache-2.0. Runs locally.
Start fresh.Forget nothing.
Midbar is an open-source tool for Cursor and Claude Code. It tells you when a long agent chat has become expensive, moves the work to a fresh chat, and lets the new agent pull back any earlier command, output or decision, word for word. Everything runs on your machine.
Long chats are expensive. Summaries forget.
Every model call re-sends the entire conversation. Across 813 agent runs from our own Cursor work, runs above 150K tokens of context per call were 39% of runs and 56% of input cost. Each one cost a median 3.9 times a short run.
Compaction trims the context but drops specifics, and not predictably. In a controlled test, the same compaction kept 12 of 12 random values in one session and 3 of 12 in another. The agent that lost them could only say it didn't know.
How it works
Keep the context small. Keep the history exact.
- 01
Measure
Hooks record the token counts Cursor reports for each agent run. A status bar item shows how many tokens the chat re-sends on every model call.
- 02
Switch
Above 150K tokens per call, Midbar suggests a fresh chat when your next prompt starts a new topic, the chat sat idle long enough for the prompt cache to expire, or the last task finished. In Claude Code it moves compaction earlier instead.
- 03
Hand off
The new chat starts with the task, where the work stopped, and about 10K tokens of earlier items ranked against your next request.
- 04
Recall
A local MCP server indexes the old transcript (commands, outputs, messages, edits) with BM25 and returns any item verbatim. One index covers Cursor and Claude Code in the same project.
It adjusts from use. Items the agent had to fetch after a handoff get more weight next time, and switch reasons you keep declining are turned off. All of it is a JSON log you can read or delete.
What it looks like
Install it once. Then just work.
- 01
Install
One command per tool. Midbar asks before it touches your hooks file, and backs it up first.
$ cursor --install-extension midbar.vsix
$ claude plugin install midbar@midbar
Installed. Restart your chats to apply.
- 02
Work as usual
A small meter shows how much conversation rides along with every message. It turns amber when the chat gets expensive.
mainSpacesPython168K/call · new chat? - 03
It picks the moment
When the chat is long and the last task looks done, or your next request is something new, Midbar offers a fresh chat. In auto mode it just opens one.
Midbar This chat re-sends about 168K tokens on every call, and the last task looks finished. Continue in a new chat? The new chat can recall anything from this one.
Continue in new chatNot now - 04
The fresh chat starts informed
The handoff carries the task, where it stopped, and the exact items your next request will likely need. You press Enter.
Continuing from an earlier Cursor chat (id 95339f38). Its full content is archived locally.
Where it stopped: loader retries added, tests pass.
Likely needed: [95339f38:a41c9e02] output of pytest · [95339f38:c7e0b5d1] decision on backoff
My request: add metrics for the retries.
- 05
The agent recalls exactly
Anything else from before is one tool call away, word for word, in Cursor or Claude Code.
midbar · recall("95339f38:c7e0b5d1")
assistant, earlier chat
Retries use exponential backoff with jitter, capped per request, so a slow bucket can't stall the loader.
- 06
See what it saved
Every handoff is measured from your editor's own token counts, before and after.
$ midbar savings
95339f38 → dfddb35c: 128K → 43K tokens per call after the handoff (66% less)
Illustration. The chat ids, the meter reading and the savings line are from a real handoff; the chat text is an example.
What we measured
Early numbers, with their caveats.
- fewer tokens per model call right after a handoff, median of 3 real handoffs.
- 70%
- Range 66% to 77%, Cursor
- facts right for a fresh agent with handoff and recall, same as the full-context agent, at a median 34% of the cost.
- 144/144
- 6 paired runs, synthetic task
- lower input cost replaying Midbar's switching rule on 813 real Cursor runs.
- 43%
- A plain 150K cutoff: 45%, more switches
Small samples from one developer. The benchmark was easy enough that both arms scored 100%, so it shows the cost difference, not a quality difference. Methods, scripts and results are in the repo. A larger benchmark on real coding tasks is next, and its data will be published too.
What's new here, and what isn't.
Keeping the full history and letting an agent search it is not new. LCM, lossless-claw, episodic-memory and Cursor's own chat history file all do a version of it, and they are worth a look.
Midbar works on the parts around that: deciding when to start over, choosing what the new chat should carry, and measuring whether any of it saved money, with prompt-cache costs counted. It also keeps one archive across Cursor and Claude Code, so you can start a task in one and finish it in the other.
Known limits.
- In Cursor the last step is yours. There is no API to send a message into a new chat, so Midbar opens it prefilled and you press Enter.
- Per-run token counts come from a field in Cursor's stop hook that isn't documented. If it goes away, the meter goes blank.
- The switching rule and the ranking are tuned on one person's work so far.
- Claude Code limits what a hook can inject to 10,000 characters, so most history stays one tool call away.
Open source, local, inspectable.
- Apache-2.0. Plain Python with no dependencies, plus a small editor extension.
- No network calls. It reads the logs your tools already keep and writes only to one folder in your home directory. Delete it and it's gone.
- A Cursor extension and a Claude Code plugin, sharing one archive per project.
# Cursor
cursor --install-extension midbar.vsix
# Claude Code
claude plugin install midbar@midbar