kg-memory: persistent memory for coding agents
This repository is no longer maintained. The project has moved in a different direction and development continues elsewhere. The code, the releases up to 0.17.0 and the kg-memory package on PyPI stay available as they are, but they will get no further updates or fixes, and issues and pull requests will not be answered.
Your coding agent forgets everything when a session ends. kg-memory gives it a memory that lasts: how your project fits together, what was decided and why, how you like to work, and which mistakes were already made once. Claude Code and Codex CLI share it; Antigravity CLI support is experimental.
It installs as a plugin for your agent plus a small server on your machine that holds the memory. It is free and open source (MIT), and it stays that way: no paid tier, no account, no API key, no telemetry. What it costs you is some context in each session and, only if you switch on background upkeep, some of your subscription quota (details).

Why it's worth trying
Without memory, every session starts from zero. The agent re-reads the files it read yesterday, re-derives the conclusions it already reached, and you explain your preferences again. kg-memory keeps what the agent learns and brings it back without being asked:
- At session start, the most important memories are already in context.
- When you type a prompt, memories that match it arrive with the prompt.
- When the agent reads or edits a file, what it learned about that file arrives with the tool result, usually before it changes anything.
- When another session writes something relevant, yours is told, instead of writing the same lesson twice.
What makes it more than a notes file:
- Lessons, not logs. Each memory is a small node: a one-line lesson (the gist), notes with the cases behind it, pointers into the files it concerns, and named links to related memories. That's why it's called a knowledge graph. The agent writes one at the moment it learns something, so next time it reads the conclusion instead of working it out again.
- It stays small. Each session sees a fixed budget of memory. What gets used, credited and connected stays on top; the rest moves to an archive that is still searchable and one read away.
- It tells you when it needs tidying. The memory tracks its own upkeep: overlong entries, file pointers that no longer resolve, repeated incidents that should become one lesson. A maintenance pass cleans it up, run by you or, if you switch it on, in the background.
- One memory for all your agents. Claude Code and Codex talk to the same local server, so what one learns the other knows.
- Yours to inspect. Plain JSON under
~/.knowledge-graph/, versioned with git if you want history, browsable in a visual editor (kg editor).
What a day with it looks like
You don't operate the memory; the agent does. You mostly notice it in the answers.
- Morning. You open a session. The most useful memories are loaded before your first message; the agent reads the rest once and says "I have recalled KG Memories".
- During work. You ask about the deploy script, and the note about its one non-obvious flag arrives with your question. The agent reads a config file, and the memory that says "generated, edit the template instead" arrives with it.
- When something is learned. The agent traces a failing test to a timezone assumption in a fixture, or you say you prefer small commits. It writes that down there and then. You can also just say "remember that…".
- When memory is wrong or missing. Correct the agent as you would anyway. It updates the lesson. If the memory existed but didn't surface, the agent reads it back and reports the miss; the report is what keeps that memory from sinking again.
- Wrapping up. Tell the agent you're wrapping up. It's the natural moment for it to write down what the session learned and credit the memories that actually helped, which keeps them on top.
- Over weeks. Memories nobody uses sink into the archive; the ones that keep helping stay visible. When upkeep is overdue, the memory says so;
/kg-maintain runs a bounded cleanup, or background upkeep does it for you.
How mature it is