memory-writer

memory-writer is an agent for Claude Code from cdeust/session-optimizer. It costs 298 tokens per session (1,210 once invoked), scanned A, original, MIT.

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 for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter; reads .claude/ paths; mentions subagents.

Part of the context-guard plugin — 1 agent shipped together

Good fit Reading a checkpoint stub and filling its sections only with facts supplied by the parent session or stub.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/cdeust/session-optimizer/memory-writer
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.

Clone the repo
git clone --depth 1 https://github.com/cdeust/session-optimizer

Made for: Claude Code.

Or install context-guard, the plugin that ships this one along with the rest of its 1 agent.

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

README.md
[![agentmods](https://agentmods.dev/badge/agents/cdeust/session-optimizer/memory-writer/github.svg)](https://agentmods.dev/agents/cdeust/session-optimizer/memory-writer)
Your own site
<a href="https://agentmods.dev/agents/cdeust/session-optimizer/memory-writer"><img src="https://agentmods.dev/badge/agents/cdeust/session-optimizer/memory-writer/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 memory-writer

Your own site · 80×15
<a href="https://agentmods.dev/agents/cdeust/session-optimizer/memory-writer"><img src="https://agentmods.dev/badge/agents/cdeust/session-optimizer/memory-writer.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
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. A grade says what 26 rules found in the file — not that it is safe.
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.00298 $0.01210
Opus 5.5 $0.00119 $0.00484
Sonnet 5.5 $0.00060 $0.00242
Haiku 4.5 $0.00030 $0.00121

Measured 1mo ago against content hash af8a140e11cf, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 1mo 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.

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. 1mo ago 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 2d ago), licensed MIT. It adds 298 tokens to every session and 1,210 once invoked, about $0.0012 per session on Opus 5.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.

Related

Other agents, from other repositories

brain-merge

Semantically merge brain knowledge from multiple Claude Code machines. Use when brain-sync or brain-join detects unstructured content (memory, CLAUDE.md) that needs intelligent merging. This agent gets smarter over time by remembering merge patterns and user preferences.

toroleapinc/claude-brain · 54 tokens

token

Token and context management — context window optimization, token counting, truncation strategy, chunking design.

tonone-ai/tonone · 21 tokens

builder

Use for standard implementation work — features, bug fixes, writing tests, refactors scoped to roughly 5 files or fewer, API endpoints, UI components. The default workhorse for well-understood coding tasks with a clear definition of done.

Adityaraj0421/gearbox · 50 tokens

architect

Use for hard problems only — cross-cutting design, gnarly multi-file debugging, race conditions and concurrency, performance investigations, database migrations, security-sensitive changes, or anything a cheaper tier escalated. Expensive; use deliberately.

Adityaraj0421/gearbox · 48 tokens

scout

Use proactively for codebase exploration, file/symbol search, reading logs, summarizing files or directories, and answering "where is X / how does Y work" questions. Read-only. Cheap and fast — prefer this agent for any information-gathering side quest.

Adityaraj0421/gearbox · 57 tokens

walkthrough-narrator

Write-only narrator for the journey-simulation skill's Phase 3 dispatch — invoke only from that skill, never for general work. Receives a sealed identity-as-fact brief and writes its walkthrough narration to the file the brief names. Tool set (Write only) and tier are pinned here so the skill's isolation holds by…

RockyHong/super-bootstrap · 73 tokens