tencentdb-agent-memory (Claude Code plugin)

Four-layer long-term memory (L0 Conversation → L1 Atom → L2 Scene → L3 Persona) for Claude Code, inspired by Tencent/TencentDB-Agent-Memory.
Fully local — no external Gateway, no paid API, no Python. All extraction and consolidation is done by the Claude agent itself.
Installation
# Add marketplace
claude plugin marketplace add https://github.com/baodq97/tencentdb-agent-memory
# Install plugin
claude plugin install tencentdb-agent-memory
Standalone CLI (npm)
The tmem CLI is also published on npm, CLI-only (no plugin assets), for use
outside Claude Code:
npx @baodq97/tmem <command> # run once, no install
npm i -g @baodq97/tmem # or install globally → `tmem`
tmem version # resolved version + path + node
tmem update # check npm for a newer release (--apply to install)
Requires Node ≥ 24 (node:sqlite DatabaseSync is flag-free from 24). The
embedding model (~314 MB, EmbeddingGemma-300M GGUF) downloads on first embed use
into ~/.memory-tencentdb/models/, not at install.
Quick start
# Inside Claude Code:
/memory-init
# → installs deps, links tmem CLI, creates store
# → hints: "ask me to seed memories"
# then say "seed memories" → agent extracts L1 atoms
# then say "consolidate memories" → agent builds scenes + persona
# done — hybrid recall is now active automatically
What happens automatically
| Hook | Action |
|---|
SessionStart | Inject the tier-0 persona core once per session (<persona-core>) + keep the global tmem shim current |
UserPromptSubmit | Hybrid recall (FTS5 + vector + RRF, relevance-floored) + L2 scene-navigation index -> inject <memory-context>. Scoped to the project store; tmem recall on the CLI still reads global + project. |
Stop | Auto-capture turn; spawn a detached headless consolidation once N new turns have accumulated |
SessionEnd | Mark session as pending for later seeding; spawn consolidation for a session that produced ≥3 new turns |
Hooks never block — failures degrade to no injection.
Consolidation runs outside the session, as a detached claude -p subprocess
that outlives it, so it costs the session no context and cannot be skipped by the
session declining to dispatch. Two arms fire it: a turn counter, and the session
boundary — the median session is short enough that a counter alone never reaches
most projects. Success is a measured store delta, never the child's exit code
(a validating run reported success while the store was byte-for-byte unchanged);
every run appends its verdict, cost and delta to consolidation_runs.jsonl, which
tmem status summarises. Turn it off with tmem config auto-consolidate off.
How recall works
Each turn, the UserPromptSubmit hook builds a <memory-context> block from three layers:
- L3 persona — the
conditional persona bullets this prompt actually reaches for, plus a short always-on insurance line (see How the persona reaches the agent).
- L1 atoms — hybrid search (FTS5 keyword + EmbeddingGemma vector, merged via RRF) over the most relevant memories, within a token budget.
- L2 scene-navigation — a heat-ranked index of scene blocks (name + heat + summary), project scenes first then global, with its own token budget. Full scene content is not inlined; load it on demand with
tmem scene <name> (progressive disclosure — cheap always-on index, full read only when needed).
Tune the scene-navigation budget with tmem config scene-max-tokens N (0 disables it).
How the persona reaches the agent
A consolidated persona grows well past what any per-turn budget can carry (~39k chars here). Rather than truncate it, each bullet is classified by duty and delivered on the channel that duty needs:
| Duty | Tier | Channel | Budget |
|---|
always | 0 | SessionStart hook → <persona-core>, once per session | persona-max-tokens (default 1200) |
conditional | 1 | UserPromptSubmit recall → <persona>, query-matched per turn | ~105 tokens |
reference | 2 | on demand — tmem persona --section <name> | none (never injected) |
Tier 0 is paid once per session, not per turn, which is what makes a budget that size affordable. The tier-0 block also carries a one-line index of every section name — including sections it delivered nothing from — so the tier-2 pointer is something the agent can actually act on.