Add /save-memories command and memory-saver background agent

- commands/save-memories.md: slash command that analyzes session context,
  finds cutoff point from last memory save, gates on value, and spawns
  memory-saver agent in background with structured summary
- agents/memory-saver.md: sonnet-based agent that stores cognitive memories
  from structured summaries via MCP tools or CLI fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-02-19 16:14:08 -06:00
parent f0f075461e
commit 43241ea612
8 changed files with 2432 additions and 2281 deletions

63
agents/memory-saver.md Normal file
View File

@ -0,0 +1,63 @@
---
name: memory-saver
description: Stores session learnings as cognitive memories. Receives a structured session summary and creates appropriate memory entries. Run in background after significant work sessions.
model: sonnet
permissions:
allow:
- "Bash(claude-memory:*)"
- "mcp__cognitive-memory__*"
---
# Memory Saver Agent
You receive a structured summary of work done in a Claude Code session. Your job is to store appropriate cognitive memories that will be useful in future sessions.
## Instructions
1. Read the session summary provided in your prompt
2. Identify distinct, storable items — each should be ONE of:
- **solution** — a problem that was solved and how
- **decision** — an architectural or design choice with rationale
- **fix** — a bug fix or correction
- **configuration** — a config that worked
- **code_pattern** — a reusable pattern discovered
- **workflow** — a process or sequence
- **procedure** — a multi-step workflow with preconditions
- **insight** — a cross-cutting observation
3. Store each item using the MCP tools (preferred) or CLI fallback
4. Always include: project tag, technology tags, category tag
5. Set importance: 0.8-1.0 critical/multi-project, 0.5-0.7 standard, 0.3-0.4 minor
## What to store
- Bug fixes with root cause and solution
- Architecture/design decisions with rationale
- New configurations that worked
- Performance improvements with before/after numbers
- Patterns that could apply to other projects
- Deployment or infrastructure changes
## What NOT to store
- Routine file edits without insight
- Session metadata (message counts, tool counts)
- Anything already stored during the session (check the summary for this)
- Speculative or incomplete work
## Storage format
Use `mcp__cognitive-memory__memory_store` with:
- `type`: one of the types listed above
- `title`: concise, descriptive, searchable (e.g., "Fix: Redis timeout via keepalive" not "Fixed a bug")
- `content`: markdown with context, problem, solution, and key details
- `tags`: array of lowercase tags — always include project name
- `importance`: float 0.0-1.0
- `episode`: true (logs to daily episode file)
## Rules
- Create separate memories for distinct topics — don't lump unrelated work into one
- Titles should be grep-friendly — someone searching for the topic should find it
- Content should be self-contained — readable without the original session context
- If the summary mentions memories were already stored during the session, don't duplicate them
- Be thorough but not excessive — 1-6 memories per session is typical

File diff suppressed because it is too large Load Diff

View File

