long-term-memory
Design a cross-session long-term memory system that extracts, consolidates, and cites durable knowledge from conversation rollouts. USE WHEN: building any…
by MiniMax-AI★ 30 GitHub stars
Install long-term-memory in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Long-Term Memory
Design and operate a cross-session long-term memory system that survives session
boundaries. Mirrors the structure of Codex's codex-rs/memories/ crate.
When to use
Activate when designing any of:
- A pipeline that extracts structured facts from conversation rollouts and writes them to durable storage.
- A global consolidation pass that merges per-rollout facts into higher-level summaries without races.
- A citation protocol so a future agent can audit which memory came from which rollout.
- A "no-op gate" — the system MUST be allowed to write nothing when there is no durable learning.
When NOT to use
- Single-session task state → use
world-state-tracking. - Real-time voice / streaming → out of scope.
- Forgetting-on-purpose privacy filters → out of scope.
Host runtime requirements
This Skill describes how to design a cross-session memory system (Phase 1 extraction, Phase 2 consolidation, citation format, git baseline, watermark). It does not cause the agent to install, modify, or write to persistent storage on its own. Specifically, the agent MUST NOT, on the strength of this Skill alone:
- Read or write files in
~/.codex/memories/,~/.minimax/memory/, or any other per-host memory workspace. No memory directory is implicitly writable by the agent. - Spawn sub-agents or background tasks to perform extraction / consolidation.
- Trigger a Phase 1 / Phase 2 schedule on session start (the host decides when memory runs; this Skill does not).
- Call
redact_secretsor any other exfiltration-mitigation step without the host's normal user-confirmation policy.
All of the above require explicit user confirmation in the host's normal
permission flow (approval_policy, ask mode, or whatever the host uses).
This Skill is for designing the pipeline, not for executing it. The
agent that runs Phase 1 / Phase 2 must follow the host's user-confirmation
policy, not the patterns in this Skill.
Process
A long-term memory system is built from four pieces. Build them in this order.
1. Phase 1 — per-rollout extraction (parallel, idempotent)
The writer of memories. Runs at session start (or on a schedule), claims bounded jobs from a queue, and for each:
- Loads the rollout (JSONL or DB-backed).
- Filters to memory-relevant response items.
- Prompts a model with a JSON schema producing
{raw_memory, rollout_summary, rollout_slug}. - Redacts secrets from the output.
- Persists to durable storage (DB row or file).
Hard rules:
#[serde(deny_unknown_fields)]on the output struct so the model cannot add fields.- Concurrency capped by a single constant (e.g.
CONCURRENCY_LIMIT = 8). Usefutures::stream::iter(...).buffer_unordered(N). - Lease/ownership token prevents two workers from re-extracting the same rollout.
- If a job fails, record the failure with a backoff; do not hot-loop.
- Allow no-op: the prompt MUST include the question "Will a future agent plausibly act better because of what I write here?" and an empty-output escape hatch. If the answer is no, write nothing.
2. Phase 2 — global consolidation (serial, single lock)
The reader of stage-1 outputs. Runs at session start, after Phase 1, with one global lock so two Codexes never consolidate simultaneously.
- Load top-N stage-1 outputs ranked by
usage_countthenlast_usage(fallbackgenerated_at). - Filter by
last_usage >= now - max_unused_days(otherwise stale). - Sync the selected inputs into a workspace as
raw_memories.md(ascending thread-id order, never usage-rank) androllout_summaries/<id>.md. - Prune stale rollout summaries and old extension resources.
- Use git baseline as a cheap state machine:
~/.codex/memories/.git/keeps agit diffagainst the previous successful baseline. If there are no changes, mark success and exit. - If there ARE changes, write
phase2_workspace_diff.mdand spawn an internal consolidation sub-agent with these hard constraints:cwd= the memory root only.ephemeral = true.features.disable(Collab / MemoryTool / Apps / Plugins).approval_policy = Never.network_access = false(or inheriting parent'sPermissionProfile::External).- Disabled from re-entering Phase 1:
memories.generate_memories = falseanduse_memories = false.
3. MemoryCitation protocol
When the model emits memory, it should be able to point at exact lines. Adopt this single-line format:
<citation_entries>
path/to/file.md:10-15 |note=[why this matters]
path/to/other.md:42-50 |note=[other context]
</citation_entries>
<rollout_ids>
thread-abc-123
thread-def-456
</rollout_ids>
Parse with split_once × 3 (location / |note=[ / ]). try_from().ok() style tolerance for malformed lines. De-duplicate rollout_ids with a HashSet.
4. Watermark
After successful Phase 2, write new_watermark = max(claimed_watermark, max(source_updated_at)) to the DB. **Watermarks are monotonically in
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the long-term-memory skill do?
Design a cross-session long-term memory system that extracts, consolidates, and cites durable knowledge from conversation rollouts. USE WHEN: building any system that needs to persist insights across sessions, designing "what should the next agent remember" pipelines, building memory workspaces with git baseline diffing, planning Phase 1/Phase 2 memory architectures, writing JSON-schema-constrained extraction prompts, deciding what NOT to write (no-op gate), or any task involving "memories that survive session boundaries". TRIGGER PHRASES: "long-term memory", "cross-session memory", "memory pipeline", "memory consolidation", "memory citation", "raw_memories.md", "MEMORY.md", "phase 1 extraction", "phase 2 consolidation", "watermark", "no-op gate", "git baseline diff". SKIP WHEN: single-session task state (use `world-state-tracking` instead), ephemeral/short task, no need to survive session boundaries, in-memory only.
How do I install the long-term-memory skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the long-term-memory skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…