From memex-claude
Extract learnings from past session transcripts and create appropriately-typed skills. Processes unreviewed sessions to find user preferences, recurring patterns, and troublesome workflows.
How this skill is triggered — by the user, by Claude, or both
Slash command
/memex-claude:deep-sleepThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Analyze past session transcripts to extract user preferences, recurring patterns, and troublesome workflows, then create appropriately-typed skills for future semantic injection.
Analyze past session transcripts to extract user preferences, recurring patterns, and troublesome workflows, then create appropriately-typed skills for future semantic injection.
Perform the following steps directly — no external scripts or API keys needed.
Find session transcripts in the project directory. The path is encoded from the current working directory:
~/.claude/projects/<encoded-cwd>/
Where <encoded-cwd> is the cwd with / replaced by - and . replaced by -.
Look for .jsonl files in that directory. Each line is a JSON object with role and content fields.
Check the watermark file to find unprocessed sessions:
~/.claude/cache/deep-sleep-watermark
If the watermark exists, only process .jsonl files modified after that timestamp. If no watermark exists, process files from the last 7 days. The user may also specify --since YYYY-MM-DD.
From each transcript, extract lines where role is "user". The content may be a string or an array of {type, text} objects. Collect messages longer than 10 characters.
Review the collected user messages and identify reusable patterns. Look for:
Skip one-off requests. Only extract clear, reusable patterns.
Scan each processed transcript for memex injection markers — lines containing "The following was automatically loaded based on semantic relevance".
For each injection found:
Also scan for missed matches — cases where the user provided information that an existing skill already contains, but that skill was not injected. For missed matches, use score: 0 and queryIndex: -1.
Record each observation to telemetry:
# Read current telemetry
cat ~/.claude/cache/memex-telemetry.json
For each observation, add it to the entry's observations array in the telemetry file. The observation format:
{
"sessionId": "<session-id>",
"prompt": "<the user prompt that triggered the injection>",
"score": <similarity score or 0 for missed>,
"queryIndex": <index of the matching query or -1 for missed>,
"outcome": "used|ignored|corrected|missed",
"diagnosis": "<one-sentence explanation>",
"timestamp": "<ISO timestamp>"
}
Cap observations at 100 per entry (keep newest).
For each candidate learning, use memex's own semantic search to check for overlapping entries. Pipe the learning text as a UserPromptSubmit query:
echo '{"hook_event_name":"UserPromptSubmit","user_prompt":"<candidate learning text>","session_id":"deep-sleep-dedup","cwd":"<cwd>"}' | $PLUGIN_ROOT/bin/memex
If the output contains additionalContext with a match at relevance >= 80%, the learning is already covered. Read the matched entry to confirm — if the existing entry says the same thing, skip the candidate. If the existing entry is related but incomplete, update it instead of creating a duplicate.
This uses the same embedding-based similarity that memex uses at runtime, so dedup quality matches injection quality.
For each novel learning, determine the right type based on how critical and universal it is:
| Pattern observed | Type | Destination |
|---|---|---|
| Corrected 3+ times across sessions | rule | <cwd>/.claude/rules/<name>.md with frontmatter |
| Preference or fact stated once | memory | <cwd>/.claude/skills/<name>/SKILL.md |
| Multi-step procedure | skill | <cwd>/.claude/skills/<name>/SKILL.md |
| Ordered multi-step process | workflow | <cwd>/.claude/skills/<name>/SKILL.md |
| Tool-specific guidance | tool-guidance | <cwd>/.claude/skills/<name>/SKILL.md |
| Stop condition pattern | stop-rule | <cwd>/.claude/skills/<name>/SKILL.md |
For entries classified as rules (corrections made 3+ times), create a rule file with full frontmatter:
---
name: <kebab-case-name>
description: "<one sentence: what this rule prevents>"
queries:
- "<query 1>"
- "<query 2>"
- "<query 3>"
one-liner: "<short reminder version>"
---
<the full rule explanation>
For all other types, create a SKILL.md:
---
name: <kebab-case-name>
description: "<one sentence: when is this useful>"
type: <memory|skill|workflow|tool-guidance|stop-rule>
queries:
- "<natural query 1>"
- "<natural query 2>"
- "<natural query 3>"
- "<natural query 4>"
- "<natural query 5>"
---
<the actual instruction or knowledge, 1-5 lines>
Write the current ISO timestamp to the watermark file:
mkdir -p ~/.claude/cache
date -u +%Y-%m-%dT%H:%M:%SZ > ~/.claude/cache/deep-sleep-watermark
Summarize what was created:
The user may specify:
--dry-run: Show extracted learnings without creating files--since <date>: Process transcripts from this date (ISO format)--global-scope: Write skills to ~/.claude/skills/ instead of <cwd>/.claude/skills/$ARGUMENTS
npx claudepluginhub jim80net/memex-claude --plugin memex-claudeExtracts reusable patterns from Claude Code sessions and saves them as learned skills for future use. Useful after long sessions with complex problem-solving.
Mines coding-agent session history, transcripts, and memories to discover recurring workflows and draft new Agent Skills from real usage evidence.
Distils repeating patterns from session logs and lessons into draft skill files. Run after 10+ sessions to extract durable knowledge.