Learn

From jleechanorg/claude-commands · View interactive version

Learn is an AI agent skill from the GitHub repository jleechanorg/claude-commands. Capture durable learnings from failures, corrections, repeated mistakes, successful recovery patterns, or direct /learn requests. Use whenever the user invokes /learn, asks to save/remember/capture a lesson, or when a workflow failure should become reusable process knowledge. Always persist to Claud

How to use this skill

Skill file

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:

  1. Claude auto-memory under ~/.claude/projects/<project-key>/memory/.
  2. Optional mem0 save when the configured helper and mem0 package are available (see step 3 gates).
  3. Monthly roadmap log at ${ROADMAP_DIR:-$HOME/roadmap}/learnings-YYYY-MM.md (skip and report when that directory is absent).
  4. A closed or referenced bead in .beads/issues.jsonl when the current repo has beads.
  5. LLM wiki ingest under the configured wiki (resolved following wiki-ingest's exact 4-step order: --wiki <path> override if passed, .wiki-default in repo root, ~/.wiki-default in 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

conversation and extract the most actionable failure, correction, or pattern.

strings, artifacts, and verification results.

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:

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:

  1. python3 -c "from mem0 import Memory" resolves (requires mem0ai PyPI pkg).
  2. The helper script exists:
  1. mem0_config.py exists next to that helper and its mem0_hooks_enabled() returns True

(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:

documentation.

existing beads use (for example rev-) via br create ... --type task --priority 3

rather than inventing a bd- id.

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):

(title, type, tags, sources, last_updated) and [[wikilinks]]

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.

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.

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.

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:

Final report must name the created/updated paths and any skipped persistence

target with its reason.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.