|
| 1 | +# Writing Effective Skills |
| 2 | + |
| 3 | +This guide covers how to write high-quality, discoverable, well-structured skills for skern. These guidelines are adapted from the [superpowers writing-skills](https://github.com/obra/superpowers/tree/main/skills/writing-skills) project and are built into skern's scaffolding and validation. |
| 4 | + |
| 5 | +## Skill Types |
| 6 | + |
| 7 | +| Type | Description | Example Name | |
| 8 | +|------|-------------|--------------| |
| 9 | +| **Technique** | Concrete method with actionable steps | `condition-based-waiting` | |
| 10 | +| **Pattern** | Mental model for problem-solving | `flatten-with-flags` | |
| 11 | +| **Reference** | API docs, syntax guides, lookup tables | `office-docs` | |
| 12 | + |
| 13 | +## When to Create a Skill |
| 14 | + |
| 15 | +Create a skill when: |
| 16 | + |
| 17 | +- The technique was not intuitively obvious |
| 18 | +- You would reference it across multiple projects |
| 19 | +- The pattern applies broadly beyond one codebase |
| 20 | +- Others would benefit from it |
| 21 | + |
| 22 | +Do **not** create a skill for: |
| 23 | + |
| 24 | +- One-time solutions or narratives about specific sessions |
| 25 | +- Patterns already well-documented in official tooling |
| 26 | + |
| 27 | +## Description: Claude Search Optimization (CSO) |
| 28 | + |
| 29 | +The `description` field in your SKILL.md frontmatter is the most critical field for agent discoverability. Agents match skills by description, so how you write it directly affects whether your skill gets loaded. |
| 30 | + |
| 31 | +**Start with "Use when..."** and describe the triggering conditions: |
| 32 | + |
| 33 | +```yaml |
| 34 | +# Good |
| 35 | +description: | |
| 36 | + Use when tests hang or flake due to timing-dependent assertions. |
| 37 | + Symptoms: intermittent CI failures, setTimeout in test code. |
| 38 | +
|
| 39 | +# Bad — summarizes the workflow (agents may shortcut) |
| 40 | +description: | |
| 41 | + A skill that teaches agents how to write better async tests |
| 42 | + using condition-based waiting patterns. |
| 43 | +``` |
| 44 | +
|
| 45 | +**Why this matters:** When a description summarizes the skill's workflow, an agent may follow the description as a shortcut instead of reading the full SKILL.md body. |
| 46 | +
|
| 47 | +**Keyword tips:** |
| 48 | +
|
| 49 | +- Include error messages agents might encounter |
| 50 | +- Add symptom words: "flaky", "hanging", "race condition", "timeout" |
| 51 | +- Use tool names and common synonyms |
| 52 | +
|
| 53 | +## Naming Conventions |
| 54 | +
|
| 55 | +- Use `kebab-case` with lowercase letters, numbers, and hyphens |
| 56 | +- Prefer verb-first active voice: `creating-skills` not `skill-creation` |
| 57 | +- Be specific: `condition-based-waiting` not `async-test-helpers` |
| 58 | + |
| 59 | +Names must match `^[a-z0-9]+(-[a-z0-9]+)*$` and be 1-64 characters. |
| 60 | + |
| 61 | +## Recommended Body Structure |
| 62 | + |
| 63 | +When you run `skern skill create`, the scaffold includes these sections by default: |
| 64 | + |
| 65 | +### Overview |
| 66 | + |
| 67 | +1-2 sentences describing the core principle or technique. Keep it concise. |
| 68 | + |
| 69 | +### When to Use |
| 70 | + |
| 71 | +List triggering conditions as bullet points: |
| 72 | + |
| 73 | +- Symptoms that signal this skill is needed |
| 74 | +- Specific use cases |
| 75 | +- When **not** to use this skill (counter-examples help agents avoid false matches) |
| 76 | + |
| 77 | +### Core Pattern |
| 78 | + |
| 79 | +The main technique or pattern. For techniques, use a before/after comparison: |
| 80 | + |
| 81 | +```markdown |
| 82 | +## Core Pattern |
| 83 | +
|
| 84 | +**Before (anti-pattern):** |
| 85 | +`setTimeout(check, 1000)` — arbitrary delay, still flaky |
| 86 | + |
| 87 | +**After (correct):** |
| 88 | +`waitFor(() => expect(value).toBe(true))` — condition-based, deterministic |
| 89 | +``` |
| 90 | + |
| 91 | +### Quick Reference |
| 92 | + |
| 93 | +A scannable table or bullet list for fast lookup. Agents should be able to use this section as a cheat sheet without reading the full skill. |
| 94 | + |
| 95 | +### Common Mistakes |
| 96 | + |
| 97 | +Frequent errors and their fixes. Helps agents self-correct. |
| 98 | + |
| 99 | +## Token Efficiency |
| 100 | + |
| 101 | +Skills are loaded into agent context windows, so brevity matters: |
| 102 | + |
| 103 | +| Skill Category | Target Word Count | |
| 104 | +|----------------|-------------------| |
| 105 | +| Getting-started workflows | < 150 words | |
| 106 | +| Frequently-loaded skills | < 200 words | |
| 107 | +| Other skills | < 500 words | |
| 108 | + |
| 109 | +**Tips:** |
| 110 | + |
| 111 | +- Use cross-references instead of repeating shared concepts |
| 112 | +- Compress examples to the minimum that demonstrates the point |
| 113 | +- Move heavy reference material (100+ lines) to supporting files |
| 114 | + |
| 115 | +## Code Examples |
| 116 | + |
| 117 | +- **One excellent example beats many mediocre ones** |
| 118 | +- Use the most relevant language for the skill's domain |
| 119 | +- Keep examples copy-pasteable and runnable |
| 120 | + |
| 121 | +## File Organization |
| 122 | + |
| 123 | +| Layout | When to Use | |
| 124 | +|--------|------------| |
| 125 | +| Single `SKILL.md` | All content fits in one file | |
| 126 | +| `SKILL.md` + supporting files | Heavy reference (100+ lines) or reusable tool code | |
| 127 | + |
| 128 | +Supporting files live in the same directory as `SKILL.md`. Reference them in the body. |
| 129 | + |
| 130 | +## Anti-Patterns to Avoid |
| 131 | + |
| 132 | +- **Narrative storytelling** — "In session 2025-10-03, I encountered..." Skills are reusable references, not journals. |
| 133 | +- **Multi-language examples** — Pick one language. Multiple languages dilute quality and waste tokens. |
| 134 | +- **Generic labels** — Avoid `helper1`, `step3`, `utils`. Use descriptive names. |
| 135 | +- **Workflow summaries in description** — The description field is for triggering conditions only. |
| 136 | + |
| 137 | +## Validation Hints |
| 138 | + |
| 139 | +Skern's validator provides hints when your skill deviates from these guidelines: |
| 140 | + |
| 141 | +- **Description missing trigger prefix** — Hints when the description doesn't start with "Use when", "Use for", "Use to", etc. |
| 142 | +- **Missing recommended sections** — Hints when the body is missing "When to Use", "Core Pattern", "Quick Reference", or "Common Mistakes" sections. |
| 143 | +- **Body too short** — Hints when the body has fewer than 20 words. |
| 144 | +- **Description too vague** — Hints when the description has fewer than 3 words. |
| 145 | + |
| 146 | +These are non-blocking hints (not errors), designed to guide you toward better skills. |
| 147 | + |
| 148 | +## Next Steps |
| 149 | + |
| 150 | +- [Quick Start](/guide/quick-start) — create and install your first skill |
| 151 | +- [Skill Format](/concepts/skill-format) — full SKILL.md specification |
| 152 | +- [Validation Reference](/reference/validation) — all validation rules |
0 commit comments