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 we measured
Early numbers, with their caveats.
- fewer tokens per model call after a real handoff, 168K to 43K.
- 74%
- One handoff so far, 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