Extract patterns from the current session into a skill (update existing or create new). ## Usage ``` /capture-skill ``` ## Instructions ### Phase 1: Analyze + Duplicate Check Run these in parallel: **Analyze context** — Review recent conversation for: - Anti-patterns discovered and solutions - Common mistakes and fixes - Trigger scenarios and keywords - Discovery context (dates, error messages) Extract: pattern name (kebab-case for directory, gerund form for heading), trigger keywords, core principles, code examples. **Duplicate check** — Search existing skills: 1. Extract 3-5 core keywords from the proposed skill 2. Search: `grep -ril "keyword1\|keyword2\|keyword3" .claude/skills/*/SKILL.md ~/.claude/skills/*/SKILL.md` 3. If 3+ keyword matches with any single skill → flag it: - Show matching skill name and description excerpt - Ask: "Similar skill found: [name]. **Merge**, **proceed**, or **abort**?" - Wait for user decision 4. If 0-2 matches → proceed silently **Decision**: match found → update existing skill. No match → create new skill. ### Phase 2: Generate Content #### For UPDATING existing skill: 1. Read existing skill 2. Add new anti-patterns, examples, discovery context (with date) 3. Preserve existing content — only add, don't remove #### For CREATING new skill: Required frontmatter: ```yaml --- name: [kebab-case-directory-name] description: "What it does. Auto-activates when [scenarios]. Trigger keywords: [list]." allowed-tools: Read, Grep, Glob, Bash --- ``` Required sections: `# Heading` (human-readable), Purpose line, and content sections appropriate to the pattern (principles, required/forbidden patterns, examples, decision trees — include what fits, omit what doesn't). Frontmatter rules: - `name` must match directory name exactly: `^[a-z0-9]+(-[a-z0-9]+)*
(1-64 chars) - `description`: 20-1024 chars, include trigger keywords - Human-readable title in `# Heading`, not in `name` ### Phase 3: Validate + Present **Validation** (inline, before showing to user): - [ ] Frontmatter: `name` matches directory, `description` present, `allowed-tools` specified - [ ] **Line budget: 300 lines max.** If over: show count, suggest trimming (remove verbose examples, cross-reference existing skills, split into skill + reference doc). Do NOT save over-budget without explicit user override ("save anyway"). - [ ] Discovery context includes dates - [ ] If skills repo has `check.sh`, run it against the new skill **Present**: Show proposed skill (or diff for updates). Ask if the pattern is captured correctly. After approval, write files. ## Output Creates or updates `.claude/skills/[skill-name]/SKILL.md`. Reports validation results (frontmatter compliance, line budget). ## Constraints - **Line budget**: 300 lines max (user can override explicitly) - **Skill directory**: `.claude/skills/[skill-name]/SKILL.md` - **OpenCode compatibility**: `name` must exactly match directory name in kebab-case. OpenCode validates this and silently skips non-matching skills. - **Allowed tools**: Most skills use `Read, Grep, Glob, Bash` — restrict as appropriate ## Optimization History - **March 13, 2026**: Applied five-step optimizer. Deleted 70-line full template (over-specifies sections Claude generates naturally), Phase 4 documentation integration (never done in practice), content structure and format validation checklists (Claude formats markdown correctly by default), example usage section (hypothetical walkthrough), notes section (duplicated constraints). Merged validation into Phase 3. Merged duplicate check into Phase 1 (parallel). 251 → 79 lines (69% reduction).