# Memento
<!--
ref: @protocol/memento
tags: [context, compaction, resume, handoff, memory, orchestration, auto-memento, claude-code, tmux, clear]
triggers: [context is getting long, compact the session, resume a session, hand off to a fresh session, save my place before clearing, orchestrator finds a seam to compact, auto memento]
trigger_prompt: You are about to clear or hand off a long session, were told your context is past the ceiling, received a prompt starting `go (auto memento`, or are asked to install memento. Do the section that matches.
complements: [@protocol/auto-memento, @protocol/memento_/memento-install, @protocol/memento_/memento-design, @protocol/memento_/memento-sizing]
version: 71
updated_at: 2026-11-24T15:02:26.628Z
appendixes: [@protocol/memento_/memento-design, @protocol/memento_/memento-install, @protocol/memento_/memento-sizing]
files: [auto-memento.sh, context-ceiling-hook.ts, skill.md, test-auto-memento.sh, test-context-ceiling-hook.sh]
-->

Hand-off notes for Claude Code: write one, clear, and the fresh session claims it. Operating reference for Memento and Auto Memento.

A memento is a one-file hand-off: the session writes it, clears, and the fresh session reads it back. New here? **[Auto Memento](https://protocol.supply/@protocol/auto-memento)** explains it, and **[Install](https://protocol.supply/@protocol/memento_/memento-install)** sets it up. This page is the operating reference. Auto memento needs Claude Code inside tmux; writing one by hand works anywhere.

## Do it

```bash
auto-memento $CLAUDE_PID <<'EOF'
# <one plain line the user can read: where it stands, what is next>
- **Top of mind** — what you were doing, decided, what bit you
- **Next action** — one concrete thing; or "none — await instruction"
- **Owed** — who waits on what: (me) / (them)
- **Traps** — gotchas that cost you something
- **Pointers** — file:line, short-sha, session id, doc ref. Point, don't pack.
EOF
```

**Only the main conversation clears.** A subagent shares its parent's process, so it writes with `--keep` and reports up; the script refuses a subagent's clear (exit 3).

Then end your turn with one line. The script writes the note to `.memento/` in your project and once your turn ends it sends `/clear`, then a `go (auto memento — …)` line naming the note. It may append `## Recently read (harness)`; don't write that section yourself.

- **Write it from live context, in one call.** No lookups, greps or re-reading. If you would have to go and find it, leave a pointer.
- **Clearing instead of answering a new prompt?** Paste it verbatim under `## Pending prompt`, then one line: `Type: ruling | question | go` (`go` only if the operator gave one). Context under it may say what the work *would* be, never `do X, commit, report`: the reader treats the note as the operator's voice. Why: [Design](https://protocol.supply/@protocol/memento_/memento-design?section=why-a-pending-prompt-carries-a-type).
- **Nothing unsaid to carry?** `auto-memento $CLAUDE_PID </dev/null` clears and says go, with no note.
- **Write only, no clear:** add `--keep`. A bare `--keep` with no note on stdin writes nothing and exits 2.
- **Background tasks stop before the clear.** If their exit notices wake you, answer in one line and do not re-arm. To keep them, add `--keep-bg` and name them in the note.
- **A pointer must outlive the clear.** Scratchpad and `/tmp` do not. Move what you'd have to redo somewhere durable first.
- **Exit codes.** **5** = too early (under 2× the boot floor): the note is kept, nothing cleared; if the seam is real, `auto-memento --now $CLAUDE_PID </dev/null` clears with it, so don't compose it again. **4** = the note was not written and nothing cleared. **3** = refused: the pid is gone, or you are a subagent or a sub-session (a `claude` started by another `claude`); write with `--keep` and tell your parent. Any other non-zero: stop and tell the user.
- **Outside tmux** (or without the hook) it writes the note and prints the go line: tell the user to type `/clear`, then send that line.

No script? Write the file yourself: [Design §By hand](https://protocol.supply/@protocol/memento_/memento-design?section=by-hand-the-file-format) has the filename and identity line.

## When

**Below the ceiling, memento at a seam:** task done, topic switched, or a new prompt that doesn't need this context. **Above it (the size hook tells you), at the next safe point.** Writing without clearing (`--keep`) is always fine.

Safe to clear means all four:

1. No tool call, subagent or background task is still running. A clear orphans them.
2. The user has read your last answer, or you are carrying their new prompt under `## Pending prompt`. The clear wipes their screen.
3. Nothing the note points at lives only in scratch or `/tmp`.
4. Above the ceiling, don't wait for a perfect seam: finish the call in flight, then go.

- **Instead of `/compact`**, always: a memento is your own hand-off, kept as a file you can read, edit and resume from. Why: [Design](https://protocol.supply/@protocol/memento_/memento-design?section=why-not-compact).
- **Only a driven session cycles.** No new instruction since the last cycle means don't cycle. When nothing remains, the next action is "none — await instruction".
- **A subagent hands off instead.** It cannot clear. Past the ceiling it ends with a handoff report (a teammate sends it to `"main"` and waits for `shutdown_request`), and the parent re-spawns fresh from it. Parent: stop feeding an agent past the ceiling. Why: [Design §Subagents](https://protocol.supply/@protocol/memento_/memento-design?section=subagents-the-report-is-the-memento).

## Reading it back

On boot, or on a `go (auto memento …)` prompt, run **`auto-memento --read $CLAUDE_PID`**. In one call it finds your run's newest unread note, checks its start time, prints it and renames it to `.read`. It also counts other runs' pending notes and names older unread notes of your own (claim one with `auto-memento --read $CLAUDE_PID <name>`).

- **Do its next action** only when it carries on work the user already approved; a next step the previous session chose itself is a proposal.
- **A `## Pending prompt` is the user's words:** echo its first line and answer it. Execute only with `Type: go`; a ruling or a question gets a proposal and a wait.
- **Another live run's note:** leave it. **An orphan** (dead or recycled pid; the script names it rather than reading it): *offer* it, never auto-resume. Claiming by hand: [Design §By hand](https://protocol.supply/@protocol/memento_/memento-design?section=by-hand-the-file-format).
- **`## Recently read (harness)`** lists what the previous session read last: look there before searching for a file. Fetch pointers only if the task needs the detail.

---

*Appendices: [Install](https://protocol.supply/@protocol/memento_/memento-install) · [Design](https://protocol.supply/@protocol/memento_/memento-design) · [Sizing](https://protocol.supply/@protocol/memento_/memento-sizing). Read them when installing or changing this practice, not when performing one. This page is read at peak context, which is why it is short.*

---

*Related: `@content/web/xinyadu/2026-11-29-claude-code-task-framing-study` · `@content/web/huggingface/2026-11-29-boundary-aware-policy-learning-robot-manipulation` · `@knowledge/protocols/agent-to-human-handoff-context-preload` · `@content/web/huggingface/2026-11-27-model-managed-context-nvidia-harness` · `@content/web/github/2026-11-27-resume-command-osc-7577-issue-112408`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*