@ -2188,8 +2188,8 @@
"lastUsedAt": 1770959377885 "lastUsedAt": 1770959377885
}, },
"sync-config": { "sync-config": {
"usageCount": 19, "usageCount": 21,
"lastUsedAt": 1771530471038 "lastUsedAt": 1771538525059
}, },
"claude-optimised": { "claude-optimised": {
"usageCount": 4, "usageCount": 4,
@ -2242,7 +2242,7 @@
"passesLastSeenRemaining": 3, "passesLastSeenRemaining": 3,
"clientDataCache": { "clientDataCache": {
"data": {}, "data": {},
"timestamp": 1771537923325 "timestamp": 1771538789822
}, },
"hasShownOpus46Notice": { "hasShownOpus46Notice": {
"57783733-6e1e-48d5-9cb7-fa588a77b795": true "57783733-6e1e-48d5-9cb7-fa588a77b795": true

View File

@ -2188,8 +2188,8 @@
"lastUsedAt": 1770959377885 "lastUsedAt": 1770959377885
}, },
"sync-config": { "sync-config": {
"usageCount": 19, "usageCount": 21,
"lastUsedAt": 1771530471038 "lastUsedAt": 1771538525059
}, },
"claude-optimised": { "claude-optimised": {
"usageCount": 4, "usageCount": 4,
@ -2234,6 +2234,10 @@
"bmad-qa": { "bmad-qa": {
"usageCount": 1, "usageCount": 1,
"lastUsedAt": 1771536951910 "lastUsedAt": 1771536951910
},
"save-memories": {
"usageCount": 1,
"lastUsedAt": 1771538857095
} }
}, },
"opusProMigrationComplete": true, "opusProMigrationComplete": true,
@ -2242,7 +2246,7 @@
"passesLastSeenRemaining": 3, "passesLastSeenRemaining": 3,
"clientDataCache": { "clientDataCache": {
"data": {}, "data": {},
"timestamp": 1771538023670 "timestamp": 1771538857202
}, },
"hasShownOpus46Notice": { "hasShownOpus46Notice": {
"57783733-6e1e-48d5-9cb7-fa588a77b795": true "57783733-6e1e-48d5-9cb7-fa588a77b795": true

View File

@ -2188,8 +2188,8 @@
"lastUsedAt": 1770959377885 "lastUsedAt": 1770959377885
}, },
"sync-config": { "sync-config": {
"usageCount": 19, "usageCount": 21,
"lastUsedAt": 1771530471038 "lastUsedAt": 1771538525059
}, },
"claude-optimised": { "claude-optimised": {
"usageCount": 4, "usageCount": 4,
@ -2234,6 +2234,10 @@
"bmad-qa": { "bmad-qa": {
"usageCount": 1, "usageCount": 1,
"lastUsedAt": 1771536951910 "lastUsedAt": 1771536951910
},
"save-memories": {
"usageCount": 1,
"lastUsedAt": 1771538857095
} }
}, },
"opusProMigrationComplete": true, "opusProMigrationComplete": true,
@ -2242,7 +2246,7 @@
"passesLastSeenRemaining": 3, "passesLastSeenRemaining": 3,
"clientDataCache": { "clientDataCache": {
"data": {}, "data": {},
"timestamp": 1771538091026 "timestamp": 1771538886396
}, },
"hasShownOpus46Notice": { "hasShownOpus46Notice": {
"57783733-6e1e-48d5-9cb7-fa588a77b795": true "57783733-6e1e-48d5-9cb7-fa588a77b795": true

View File

@ -44,7 +44,7 @@
"agent-flag": 652 "agent-flag": 652
}, },
"memoryUsageCount": 18, "memoryUsageCount": 18,
"promptQueueUseCount": 4513, "promptQueueUseCount": 4515,
"cachedStatsigGates": { "cachedStatsigGates": {
"tengu_disable_bypass_permissions_mode": false, "tengu_disable_bypass_permissions_mode": false,
"tengu_use_file_checkpoints": true, "tengu_use_file_checkpoints": true,
@ -2188,8 +2188,8 @@
"lastUsedAt": 1770959377885 "lastUsedAt": 1770959377885
}, },
"sync-config": { "sync-config": {
"usageCount": 19, "usageCount": 21,
"lastUsedAt": 1771530471038 "lastUsedAt": 1771538525059
}, },
"claude-optimised": { "claude-optimised": {
"usageCount": 4, "usageCount": 4,
@ -2234,6 +2234,10 @@
"bmad-qa": { "bmad-qa": {
"usageCount": 1, "usageCount": 1,
"lastUsedAt": 1771536951910 "lastUsedAt": 1771536951910
},
"save-memories": {
"usageCount": 1,
"lastUsedAt": 1771538857095
} }
}, },
"opusProMigrationComplete": true, "opusProMigrationComplete": true,
@ -2242,7 +2246,7 @@
"passesLastSeenRemaining": 3, "passesLastSeenRemaining": 3,
"clientDataCache": { "clientDataCache": {
"data": {}, "data": {},
"timestamp": 1771538153521 "timestamp": 1771539001655
}, },
"hasShownOpus46Notice": { "hasShownOpus46Notice": {
"57783733-6e1e-48d5-9cb7-fa588a77b795": true "57783733-6e1e-48d5-9cb7-fa588a77b795": true

File diff suppressed because it is too large Load Diff

72
commands/save-memories.md Normal file
View File

@ -0,0 +1,72 @@
---
allowed-tools: Task
description: Save session learnings to cognitive memory
---
Analyze the current conversation and create a structured session summary, then delegate memory storage to the memory-saver agent.
## Step 1: Find the cutoff point
Scan the conversation for the most recent `memory_store` MCP call or `claude-memory store` Bash call. If found, **only analyze the conversation AFTER that point** — everything before it has already been captured. If no prior memory storage is found, analyze the full conversation.
## Step 2: Analyze the session (after cutoff)
Review the conversation (from cutoff onward) and identify:
1. **Project(s)** worked on (e.g., "cognitive-memory", "paper-dynasty", "homelab")
2. **Key accomplishments** — what was built, fixed, changed, or decided
3. **Technical details** — specific files, functions, configs, or commands involved
4. **Decisions made** — any architectural choices, tradeoffs evaluated, or conventions established
5. **Problems solved** — bugs found, root causes identified, solutions implemented
6. **Performance data** — any before/after measurements
## Step 3: Evaluate whether anything is worth storing
If the work after the cutoff is trivial (routine chat, simple questions answered, minor file reads with no actionable outcome), tell the user "Nothing new worth storing since the last save" and **stop — do not spawn the agent**.
Only proceed if there are concrete storable items: solutions, decisions, fixes, configs, patterns, or insights.
## Step 4: Build the summary
Write a structured summary using this format:
```
PROJECT: <project name(s)>
ALREADY_STORED: <brief list of memories stored during session, or "none">
ITEMS:
1. [type: solution|decision|fix|configuration|code_pattern|workflow|insight]
Title: <concise, searchable title>
Tags: <comma-separated lowercase tags>
Importance: <0.3-1.0>
Content: <self-contained description with context, problem, solution, key details>
2. [type: ...]
...
```
## Step 5: Launch the memory-saver agent
Use the Task tool to spawn the `memory-saver` agent in the background with the summary as the prompt. Use sonnet model.
```
Task(
subagent_type="memory-saver",
model="sonnet",
run_in_background=true,
description="Store session memories",
prompt="<your structured summary here>"
)
```
## Step 6: Confirm
Tell the user how many memory items you identified and that the agent is saving them in the background.
## Guidelines
- Be thorough — capture everything worth remembering
- Don't duplicate memories already stored during the session
- Each item should be self-contained and useful on its own
- 1-6 items per session is typical; more is fine for large sessions
- Prefer specific, searchable titles over vague ones