/memstack:diaryfrom memstack
Logs session summaries including project, date, changes, files, commits, decisions, and problems. Activates on explicit user requests like 'save diary' or 'wrapping up'.
Ships in memstack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Document what was accomplished in each CC session for future recall.
When this skill activates, output:
📓 Diary: Logging session...
Then execute the protocol below.
| Context | Status | Priority |
|---|---|---|
| User says "save diary", "log session", "write diary" | ACTIVE: write diary | P1 |
| User explicitly says they're done ("that's it", "wrapping up") | ACTIVE, suggest diary if work was done | P2 |
| Multi-agent session (Builder/Reviewer role) | DORMANT: Manager handles diary | none |
| Mid-session, user is actively coding | DORMANT, don't interrupt flow | none |
| Casual conversation, no code changes made | DORMANT: nothing to log | none |
| User asks to recall past sessions ("what did we do") | DORMANT, Echo handles recall, not Diary | none |
| User says "save project" or "handoff" | DORMANT, Project skill handles this | none |
| Session just started, no work yet | DORMANT: nothing to log | none |
When the user asks to save a diary, keep these in mind:
| Temptation | Why it matters |
|---|---|
| "Nothing important happened" | Even small decisions are worth recording: what was decided, and who decided it. |
| "Commits capture everything" | Commits don't capture decisions, blockers, or next steps. |
| "Skip the handoff section" | Handoffs are the most valuable part for session continuity. |
Never pass a JSON payload as a quoted command-line argument. Write it to a file and pipe it in with the dash sentinel, as every command below shows. On Windows, cmd.exe treats single quotes as ordinary characters, so a redirection operator anywhere in a quoted payload is executed rather than passed.
All JSON field values must be plain strings. Never pass arrays or objects. If multiple items (files, commits, decisions), join them as a comma-separated string.
Summarize the session:
Check git log for commits:
git log --oneline -10
Format the diary entry:
# Session Diary: {project}, {date}
## Accomplished
- Item 1...
## Files Changed
- path/to/file.ts: description
## Commits
- abc1234 Message
## Decisions
- User decision: what was decided. Stated reason: as quoted from the session, the task prompt or a commit message, or "none stated"
- Session choice: what was chosen
## Next Steps
- What to do next
## Session Handoff
**In Progress:** [what was actively being worked on when session ended]
**Uncommitted Changes:** [list any unstaged/uncommitted work, or "None"]
**Pick Up Here:** [exact instruction for next session, specific enough to start cold]
**Session Context:** [anything important that isn't captured elsewhere, as observed: temporary decisions and who made them, the debugging state as last seen (what was run and what it showed), gotchas found]
Save to SQLite database (primary storage):
Write the payload to a file, then pipe it in with - as the argument. A payload on stdin is never seen by the shell's parser, so a redirection operator inside your prose cannot be read as one.
cat session.json | python "${CLAUDE_PLUGIN_ROOT}/db/memstack-db.py" add-session -
The store is ~/.memstack/memstack.db, one file per user, never a file beside the script. Every command prints the path it used on stderr as memstack-db: store <path>, so a session can confirm where it wrote instead of assuming.
The SQLite row is the primary store. The markdown in memory/sessions/ is
a backup export. The row holds the full raw_markdown, so a markdown file
that is lost, truncated or overwritten can be restored from it: find the row
in the sessions table by project and date, and write raw_markdown back to
the file. This matters because memory/ is gitignored, so version control is
not a fallback and the database is the only one there is.
session.json contains:
{"project":"<name>","date":"<YYYY-MM-DD>","accomplished":"<bullets>","files_changed":"<bullets>","commits":"<bullets>","decisions":"<bullets>","problems":"<bullets>","next_steps":"<bullets>","duration":"<estimate>","raw_markdown":"<full text>"}
Save insights for cross-project search:
Same form: write the payload to a file, pipe it in, - as the argument. Insight text is prose, so it must never travel on the command line.
cat insight.json | python "${CLAUDE_PLUGIN_ROOT}/db/memstack-db.py" add-insight -
insight.json contains:
{"project":"<name>","type":"<type>","content":"<insight>","context":"Session <date>","tags":"<project>"}
Choose <type> deliberately from this vocabulary, do not default to one:
gotcha: something that bit us and the fix. Non-obvious behavior a future session would trip on again.lesson: a general rule learned the hard way. Broader than one bug.pattern: a reusable approach or convention that worked.warning: a known hazard to avoid. Not yet a bug, but will be.failed_approach: something tried that did not work, and the failure as observed (the error, the test result). Prevents retrying it.architecture: a structural fact about how a system is built.decision: a decision as made and who made it, with the reason only as already recorded (the user's words, the task prompt or a commit message). Historical record.The first five are procedural: an agent can act on them at retrieval time. architecture and decision are record. When a row could be either, prefer the procedural type.
Unknown types pass through unchanged but come back as type_unknown in the JSON response, that is the signal to pick a type from the list above.
CRITICAL: The field name is "content", NOT "insight". Using "insight" will fail with a missing required field error.
Update project context with last session date:
Same form, even though this payload is only metadata. One rule with no exceptions is easier to follow than a rule you have to judge.
cat context.json | python "${CLAUDE_PLUGIN_ROOT}/db/memstack-db.py" set-context -
context.json contains:
{"project":"<name>","last_session_date":"<YYYY-MM-DD>"}
Also save a markdown copy to memory/sessions/, under a name nothing
already occupies. Append a ## FACTS block (see below) as the last
section of this markdown.
Compute the filename immediately before writing it, not at the start of
the task. List memory/sessions/ and take the first free name:
| Attempt | Name |
|---|---|
| 1st diary of the day for this project | {date}-{project}.md |
| 2nd | {date}-{project}-2.md |
| 3rd | {date}-{project}-3.md |
There is no -1: the plain name is the first, so the numbers you see in the
directory match how many diaries exist for that day.
The check has to happen at the moment of the write because a session can run for hours, and another session, or an agent run, can file a diary for the same project in between. A name that was free when the task started is not evidence that it is free now.
Never write over an existing file. If the name you computed exists when you go to write it, stop and report it rather than writing. Do not overwrite, do not append, do not pick a name by guessing. A diary is another session's only human-readable record, and the Write tool reporting "updated" instead of "created" is the only warning you will get, which is far too quiet to rely on.
A suffixed filename changes step 8. diary_ingest derives the project
namespace from the filename, so 2026-09-06-myproject-2.md derives
myproject-2, which ingests cleanly, exits 0, and is invisible to every
recall for the real project. Whenever the name carries a -N suffix, pass
--project explicitly.
Ingest the FACTS block into the Memory Engine, right after the markdown is written:
python -m memstack_skill_loader.diary_ingest "memory/sessions/{the name you just wrote}" --project {project}
This parses the ## FACTS block and stores each fact with source_type='diary'.
Read the summary it prints. This step is not fire-and-forget. It reports memory-ingest: N ingested, M duplicate, K skipped into project 'NAME': PATH on stdout, followed by one indented reason per skipped line naming the line number and what was wrong with it. NAME is the namespace the facts were actually written to, derived from the diary's filename, and it is the part to check: a diary filed under an unintended project ingests cleanly and exits 0 while staying invisible to every recall for the real one. When no fact has ever been stored under that namespace the line reads into NEW project 'NAME', which is the cheapest signal that derivation landed somewhere unintended. Pass --project NAME to skip filename derivation entirely when the derived name would be wrong. The exit code classifies the outcome:
| Exit | Meaning |
|---|---|
| 0 | Nothing was lost: facts ingested, an all-duplicates re-run, or no FACTS block at all (which prints nothing at all). |
| 1 | Total loss. The block held lines and not one of them ingested. |
| 2 | Store failure. The run aborted at the first bad row; the Memory Engine is broken, not the diary. |
If K is not 0, fix those lines in the markdown and run the command again. A skipped line is a fact this session was supposed to hand to the next one and did not, and the most common cause is a | inside a claim. Re-running is safe: facts dedupe on source + subject + claim, so anything already stored comes back as a duplicate rather than being written twice.
A non-zero exit never means the diary failed to save. The markdown and the SQLite row are already written by this point, and ingestion cannot undo them.
The ## FACTS block is how a session hands durable, atomic knowledge to future sessions. It is machine-parsed, so the format is fixed. One fact per line:
subject | claim | method [| entities]
memstack.dashboard.start, adminstack.portal.auth). Group related facts under a shared prefix.|.verified (you saw it work / read the code / ran it), reported (stated but unconfirmed), inferred (deduced), assumed (a guess: scored lowest).## FACTS
memstack.dashboard.start | start_dashboard() in dashboard.py, port 3333, proxy opt-in | verified
memstack.memory.recall-scoring | recall score = confidence * exp(-age/half_life), computed at query time, never stored | verified
adminstack.portal.auth | portal uses Supabase magic-link auth, not passwords | reported | supabase, auth
memstack.memory.corrections | a superseded fact cannot be corrected; corrections extend from the live tip | verified | correction
verified over reported. If you actually confirmed it, say so, verified facts are trusted and decay slowest. Don't inflate: an unconfirmed claim is reported.| Gotcha | Why it matters |
|---|---|
| The markdown filename is computed, never assumed | On 2026-09-06 a session wrote memory/sessions/2026-09-06-memstack-skill-loader.md when a file of that name already existed, destroying 10238 characters of an earlier session's diary including its FACTS block. Nothing warned: the Write tool said "updated" rather than "created" and the session did not notice for several steps. Recovery was possible only because the SQLite sessions table still held that row's raw_markdown. memory/ is gitignored, so there was no version-control fallback and no second chance if the row had been missing. |
| A free name goes stale | The scan belongs immediately before the write. Sessions run long, and agent runs file diaries for the same project while one is open. |
A -N suffix silently re-namespaces the FACTS | diary_ingest derives the project from the filename, so a suffixed diary ingests into {project}-N and exits 0 while being invisible to recall for the real project. Pass --project whenever the name is suffixed. |
| The database is the only backup | The markdown is an export. If it is gone, restore it from raw_markdown in the sessions table rather than rewriting it from memory. |
The 500-line limit on markdown files is no longer a concern since SQLite is the source of truth.
Markdown files in memory/sessions/ are now just human-readable exports.
Old markdown files are preserved but not the primary storage.
User: "save diary"
📓 Diary: Logging session...
Saved: memory/sessions/2026-02-18-adminstack.md
Project: AdminStack | Duration: ~2 hours
Accomplished: Built CC Monitor page, API routes, setup guide
Commits: 4 (45b4c42, d1c7e11, f6c8e18, f0e793f)
Files changed: 8
This session is now searchable via Echo.
The diary system includes an automatic PreCompact hook that fires before Claude Code compresses the context window. This closes the gap where session context could be lost during long conversations.
.claude/diary/{date}-compaction.md, one file per day, appends on multiple compactionsCOMPACTION_INTERRUPTED so the next session knows context was cut| Data | Source |
|---|---|
| Uncommitted changes | git status --short |
| Recent commits | git log --oneline -5 |
| Recent shell commands | Shell history (last 5) |
| Recently modified files | Files modified since last git operation |
| Branch and project | Git branch + directory name |
| Manual Diary | PreCompact Diary | |
|---|---|---|
| Trigger | User says "save diary" | Automatic before compaction |
| Content | Full narrative with decisions, handoff | Snapshot of working state |
| Storage | SQLite + memory/sessions/ | .claude/diary/ only |
| Purpose | Session documentation | Context recovery after compaction |
When resuming after compaction, check .claude/diary/ for entries with today's date. The COMPACTION_INTERRUPTED flag signals that the previous context was truncated and these files contain the lost state.
Hook is registered in .claude/settings.json under PreCompact. Script lives at .claude/hooks/pre-compact.sh. Always exits 0: must never block compaction.
The Diary skill is part of a broader hook system that automates session lifecycle, security, and observability. All hooks follow the same defensive pattern: set -uo pipefail, SCRIPT_DIR resolution, all external commands wrapped with fallbacks, guaranteed exit 0.
| Event | Script | Matcher | Timeout | Purpose |
|---|---|---|---|---|
| PreToolUse | pre-tool-notify.sh | Write|Edit|MultiEdit|Bash | 10s | TTS voice alert before approval prompts |
| PreToolUse | pre-push.sh | Bash (git push) | 60s | Build verification + secrets scan before push |
| PostToolUse | post-commit.sh | Bash (git commit) | 10s | Debug artifact + secrets scan after commit |
| PostToolUse | post-tool-monitor.sh | Write|Edit|MultiEdit|Bash | 10s | Observation capture, logs tool calls to .claude/observations/ |
| SessionStart | session-start.sh | (all) | 10s | CLAUDE.md indexing, monitoring ping |
| SessionStart | session-context-load.sh | (all) | 15s | Context injection, last 3 diary + observation summaries → .claude/session-context.md |
| Stop | session-end.sh | (all) | 10s | Monitoring API session-complete ping |
| PreCompact | pre-compact.sh | (all) | 15s | Auto-save diary snapshot before context compaction |
settings.json, giving it its own timeout budget.claude/observations/YYYY-MM-DD.md: daily files, append-only.claude/session-context.md on each new session.claude/observations/ and .claude/session-context.md are in .gitignore (ephemeral runtime output).claude/hooks/ and use ${CLAUDE_PROJECT_DIR} for portable path resolution.claude/rules/diary.md), always-on session logging awareness without skill file read. (Origin: MemStack v3.0-beta, Feb 2026)## FACTS block, atomic, machine-parsed cross-session knowledge (subject | claim | method | entities) ingested into the Memory Engine via diary_ingest after each save. Fail-open, dedupe-safe, corrections-first. (Origin: MemStack Memory Engine step 4, Jul 2026)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
session-logging, work-tracking, session-summary, productivity
npx claudepluginhub cwinvestments/memstack --plugin memstack87 skills in this plugin
/memstack-seo-ai-search-visibilityUse this skill when the user says 'AI search', 'AI visibility', 'ChatGPT ranking', 'Perplexity optimization', 'GEO', 'generative engine optimization', or needs to optimize content for AI-powered search engines and LLM citations. Do NOT use for traditional SEO audits or Google Ads./memstack-security-api-auditUse this skill when the user says 'audit API', 'check API security', 'API routes security', 'endpoint audit', 'check my routes', or needs to verify API route protection. Reviews API endpoints for authentication, authorization, and input validation gaps. Do NOT use for frontend security headers or dependency scanning./memstack-development-api-designerUse this skill when the user says 'design API', 'API endpoints', 'REST API', 'API designer', 'route structure', 'API architecture', or is designing RESTful API routes, request/response schemas, and endpoint organization. Do NOT use for API security audits or database design./memstack-automation-api-integrationUse this skill when the user says 'API integration', 'connect APIs', 'sync data', 'data mapping', 'rate limiting', or needs system-to-system connectors with authentication, rate limit handling, and error recovery. Generates API integration code with authentication (OAuth, API key, JWT), request/response mapping, rate limit handling, error recovery with circuit breakers, and sync monitoring. Do NOT use for visual n8n workflows or webhook receiving./memstack-content-blog-postUse this skill when the user says 'write blog post', 'blog post about', 'write article', 'create blog', 'content for blog', 'write post', or is creating long-form written content for a blog or publication. Do NOT use for landing page copy, email sequences, or social media posts./memstack-development-changelog-generatorUse when the user says 'generate changelog', 'update changelog', 'what changed', 'release notes', 'write changelog', or needs a formatted CHANGELOG.md from git commit history. Do NOT use for diary entries, git log viewing, or commit message writing.Other plugins' skills for the same job