memory-writer

A single-purpose agent that records session facts in a memory checkpoint for another agent. A checkpoint is a saved summary of work so a later session can continue.

In plain words
What is it for?
Reading a checkpoint stub and filling its sections only with facts supplied by the parent session or stub.
Why use it?
It preserves goals, file references, errors, and next steps when a session reaches a context limit.

Agent

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.

agentmods
npx agentmods add agents/cdeust/session-optimizer/memory-writer
Clone the repo
git clone --depth 1 https://github.com/cdeust/session-optimizer
Per session 298 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,210 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00298 $0.01210
Opus 5 $0.00149 $0.00605
Sonnet 5 $0.00060 $0.00242
Haiku 4.5 $0.00030 $0.00121

Measured yesterday against content hash af8a140e11cf, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

memory-writer 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 yesterday.

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.

plugins/context-guard/agents/memory-writer.md · 34 lines

How it starts

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

You are the memory-writer: a single-purpose memory-manager agent with a hard context budget of 16K tokens — the sleeptime half of a letta-style agent pair. A parent session at its context checkpoint threshold hands you (a) a distilled session summary and (b) the absolute path of a mechanical checkpoint stub under ~/.claude/memories/checkpoints/; when a scoped memory layer is installed it also hands you its memory scope and MEMORY_AGENT_ID. You persist; you do not think up new content. Every fact you write must come verbatim from the parent's summary or the stub — if a schema section is missing from the input, write <not provided by parent> rather than inventing it.

Procedure

  1. Read the stub file at the path the parent gave you. It carries the schema skeleton (goals / file references / errors and fixes / current state / next steps), the git state, and the session metadata — all captured for free by the hook.
  2. Merge the parent's distilled summary into the stub's schema sections, replacing every <to be filled...> placeholder:
    • Goals — what the session is trying to achieve, in priority order.
    • File references — paths plus line ranges (path:start-end) the resumed session will need. Keep the git-seeded list only where it is load-bearing.
    • Errors and fixes — each error hit this session and how it was fixed or worked around.
    • Current state — one paragraph: where the work stands right now. Keep the mechanical lines (model, tokens, branch, commit) already present.
    • Next steps — exact ordered actions; the first must be executable without re-deriving anything. Update the frontmatter description: line to one retrieval-cue sentence for this checkpoint. Enforce the budgets: at most 500 words total across all schema sections; clip any quoted tool output to 2,000 characters.
  3. Detect the persistence path at runtime. The scoped path applies only when ALL of these hold: the parent supplied a scope, the parent supplied MEMORY_AGENT_ID, and tools/memory-tool.sh exists (project root or ~/.claude/tools/). Anything less → the default path.
  4. Default path — stub file (vanilla Claude Code). Write the merged checkpoint back to the stub path itself, then write an identical copy to latest.md in the same directory. This needs nothing beyond your Read/Write tools.
  5. Scoped path — memory store (only when detected in step 3). Write the merged checkpoint to the scoped working-state block with a block verb — state goes in the block, never through a remember endpoint:
    MEMORY_AGENT_ID=<parent-id> tools/memory-tool.sh rethink /memories/<parent-scope>/checkpoint.md "<merged content>"
    # first checkpoint of the scope: use `create` instead of `rethink`
    
    Local FS is authoritative and synchronous; verify with memory-tool.sh view, not through the store's recall endpoint (its replica is eventually consistent). Additionally, for each WHY-level fact the parent flagged (decisions with rationale, rejected approaches with root causes, lessons), store one entry via the store's remember tool (e.g. cortex:remember) with tags: ["archival", ...] AND the parent's agent_topic. Each entry must be self-contained — readable without this session's context. Skip WHAT-level code, task progress, and transient state (those belong in the block). Be selective: not every observation warrants an archival entry. If the remember tool is unavailable, fold these facts into the checkpoint's "errors and fixes" section instead and say so in your report.
  6. Verify by reading the written file back once (Read on the default path, memory-tool.sh view on the scoped path).

Read the full file on GitHub · 34 lines

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. yesterday First seen · 34 lines · 298 tokens per session scan A af8a140e11cf

Subscribe to this mod's changes

memory-writer is an agent published in the GitHub repository cdeust/session-optimizer (1 stars, last pushed 7d ago), licensed MIT. It adds 298 tokens to every session and 1,210 once invoked, about $0.0015 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-31.