folded-memory-implementation

folded-memory-implementation is a skill for Claude Code, Codex from simbajigege/book2skills. It costs 70 tokens per session (3,343 once invoked), scanned A, original, MIT.

A developer guide for hierarchical memory in an AI agent. It keeps recent conversation turns in detail, compresses older turns into episodes, and distills the oldest information into durable facts.

In plain words
What is it for?
Use it to design memory that moves information between working, episodic, and semantic layers and recalls the appropriate level of detail during later turns.
Why use it?
It preserves useful long-term knowledge without keeping the entire conversation at full length, while retaining more detail for recent work.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to design memory that moves information between working, episodic, and semantic layers and recalls the appropriate level of detail during later turns.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/simbajigege/book2skills/folded-memory-implementation
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add simbajigege/book2skills --skill folded-memory-implementation
Clone the repo
git clone --depth 1 https://github.com/simbajigege/book2skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for folded-memory-implementation

README.md
[![agentmods](https://agentmods.dev/badge/skills/simbajigege/book2skills/folded-memory-implementation/github.svg)](https://agentmods.dev/skills/simbajigege/book2skills/folded-memory-implementation)
Your own site
<a href="https://agentmods.dev/skills/simbajigege/book2skills/folded-memory-implementation"><img src="https://agentmods.dev/badge/skills/simbajigege/book2skills/folded-memory-implementation/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for folded-memory-implementation

Your own site · 80×15
<a href="https://agentmods.dev/skills/simbajigege/book2skills/folded-memory-implementation"><img src="https://agentmods.dev/badge/skills/simbajigege/book2skills/folded-memory-implementation.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 70 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,343 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00070 $0.03343
Opus 5 $0.00035 $0.01672
Sonnet 5 $0.00014 $0.00669
Haiku 4.5 $0.00007 $0.00334

Measured 9d ago against content hash 34fb42bb6573, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

folded-memory-implementation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/folded-memory-implementation/SKILL.md · 364 lines

How it starts

The opening of the file, as written. The whole thing — 364 lines — stays where its author put it; the contents beside it link to each section on GitHub.

folded-memory-implementation

A developer guide for hierarchical memory: instead of replacing history with a single flat summary, maintain three memory layers at different levels of detail. Old content is compressed more aggressively — not discarded. Each layer is independently stored and selectively recalled.

Prerequisite: read compact-memory-implementation first. Folded memory builds on the same fork-agent and trigger concepts.


The core idea

L1 Working memory    [ turn 38..50 ] — raw turns, full detail, short window
L2 Episodic memory   [ turn 10..37 ] — compressed episodes, medium detail
L3 Semantic memory   [ turn 1..9  ] — abstract facts and decisions, sparse

When L1 fills up → fork an episode compactor → move oldest L1 turns into L2. When L2 fills up → fork a semantic extractor → distill L2 into L3.

At each agent turn, inject the right combination of layers into the system prompt.


Step 1 — Understand the setup

Same questions as compact-memory-implementation, plus:

  • How long do sessions run? If sessions are short (<50 turns), flat compact is enough.
  • What kind of information ages badly? Decisions and patterns age well (good for L3). Exact tool outputs age badly (keep only in L1 or summarize into L2).
  • Does the agent need to cite past reasoning? If yes, L2/L3 must preserve decision rationale, not just conclusions.

Step 2 — Three-layer architecture

Layer 1 — Working memory

  • Content: raw conversation turns, full fidelity
  • Window: last N turns (e.g., 20 turns or ~30k tokens)
  • Trigger to flush: when L1 exceeds its window, oldest turns move to L2
  • Injected as: full message history in messages[]

Layer 2 — Episodic memory

  • Content: compressed episode summaries — what happened, what was decided, what was tried
  • Window: up to M episodes (e.g., 10 episodes, each covering ~20 turns)
  • Trigger to flush: when episode count exceeds M, oldest episodes distill into L3
  • Injected as: structured block in system prompt

Read the full file on GitHub · 364 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 364 lines · 70 tokens per session scan A 34fb42bb6573

Subscribe to this mod's changes

folded-memory-implementation is a skill published in the GitHub repository simbajigege/book2skills (161 stars, last pushed 14d ago), licensed MIT. It adds 70 tokens to every session and 3,343 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

crewai-multi-agent

Multi-agent orchestration framework for autonomous AI collaboration. Use when building teams of specialized agents working together on complex tasks, when you need role-based agent collaboration with memory, or for production workflows requiring sequential/hierarchical execution. Built without LangChain dependencies…

davila7/claude-code-templates · 61 tokens

langchain

Framework for building LLM-powered applications with agents, chains, and RAG. Supports multiple providers (OpenAI, Anthropic, Google), 500+ integrations, ReAct agents, tool calling, memory management, and vector store retrieval. Use for building chatbots, question-answering systems, autonomous agents, or RAG…

davila7/claude-code-templates · 79 tokens

memory-search

Search conversation history and semantic memory to recall previous discussions, decisions, and context. Use when the user asks to "search memory", "what did we discuss", "remember when", "find previous conversation", "check history", or before starting work to recall prior decisions.

davila7/claude-code-templates · 57 tokens

agent-memory-mcp

A hybrid memory system that provides persistent, searchable knowledge management for AI agents (Architecture, Patterns, Decisions).

davila7/claude-code-templates · 26 tokens

agent-memory-systems

Memory is the cornerstone of intelligent agents. Without it, every interaction starts from zero. This skill covers the architecture of agent memory: short-term (context window), long-term (vector stores), and the cognitive architectures that organize them. Key insight: Memory isn't just storage - it's retrieval. A…

davila7/claude-code-templates · 100 tokens

conversation-memory

Persistent memory systems for LLM conversations including short-term, long-term, and entity-based memory Use when: conversation memory, remember, memory persistence, long-term memory, chat history.

davila7/claude-code-templates · 39 tokens