Learn
Use this skill to turn a concrete lesson into durable, discoverable artifacts. Do
not stop at a chat summary. A complete learning capture writes the file-backed
records that future agents and reviewers will actually find.
Required outputs
Every confirmed learning must produce or update all of these:
- Claude auto-memory under
~/.claude/projects/<project-key>/memory/. - Optional mem0 save when the configured helper and mem0 package are available (see step 3 gates).
- Monthly roadmap log at
${ROADMAP_DIR:-$HOME/roadmap}/learnings-YYYY-MM.md(skip and report when that directory is absent). - A closed or referenced bead in
.beads/issues.jsonlwhen the current repo has beads. - LLM wiki ingest under the configured wiki (resolved following
wiki-ingest's exact 4-step order:--wiki <path>override if passed,.wiki-defaultin repo root,~/.wiki-defaultin home, or$WIKI_ROOT/wiki; report "WIKI_ROOT not configured" and skip when no wiki is configured): raw source copy, source page, index entry, log entry, and relevant concept/entity updates.
If a persistence target is unavailable, report the exact blocker and continue
with the remaining targets. Do not silently skip wiki ingest.
Workflow
1. Extract the learning
- If the user supplied a lesson, use it as the source.
- If the user invoked
/learnwithout specifics, inspect the recent
conversation and extract the most actionable failure, correction, or pattern.
- Classify it as
Critical,Mandatory,Best Practice, orAnti-Pattern. - Prefer precise references: PR URLs, commit SHAs, file paths, commands, error
strings, artifacts, and verification results.
- Search existing local records before writing:
~/.claude/projects/**/memory${ROADMAP_DIR:-$HOME/roadmap}/learnings-*.md.beads/issues.jsonl$WIKI_ROOT/wiki/index.mdand relevantconcepts/pages (when configured)
1a. Fix vs. Document decision (apply BEFORE writing the memory entry)
Workarounds-as-memory are NOT a complete resolution when a small fix is possible. Apply the fix-on-discovery rule from ~/.claude/CLAUDE.md:
| Bug class | Action |
|---|---|
| User-managed config (yaml/plist/dotfile) + fix < 10 lines + currently blocking | FIX IT NOW, then write memory entry that references the fix (commit SHA, diff, or <config-file>:line). Memory body must say "FIX: <what> at <where> on <date>" — not just "workaround: ..." |
| User's published code in a separate PR scope (separate repo, separate concern) | Document workaround; open a dedicated fix PR; memory links the fix PR |
| Third-party code (provider outage, npm package, OS-level) | Workaround only — no fix possible from here. Memory describes the trigger conditions and the recovery path |
| Agent-orchestrator core code in same repo | Fix in same PR per project CLAUDE.md; memory captures the pattern (e.g. "configKey/name/path mismatch must be validated at write-time") so the fix is durable |
| Documentation, test, tooling, scripts | Document; no fix required |
If you find yourself writing "workaround: ..." without a corresponding fix, re-read the table. The most common mistake is treating a 1-line config fix as "out of scope" — that is exactly the class this rule targets.
2. Write Claude auto-memory
Determine memory type from classification: Critical/Mandatory rules → feedback;
architecture or design decisions → project; best practices → feedback; durable
external facts or documentation-style lookups → reference.
Use the current git root to derive the project memory path:
project_key = git_root.replace("/", "-")
memory_dir = ~/.claude/projects/<project_key>/memory/
Create or update:
<type>_YYYY-MM-DD_<slug>.mdMEMORY.md
Never let a write failure (permissions, disk) block learning capture. If the
write fails, log a warning and continue to the remaining persistence targets.
The memory file must include frontmatter:
---
name: <learning title>
description: <one-line summary>
type: feedback|project|reference
bead: <bead id or none>
---
The body must include context, technical detail, solution or rule, verification,
references, and a reusable pattern.
3. Save to mem0 when available
Save a concise text record only when a configured helper and the **mem0 Python
package are present. Do NOT probe OPENAI_API_KEY / MEM0_API_KEY** — those
were the pre-Ollama-era gates; mem0 now uses local Ollama embedder + Groq LLM
(configured in $MEM0_HOOKS_DIR/mem0_config.py), neither of which
require OPENAI_API_KEY. The real availability gates are:
python3 -c "from mem0 import Memory"resolves (requiresmem0aiPyPI pkg).- The helper script exists:
$MEM0_HOOKS_DIR/mem0_save.py(machine-local hooks dir; unset means skip mem0), OR$(git rev-parse --show-toplevel)/.claude/hooks/mem0_save.py(repo-local fallback)
mem0_config.pyexists next to that helper and itsmem0_hooks_enabled()returnsTrue
(this is the helper's own gate — it inspects OPENAI_API_KEY, GROQ_API_KEY,
OLLAMA_HOST, etc., not what we hard-code here).
Verification step (mandatory before reporting "mem0 unavailable"): Run the
existing read-only health check. Do not manufacture a learning message or require a
Qdrant/markdown write merely to test availability:
"${MEM0_PYTHON:-python3}" - <<'EOF'
import os, subprocess, sys
from pathlib import Path
try:
from mem0 import Memory # noqa: F401
except ImportError as e:
raise AssertionError(f"mem0 package missing: {e}")
hooks_env = os.environ.get("MEM0_HOOKS_DIR", "")
hooks = Path(hooks_env) if hooks_env else None
helpers = [hooks / "mem0_save.py"] if hooks else []
if not any(h.is_file() for h in helpers):
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True, timeout=10,
)
if result.returncode == 0:
helpers.append(Path(result.stdout.strip()) / ".claude/hooks/mem0_save.py")
found = [h for h in helpers if h.is_file()]
assert found, f"mem0_save.py missing (MEM0_HOOKS_DIR not configured?): {helpers}"
hooks = found[0].parent
assert (hooks / "mem0_config.py").is_file(), f"mem0_config.py missing: {hooks}"
sys.path.insert(0, str(hooks))
import mem0_config
assert mem0_config.mem0_hooks_enabled(), "mem0_hooks_enabled() is False"
print("mem0 available")
EOF
This checks all three gates above (the real Memory import, either helper
path, and the helper's own mem0_hooks_enabled() — asserting mem0_config.py
exists first so a missing hooks dir yields an assertion, not a traceback),
never writes anything, and prints the failing assertion. If it fails report `mem0 unavailable: <exact assertion
message>; otherwise report mem0 available` and save only the actual learning.
Never block learning capture on a mem0 error — it is an optional target;
continue to the remaining persistence steps regardless of outcome.
Reference incident: 2026-06-24 — old SKILL.md probed OPENAI_API_KEY and
falsely reported "mem0 unavailable" for ~2 months after the Ollama/Groq switch
in PR #7178 / bead rev-1cmaj (2026-05-24).
4. Append the roadmap learning log
Append to ${ROADMAP_DIR:-$HOME/roadmap}/learnings-YYYY-MM.md (if the directory is absent, report it and skip):
## YYYY-MM-DD - <learning title>
- **Type**: feedback|project|reference
- **Classification**: Critical|Mandatory|Best Practice|Anti-Pattern
- **Summary**: <one-line summary>
- **Bead**: <bead id or none>
- **Files**: <paths created or updated>
- **References**: <PRs, commits, artifact links, commands>
5. Create or reference a bead
If .beads/issues.jsonl exists:
- Reuse a matching learning bead when one already exists.
- Otherwise create a closed task bead with labels including
learningand
documentation.
- Use the repository's normal bead id prefix when possible: follow the prefix
existing beads use (for example rev-) via br create ... --type task --priority 3
rather than inventing a bd- id.
- Record the bead id in the Claude memory frontmatter and roadmap entry.
If beads are unavailable, write none and report why.
6. Always wiki-ingest using the calling CLI
Wiki ingest is mandatory for /learn. Use the Claude memory file (preferred)
or the roadmap entry as the source document. Read the canonical wiki-ingest
skill and execute its full procedure with the calling CLI's own inference and
tools. If the runtime provides a native skill invocation, it may use that; a
Claude-specific Skill tool or a second CLI is never a prerequisite. Writes
performed as part of the complete wiki-ingest procedure are authorized; do
not substitute a partial copy that skips entity/concept extraction or validation.
Resolve the wiki destination once for both ingestion and verification, following the exact wiki-ingest order (--wiki <path> / $WIKI_OVERRIDE first, then .wiki-default in repo root, then ~/.wiki-default, then $WIKI_ROOT/wiki):
# Resolve destination once for both ingestion and verification:
if [ -n "${WIKI_OVERRIDE:-}" ]; then
WIKI="$WIKI_OVERRIDE"
elif [ -f ".wiki-default" ]; then
WIKI=$(cat .wiki-default)
elif [ -f "$HOME/.wiki-default" ]; then
WIKI=$(cat "$HOME/.wiki-default")
elif [ -n "${WIKI_ROOT:-}" ]; then
WIKI="$WIKI_ROOT/wiki"
else
echo "WIKI_ROOT not configured — skipping wiki ingest and verification"
return 0 2>/dev/null || exit 0
fi
# Gate verification assertions directly against the resolved $WIKI:
if [ -n "${WIKI:-}" ] && [ -d "$WIKI" ]; then
WIKI_ROOT=$(dirname "$WIKI")
RAW_DIR="$WIKI_ROOT/raw"
# Verify raw source copy, canonical source page, index, log, and clean git commit recording the ingested source page:
( { test -f "$RAW_DIR/<basename>" 2>/dev/null || test -f "$WIKI/raw/<basename>"; } && \
test -f "$WIKI/sources/<slug>.md" && \
grep -q -F "<slug>" "$WIKI/index.md" && \
tail -20 "$WIKI/log.md" | grep -q "<title>" && \
test -z "$(git -C "$WIKI" status --porcelain)" && \
git -C "$WIKI" log -n 1 --oneline -- "sources/<slug>.md" | grep -q . ) || \
{ echo "ERROR: wiki ingest verification failed" >&2; exit 1; }
fi
After execution, verify the required side effects using the exact resolved destination $WIKI (and sibling $RAW_DIR):
"$RAW_DIR/<basename>"(or"$WIKI/raw/<basename>") exists"$WIKI/sources/<slug>.md"exists with the canonical frontmatter
(title, type, tags, sources, last_updated) and [[wikilinks]]
"$WIKI/index.md"was updated under## Sources(verify withgrep -F "<slug>" "$WIKI/index.md")"$WIKI/log.md"was appended with## [YYYY-MM-DD] ingest | <title>(verify withtail -20 "$WIKI/log.md")- Git commit created on publish branch (verify with
test -z "$(git -C "$WIKI" status --porcelain)" && git -C "$WIKI" log -n 1 --oneline -- "sources/<slug>.md" | grep -q .) - Relevant entity/concept updates exist and the wiki's link lint passes.
If the full procedure cannot be completed, report the exact missing step and
continue independent persistence; never present a partial ingest as complete.
No exceptions for "the learning seems not wiki-bearing." The learning
itself is the source. The skill's classifier decides what is wiki-bearing.
Working-directory caveat: if the current session cwd is not
the resolved $WIKI_ROOT (e.g. an /integrate flow running in a feature worktree),
resolve the source by its absolute path and pass an explicit --wiki "$WIKI" path
(setting WIKI_OVERRIDE="$WIKI") so the destination does not depend on a current-directory override.
7. Publish to roadmap and wiki, then validate and report
Publish both available learning outputs to their respective origin/main
branches on every run. A local commit or an open PR is an intermediate result.
- Roadmap. Publish from the Git root that contains the monthly entry written
in Step 4. For the canonical roadmap, use
nextsteps roadmap publication:
start from the remote head and use a normal expected-head push of the scoped
changes. For a configured alternative, follow that repository's publication
policy. Never switch destinations or transfer direct-push authority.
- Wiki. Use the wiki-ingest PR from Step 6. Follow the resolved repository's
publication policy. If its standing wiki-content approval applies, verify
eligibility and local validation, mark the ingest PR ready when applicable,
verify checks and mergeability at the current head, then merge with --match-head-commit. Honor operator holds and branch protections.
- Read back the intended learning on both remote branches and report the
commit URLs. Reuse matching remote content when already published. If either
destination is unconfigured, unavailable, or subject to an unmet approval,
finish the other destination and report the exact incomplete step and any
pending PR. Preserve explicit write limits and the Beads publication route.
Before reporting complete:
- Verify files exist for each persistence target that was available.
- Validate
.beads/issues.jsonlparses when modified. - Check duplicate bead ids when a bead was created manually.
- Run a whitespace check for repo changes when applicable.
Final report must name the created/updated paths and any skipped persistence
target with its reason.