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.
git clone --depth 1 https://github.com/cdeust/session-optimizerWrote 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.
[](https://agentmods.dev/agents/cdeust/session-optimizer/memory-writer)<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.
<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>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00298 | $0.01232 |
| Opus 5.5 | $0.00119 | $0.00493 |
| Sonnet 5.5 | $0.00060 | $0.00246 |
| Haiku 4.5 | $0.00030 | $0.00123 |
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 22d 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.
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
- 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.
- 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.
- 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, andtools/memory-tool.shexists (project root or~/.claude/tools/). Anything less → the default path. - Default path — stub file (vanilla Claude Code). Write the merged checkpoint back to the stub path itself. Do not write
latest.md: the Stop hook copies this file there on its own once no<to be filledplaceholder is left, so a stub never replaces a complete checkpoint. This needs nothing beyond your Read/Write tools. - 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:
Local FS is authoritative and synchronous; verify withMEMORY_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`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) withtags: ["archival", ...]AND the parent'sagent_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. - Verify by reading the written file back once (Read on the default path,
memory-tool.sh viewon the scoped path).
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.
- 22d ago Changed 65e874142255
- 3mo ago First seen · 34 lines · 298 tokens per session scan A af8a140e11cf
memory-writer is an agent published in the GitHub repository cdeust/session-optimizer (2 stars, last pushed today), licensed MIT. It adds 298 tokens to every session and 1,232 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.
memory-writer compared with agents from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| memory-writercdeust/session-optimizer | Agent | 2 | today | MIT | A | 298 | Claude Code |
| brain-mergetoroleapinc/claude-brain | Agent | 97 | 5mo ago | MIT | A | 54 | Claude Code |
| dream-organizergtapps/hermitd | Agent | 88 | today | MIT | A | 19 | Claude Code |
| tokentonone-ai/tonone | Agent | 85 | yesterday | MIT | A | 21 | Claude Code |
| walkthrough-narratorRockyHong/super-bootstrap | Agent | 3 | 2d ago | MIT | A | 69 | Claude Code |
| builderAdityaraj0421/gearbox | Agent | 17 | 1mo ago | MIT | A | 50 | Claude Code |
| architectAdityaraj0421/gearbox | Agent | 17 | 1mo ago | MIT | A | 48 | Claude Code |