. If it does not match,\nask for a valid Hex package identifier instead of replacing characters or\ninventing a name. Use the trimmed original identifier, not the normalized\ndirectory name, to look up `mix.lock`.\n\nWithout `--library`, use the [General Correction Route](#general-correction-route).\n\n### Step 3: Check Existing Knowledge\n\nCheck if already documented:\n\n- Grep project CLAUDE.md and `~/.claude/CLAUDE.md` for the pattern keyword\n- Check auto-memory files for similar lessons\n- For library lessons, inspect both\n `~/.claude/skills/hex-\u003cpackage>/SKILL.md` and\n `.claude/skills/hex-\u003cpackage>/SKILL.md`\n- Read `${CLAUDE_SKILL_DIR}/references/common-mistakes.md` (read-only plugin\n reference)\n\nDo not duplicate the same lesson across CLAUDE.md, memory, and a package skill.\nIf the same rule exists, merge wording or report it as already captured.\n\n## Library Route\n\nPlugin files are read-only: files under `~/.claude/plugins/` are cached\nand get overwritten on updates. Package skills are user-owned files, never\nplugin cache files.\n\n### Resolve Scope and Precedence\n\n| `--scope` | Canonical destination |\n|-----------|-----------------------|\n| `personal` | `~/.claude/skills/hex-\u003cpackage>/SKILL.md` |\n| `project` | `.claude/skills/hex-\u003cpackage>/SKILL.md` |\n\nPersonal skills override same-named project skills. If a personal\n`hex-\u003cpackage>` skill exists, never unknowingly create or update a shadowed\nproject skill: explain the conflict and ask whether to update personal scope or\nkeep distinct project-only knowledge. If project scope already exists before a\npersonal write, warn that the new skill will shadow it and offer to merge or\nmove it. Maintain one canonical skill per package unless the user explicitly\nneeds distinct scope-specific rules; never create one skill per lesson.\n\n### Read the Locked Version\n\nInspect `mix.lock` for the package. Record the exact locked version when found.\nIf it is absent, say the lesson is not tied to a locally locked version and do\nnot invent one. Qualify version-sensitive rules. When two verified rules\nconflict across versions, preserve both with explicit version ranges instead of\nreplacing either.\n\n### Create or Safely Update the Skill\n\nFor a new package skill, create:\n\n```markdown\n---\nname: hex-\u003cpackage>\ndescription: \u003cPackage/module/API/task trigger terms for this knowledge>\nuser-invocable: false\n---\n\n# \u003cPackage> Knowledge\n\n## Verified Rules\n\n- **\u003cRule>** (verified with \u003cpackage> \u003cversion>): \u003cactionable guidance>\n```\n\nMake the description precise: include the Hex package, Elixir module names,\nimportant APIs/file formats, and tasks that should trigger this knowledge.\nActivation is model-selected from this description; package presence in\n`mix.lock` does not guarantee activation.\n\nBefore updating an existing skill, read all of it. Preserve unrelated and\nhand-authored sections. Merge semantically identical rules. If safe merging is\nunclear, show the conflict and ask instead of overwriting content.\n\nDo not add `paths:` to a personal package skill by default: it is a file-path\nactivation gate, not a dependency predicate. Add `paths:` only to project scope\nwhen explicitly appropriate and meaningful package-specific paths exist.\n\n## General Correction Route\n\nChoose the narrowest non-library destination:\n\n| Scope | Write to | Example |\n|-------|----------|---------|\n| This project | Project CLAUDE.md | \"Never use raw SQL in this app\" |\n| This project across sessions | Project-keyed auto-memory | \"jsonb uses string keys\" |\n| All your projects | `~/.claude/CLAUDE.md` personal instructions | \"Prefer explicit error tuples\" |\n| Detailed completed fix | `.claude/solutions/` via `/phx:compound` | Debugging narrative |\n\nFor project or personal instructions, preserve existing content and append\n`**RULE NAME** — Do NOT [bad]. Instead [good]` under the relevant category. Use\npersonal instructions only for rules that should load in every project. For\nauto-memory, append to the project-keyed\n`~/.claude/projects/{project-hash}/memory/MEMORY.md`:\n\n```markdown\n### Lesson: [Title]\n- **Pattern**: Do NOT [bad] — instead [good]\n- **Why**: [root cause explanation]\n```\n\nIf the lesson is universal to the plugin rather than one project or package,\nsuggest a plugin contribution; never write it into cached plugin files.\n\n## Output\n\nAfter capturing, confirm:\n\n```text\nLesson captured in [location]\n\nPattern: Do NOT [bad pattern] — instead [good pattern]\nCategory: [Ecto/LiveView/OTP/Testing/etc]\nVersion: [locked package version, not found, or not applicable]\n```\n\nFor package skills, also state that description-based activation is\nmodel-selected, not guaranteed by `mix.lock`.\n\n## Iron Laws\n\n1. **NEVER write generated knowledge to plugin cache** — use only the user-owned destinations above\n2. **DO NOT duplicate existing lessons** — always check CLAUDE.md and memory before writing\n3. **NEVER overwrite hand-authored content** — read both package skill scopes and merge safely\n4. **ONLY persist verified knowledge** — completed fixes or explicit user-taught rules, never hypotheses\n5. **DISCLOSE scope precedence** — a global package skill shadows its project counterpart\n\n## References (READ-ONLY — do NOT edit)\n\n- `${CLAUDE_SKILL_DIR}/references/common-mistakes.md` — Common Elixir mistakes\n reference. Consult when checking for duplicates.\n","licenseDocuments":[]}}
界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
文档与办公 · SKILL.md

learn-from-fix

learn-from-fix

【文档与办公】Capture Elixir/Ecto/LiveView lessons and Hex API rules. Use after corrections or when asked to document learning, record a lesson, prevent a fixed mistake, or remember package guidance with --library.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: learn-from-fix description: Capture Elixir/Ecto/LiveView lessons and Hex API rules. Use after corrections or when asked to document learning, record a lesson, prevent a fixed mistake, or remember package guidance with --library. effort: low argument-hint: "[--library --scope personal|project] "

Learn From Fix

After fixing a bug or receiving a correction, capture the lesson to prevent future mistakes.

Usage

/phx:learn-from-fix Fixed N+1 query in user listing - was missing preload
/phx:learn-from-fix String vs atom key mismatch in params handling
/phx:learn-from-fix LiveView assign_async needs render_async in tests
/phx:learn-from-fix --library ical --scope personal ICal.to_ics output needs CRLF line endings
/phx:learn-from-fix --library ical --scope project Use method: "PUBLISH" for calendar feeds

Workflow

Step 1: Verify the Lesson

Persist only one of:

  • A completed fix verified by tests, reproduction, or user confirmation
  • An explicit rule the user taught or asked to save

Stop without writing if neither condition is met. Do not save a hypothesis, unverified workaround, investigation narrative, or unsolved error. Use /phx:compound for a detailed completed investigation. Capture the root cause as a concise actionable rule, not the symptom.

Step 2: Select the Route

When both --library <package> and --scope personal|project are present, use the Library Route. Require both flags; do not guess scope. For the skill directory only, trim surrounding whitespace and lowercase the package name. Preserve underscores when forming directory names (phoenix_live_view becomes hex-phoenix_live_view). Validate the normalized name against ^[a-z][a-z0-9_]+$. If it does not match, ask for a valid Hex package identifier instead of replacing characters or inventing a name. Use the trimmed original identifier, not the normalized directory name, to look up mix.lock.

Without --library, use the General Correction Route.

Step 3: Check Existing Knowledge

Check if already documented:

  • Grep project CLAUDE.md and ~/.claude/CLAUDE.md for the pattern keyword
  • Check auto-memory files for similar lessons
  • For library lessons, inspect both ~/.claude/skills/hex-<package>/SKILL.md and .claude/skills/hex-<package>/SKILL.md
  • Read ${CLAUDE_SKILL_DIR}/references/common-mistakes.md (read-only plugin reference)

Do not duplicate the same lesson across CLAUDE.md, memory, and a package skill. If the same rule exists, merge wording or report it as already captured.

Library Route

Plugin files are read-only: files under ~/.claude/plugins/ are cached and get overwritten on updates. Package skills are user-owned files, never plugin cache files.

Resolve Scope and Precedence

--scopeCanonical destination
personal~/.claude/skills/hex-<package>/SKILL.md
project.claude/skills/hex-<package>/SKILL.md

Personal skills override same-named project skills. If a personal hex-<package> skill exists, never unknowingly create or update a shadowed project skill: explain the conflict and ask whether to update personal scope or keep distinct project-only knowledge. If project scope already exists before a personal write, warn that the new skill will shadow it and offer to merge or move it. Maintain one canonical skill per package unless the user explicitly needs distinct scope-specific rules; never create one skill per lesson.

Read the Locked Version

Inspect mix.lock for the package. Record the exact locked version when found. If it is absent, say the lesson is not tied to a locally locked version and do not invent one. Qualify version-sensitive rules. When two verified rules conflict across versions, preserve both with explicit version ranges instead of replacing either.

Create or Safely Update the Skill

For a new package skill, create:

---
name: hex-<package>
description: <Package/module/API/task trigger terms for this knowledge>
user-invocable: false
---

# <Package> Knowledge

## Verified Rules

- **<Rule>** (verified with <package> <version>): <actionable guidance>

Make the description precise: include the Hex package, Elixir module names, important APIs/file formats, and tasks that should trigger this knowledge. Activation is model-selected from this description; package presence in mix.lock does not guarantee activation.

Before updating an existing skill, read all of it. Preserve unrelated and hand-authored sections. Merge semantically identical rules. If safe merging is unclear, show the conflict and ask instead of overwriting content.

Do not add paths: to a personal package skill by default: it is a file-path activation gate, not a dependency predicate. Add paths: only to project scope when explicitly appropriate and meaningful package-specific paths exist.

General Correction Route

Choose the narrowest non-library destination:

ScopeWrite toExample
This projectProject CLAUDE.md"Never use raw SQL in this app"
This project across sessionsProject-keyed auto-memory"jsonb uses string keys"
All your projects~/.claude/CLAUDE.md personal instructions"Prefer explicit error tuples"
Detailed completed fix.claude/solutions/ via /phx:compoundDebugging narrative

For project or personal instructions, preserve existing content and append **RULE NAME** — Do NOT [bad]. Instead [good] under the relevant category. Use personal instructions only for rules that should load in every project. For auto-memory, append to the project-keyed ~/.claude/projects/{project-hash}/memory/MEMORY.md:

### Lesson: [Title]
- **Pattern**: Do NOT [bad] — instead [good]
- **Why**: [root cause explanation]

If the lesson is universal to the plugin rather than one project or package, suggest a plugin contribution; never write it into cached plugin files.

Output

After capturing, confirm:

Lesson captured in [location]

Pattern: Do NOT [bad pattern] — instead [good pattern]
Category: [Ecto/LiveView/OTP/Testing/etc]
Version: [locked package version, not found, or not applicable]

For package skills, also state that description-based activation is model-selected, not guaranteed by mix.lock.

Iron Laws

  1. NEVER write generated knowledge to plugin cache — use only the user-owned destinations above
  2. DO NOT duplicate existing lessons — always check CLAUDE.md and memory before writing
  3. NEVER overwrite hand-authored content — read both package skill scopes and merge safely
  4. ONLY persist verified knowledge — completed fixes or explicit user-taught rules, never hypotheses
  5. DISCLOSE scope precedence — a global package skill shadows its project counterpart

References (READ-ONLY — do NOT edit)

  • ${CLAUDE_SKILL_DIR}/references/common-mistakes.md — Common Elixir mistakes reference. Consult when checking for duplicates.
我的收藏