From learn-from-sessions
Mine past Claude Code session logs for recurring failures, the workarounds that resolved them, and user corrections — then propose concrete rules to add to CLAUDE.md / MEMORY.md. Use when the user wants to "learn from my sessions/history/logs", reduce repeated mistakes, or auto-improve their project context files. Claude Code only; reads ~/.claude/projects logs locally.
How this skill is triggered — by the user, by Claude, or both
Slash command
/learn-from-sessions:learn-from-sessionsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Offline learning loop: parse this project's Claude Code logs into a digest, read
Offline learning loop: parse this project's Claude Code logs into a digest, read the trajectory (failures and how they were resolved), and propose rules that would prevent the waste next time. You — the running agent — are the analyzer; nothing calls an external LLM. You propose, the user approves, then you write.
The scanner scan.py ships next to this SKILL.md. Resolve its path once —
prefer the plugin root if set, else locate it (works for both plugin and
personal-skill installs):
SCAN="${CLAUDE_PLUGIN_ROOT:+$CLAUDE_PLUGIN_ROOT/skills/learn-from-sessions/scan.py}"
[ -f "$SCAN" ] || SCAN=$(find "$HOME/.claude/plugins" "$HOME/.claude/skills" -name scan.py -path '*learn-from-sessions*' 2>/dev/null | head -1)
python3 "$SCAN" # scans the current working directory's project
Reuse $SCAN for the calls below.
python3 "$SCAN" --project /path/to/repopython3 "$SCAN" --list--max-tokens 40000--fullIncremental by default: the scanner skips sessions already analyzed in a
previous run (keyed by file size, so a session that later grew is re-analyzed).
A session is "analyzed" only once you commit it in Step 5 — so re-running before
approving re-shows the same new sessions. The accumulated rules still live in
CLAUDE.md / MEMORY.md, which you read in Step 2, so skipping old sessions does
not lose past learnings. If the header says everything is already analyzed,
there's nothing new — stop and tell the user (or offer --full).
The script prints a header naming the target files (the project CLAUDE.md
and the per-project MEMORY.md), then a digest of every session. Sessions are
ordered roughly by time (last-modified); events within a session are in
strict order. Each line is a tool call as -> OK / -> ERROR(category), or a
USER:, INTERRUPTED:, or SUBAGENT: line.
Read the two target files named in the header (skip any marked absent). Treat
their existing content as the starting point so you refine and dedupe rather than
re-propose what's there. Recognize both marker styles as prior learnings:
this skill's <!-- learn-from-sessions:start --> block and, if the project was
ever processed by upstream headroom, its <!-- headroom:learn:start --> block —
preserve/merge into them rather than duplicating their rules.
The digest is ordered. For each problem, read forward to find the resolution — that's where the rule comes from:
-> OK doing the same thing differently
⇒ the rule is the working form. e.g. python3 x.py -> ERROR(command_not_found)
then uv run python x.py -> OK ⇒ "Use uv run python, not bare python3."USER: correction or an INTERRUPTED:
⇒ encode the user's stated preference.no_matches then succeeds with a different scope
⇒ record the right scope.Rules for what to propose (mirrors the original headroom rubric):
CONTEXT_FILE) — stable, project-level facts: environment
commands, correct paths, known-large files, build/test invocations.MEMORY_FILE) — evolving, session-level preferences: things
the user corrected, rejected, or asked for.Present a compact table grouped by destination. Do not write yet. For each candidate show: target file · section · the rule (1–3 lines) · evidence count · est. tokens/session saved · the digest line(s) that justify it. Then ask which to apply (all / a subset / none). If nothing clears the evidence bar, say so plainly.
For approved items, append/update inside a clearly marked, regenerable block so the edits are reversible and a re-run updates in place rather than duplicating:
<!-- learn-from-sessions:start -->
## Learned from sessions (YYYY-MM-DD)
### <section>
<rule>
<!-- learn-from-sessions:end -->
~/.claude/CLAUDE.md if the project is home).~/.claude/projects/<encoded>/memory/MEMORY.md); create the dir if needed.Then mark these sessions as analyzed so the next run skips them:
python3 "$SCAN" --commit
Only commit after the user has reviewed (whether they approved rules or chose
"none" — both mean the sessions were considered). If the user aborted without
reviewing, do not commit, so the sessions resurface next time. Pass the same
--project you scanned with if it wasn't the cwd.
~/.claude/projects/*.jsonl.learn pipeline (scan → digest → analyze → write) with
the LLM step replaced by you and the auto-writer replaced by propose-then-confirm.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub divbyzeroit/dbz-skills --plugin learn-from-sessions