segmem
Long-term memory for coding agents that knows the difference between
who you are, how this repo works, and what happened on Tuesday.
One Python file. SQLite. No server, no daemon, no API key. Works with any
agent that can run a shell command. On Claude Code and Codex CLI, hooks make
the startup read and per-prompt recall automatic.
The problem
An agent forgets everything when the session ends. Bolt-on memory tools fix
that by appending every note to one timeline, and two things go wrong:
- Noise. "PR #412 is awaiting review" and "you prefer rebase over merge"
land in the same list, and the first kind outnumbers the second fifty to one.
- Bleed. A convention from one repo ("uses npm") gets read as a preference
and followed in the next repo, where it's wrong.
Both come from the same mistake: storing facts with different lifetimes on one
axis. segmem gives each fact a kind (how it decays) and a scope (where
it applies), then loads only what the current project needs.
What the agent sees
At the start of a session, in the segmem repo:
## Memory (project: segmem)
### Identity
#3 prefers short commits, one concern each (global)
### Procedural
#7 prefers pnpm (global) OVERRIDDEN by #12 uses npm, Lambda runtime needs it (segmem)
#9 tests: python3 test_segmem.py (segmem)
### People known: alice
Run `segmem recall <name>` before acting on or about them.
### Episodic (segmem), oldest first
#0-3 2026-08-21 chose SQLite over DuckDB; stdlib, WAL, FTS5
#4 2026-08-21 naps come due only for blocks the wake cover prints
#5 2026-08-22 wake runs from a SessionStart hook; the agent skipped it once
You are awake.
Global preferences load whole. The project's conventions load whole and win
over global ones, with both shown so the agent knows why. History loads with
detail that decays: yesterday verbatim, last month as one line. People load
as names only; the agent looks them up when they come up.
Install
Requires Python 3.8 or later and git. Nothing else.
As a Claude Code plugin
/plugin marketplace add mahuebel/segmem
/plugin install segmem@segmem
That's the whole install: the three hooks register automatically, and the
doctrine (what to record and when) is injected at session start, so there is
no CLAUDE.md paste and no settings.json merge. Skip the manual steps below.
The hooks they print claim each session with --once, so running both no
longer doubles wake and recall, but it still starts a second process per event.
Any harness
git clone https://github.com/mahuebel/segmem ~/.segmem/src
~/.segmem/src/segmem init
init prints two things:
- A
## Memory block. Paste it into ~/.claude/CLAUDE.md (or your agent's
AGENTS.md). It tells the agent what to record and when.
- A
hooks block. Merge it into ~/.claude/settings.json (Claude Code) or
save it as ~/.codex/hooks.json (Codex CLI); both use the same shape. It
makes the harness run wake at every session start and search memory on
every prompt, so neither depends on the agent remembering.
On a harness without hooks (Cursor, Aider, your own), skip step 2. The prompt
block alone carries it: the agent runs wake and recall itself. That works,
but it relies on the agent following instructions. If your harness can run a
command at session start or pipe each prompt to a command, point it at
segmem wake and segmem hook; hook accepts the JSON that Claude Code and
Codex send, or plain text, on stdin.
Start a new session. The first wake prints an empty header; the agent fills
it in as you work.
Kinds
| Kind | Holds | At wake | Replaced by newer facts? |
|---|
identity | who you are, how you like to work: "prefers" | loaded whole | yes |
procedural | how this project works and why: "uses" | loaded whole | yes |
episodic | decisions with reasons, root causes, handoffs | decaying window | no, it's history |
people | who someone is | names only | yes |
The word choice is the classification. Prefers is about you and goes
global. Uses is about a repo and stays there.
Tags
--entities=a,b tags a fact with its subjects: people, components, files.
Tags are one vocabulary across projects. When you write one that matches an
existing tag ignoring case, the stored spelling wins; when it's new but close
to an existing one, note says so (new tag: github_actions (similar: github-actions)), and you use the suggestion next time. A tag that looks
like a name with no people record gets a nudge to create one. recall
prints tags in brackets so you can see what's in use.
Tags earn their keep in three places: they pair project facts with the
global facts they override, they let promote match the same fact across
projects, and they're what makes a capitalized word in a prompt count as
something worth looking up.
Scope