Capture the lesson — structured + markdown.
a. Structured (preferred when scripts/learnings.sh is present). The distinctive fields for this skill are --wrong-turns (the failed attempts) and --time-cost (minutes the loop cost) — populate them; they are what the trigger produces. Use --source golden-path. Since this is self-driven trial-and-error with no human or model recommendation, the decision origin is system-inferred.
LS="scripts/learnings.sh"; [ -f "$LS" ] || LS="${CLAUDE_PLUGIN_ROOT:-.}/scripts/learnings.sh"
bash "$LS" add \
--workflow "${MTK_WF_UUID:-manual}" \
--scope "personal|team" \
--source golden-path \
--decision-origin system-inferred \
--severity "info|warn|block" \
--phase "spec|plan|implement|review|any" \
--files "comma,separated,paths" \
--title "Short title — the golden path, not the struggle" \
--body "What kept failing (the signature) and what finally worked" \
--rule "The reusable rule: when you hit <signature>, do <golden path>" \
--applies-when "When this rule should activate (file/error signature)" \
--wrong-turns "failed attempt A — why it failed,failed attempt B — why it failed" \
--time-cost 15 \
--evolution-actions "routing|claude_md|reference|hook|none"
bash "$LS" regen-markdown
--wrong-turns — the dead ends you tried, each with a one-line why, so the next session doesn't repeat them. This is the core of a golden-path lesson.
--time-cost — rough minutes lost to the loop. Makes the value of the golden path concrete.
--evolution-actions — a FORCED decision: if you repeatedly hit this signature, the fix may belong in CLAUDE.md, a reference, or a hook, not just a lesson. none is allowed but state why in the body.
--source golden-path is a new but consistent free-text source value (learnings.sh add accepts --source as pass-through; only --decision-origin is enum-validated). It lets retrieval and metrics distinguish self-driven captures from engineer corrections.
Schema: .claude/references/learnings-schema.md.
Optional executable contract (v7.25). If the golden path has a checkable outcome — specific files/fields that must exist, or a pre-final check that must pass — attach --confidence, --output-contract, --prefinal-checklist, and --source-evidence-refs so the lesson is verifiable next time, not just readable. Optional: most in-session golden-path captures stay prose and add the contract only at promote-lesson time. See the schema's Executable lesson contract.
b. Markdown fallback (older repos without learnings.sh). Append to the chosen file (create .claude/lessons/ if missing). Resolve path to main worktree if in a worktree.
## [Date] — [Short title — the golden path]
**Failure signature:** [What kept failing, 2+ times, and the shared root cause]
**Golden path:** [The materially different approach that worked, and why]
**Rule:** [When you hit <signature>, do <golden path>]
**Applies to:** [When this rule should activate in future work]
**Wrong turns:** [Each failed attempt + why it failed — so they aren't repeated]
**Time cost:** [Rough minutes lost to the loop]
**Evolution:** [Which toolkit asset you changed because of this: routing / CLAUDE.md / a reference / a hook / none-and-why]
The structured form enables 5-layer retrieval (proximity / recurrence / severity / validity / phase) at the start of the next spec or fix. The markdown form remains the team-canonical, committed view.