Sub topic 9
Anatomy of a skill: folder, SKILL.md, and frontmatter
This chapter assumes you have used an AI coding assistant, can read Markdown and simple YAML, and know basic Git and repository layout. It also assumes you know what a context window is. A skill is a folder of instructions that an agent loads only when a task calls for it. Here you will learn what goes in that folder, what the SKILL.md file must contain, and which mistakes cause a skill to fail silently.
File names and frontmatter fields differ between products. The examples follow a widely used convention, so check your tool's documentation for the exact schema before you rely on a field.
The skill folder
A skill is a directory. The directory name is the skill's identity on disk, and the one required file inside it is SKILL.md. Everything else is optional.
changelog-entry/
├── SKILL.md
├── reference/
│ └── format.md
└── scripts/
└── check_format.pyEach part has a distinct job:
| Part | Required | Purpose |
|---|---|---|
| `SKILL.md` | Yes | Entry point: metadata plus the core instructions |
| `reference/` | No | Longer documents the agent reads only when needed |
| `scripts/` | No | Code the agent can run instead of generating it each time |
The folder names reference and scripts are conventions, not rules. The agent finds those files because SKILL.md names them, not because of where they sit. Keep paths in SKILL.md relative to the skill folder, so the skill still works when someone copies it to another repository or user directory.
Tools usually scan fixed locations for skills. Typical ones are a project directory inside the repository, so the whole team shares the skill, and a user directory in your home folder, so it follows you across projects. When the same skill name appears in both places, tools differ on which one wins. Look this up for your tool before you depend on it.
The two parts of SKILL.md
SKILL.md has two parts: YAML frontmatter between --- lines, then a Markdown body.
---
name: changelog-entry
description: Writes a changelog entry in the project's format. Use when the user asks to add, draft, or update a changelog or release note.
---
# Changelog entry
1. Read the latest entries in CHANGELOG.md to match the format.
2. Group changes under Added, Changed, Fixed, or Removed.
3. Write one line per change, in the past tense, with the pull request number if known.
For the full format rules, see reference/format.md.The two parts are read at different times. The agent reads the frontmatter early, often for every skill at the start of a session, and uses it to decide whether the skill is relevant. It reads the body only after it decides to use the skill. That difference drives most of the design advice that follows.
The next chapters cover this loading behavior in more detail. For now, remember that the frontmatter costs context in every session, while the body costs context only when the skill is used.
Frontmatter fields
Two fields are the common core.
nameis a short identifier. A common convention is lowercase letters, digits, and hyphens, and it should match the folder name. Some tools reject names that break the pattern or do not match the folder.descriptionsays what the skill does and when to use it. The agent matches the user's request against this text. A skill with a weak description will rarely be selected, however good its body is.
Many tools accept further optional fields, such as a list of allowed tools, a version, or a flag that stops the agent from invoking the skill on its own. These vary a lot. An unknown field is usually ignored without a warning, so a misspelled or unsupported field does nothing and gives you no error.
YAML details that break skills
Frontmatter is YAML, and YAML has traps that show up often in descriptions.
- A description containing a colon followed by a space, such as
Use when: the user asks, can be parsed as a nested mapping and fail. Wrap the value in quotes, or use a block scalar. - A description starting with a special character such as
*,&,[, or ``` can fail to parse for similar reasons. - Tabs for indentation are invalid. Use spaces.
- The opening
---must be the first line of the file. A blank line or a byte order mark before it can make the tool treat the file as having no frontmatter.
A safe way to write a long description is a folded block scalar:
---
name: changelog-entry
description: >-
Writes a changelog entry in the project's format. Use when the user asks
to add, draft, or update a changelog: release notes, version notes,
or a "what changed" summary.
---The >- joins the lines into one string and removes the trailing newline, and the colon inside is now safe.
Writing the body
The body is ordinary Markdown instructions, and the agent follows it when the skill is active. A few habits make bodies work better.
- Start with the steps, in order, as a numbered list. Agents follow a sequence more reliably than a loose description.
- State the output you expect, such as the format, the location, or what to report back.
- Say what the skill must not do when a mistake would be costly, for example "Do not edit files outside
docs/." - Keep the body short. Move long tables, style guides, and examples into reference files and link to them. Once the body loads, every line of it occupies the context window alongside the user's task. A common rule of thumb is to keep the body to a few hundred lines at most, but the right limit depends on your tool and model.
- Tell the agent when to open a reference file, not just that it exists. "If the change touches the public API, read
reference/format.md" is better than "see reference/format.md".
Scripts deserve a specific note. If a step is mechanical, such as validating a format, a script gives the same result every time and costs no tokens to generate. The body should say how to run it and what its output means. For example:
After drafting the entry, run `python scripts/check_format.py CHANGELOG.md`.
If it prints any line starting with `ERROR`, fix the entry and run it again.Remember that running a script gives code execution inside your environment. A later chapter on security covers how to review bundled scripts.
A minimal validator
A skill that fails to parse often just does not appear, with no message. You can catch the common problems before committing. This script checks the frontmatter of each skill folder under a directory. It requires the PyYAML package (pip install pyyaml).
import re
import sys
from pathlib import Path
import yaml
NAME_PATTERN = re.compile(r"^[a-z0-9]+(-[a-z0-9]+)*$")
def check_skill(folder: Path) -> list[str]:
problems = []
skill_file = folder / "SKILL.md"
if not skill_file.is_file():
return [f"{folder}: missing SKILL.md"]
text = skill_file.read_text(encoding="utf-8")
match = re.match(r"^---\n(.*?)\n---\n", text, re.DOTALL)
if not match:
return [f"{skill_file}: no frontmatter at the top of the file"]
try:
meta = yaml.safe_load(match.group(1))
except yaml.YAMLError as error:
return [f"{skill_file}: invalid YAML ({error})"]
if not isinstance(meta, dict):
return [f"{skill_file}: frontmatter is not a mapping"]
name = meta.get("name")
description = meta.get("description")
if not isinstance(name, str) or not NAME_PATTERN.match(name):
problems.append(f"{skill_file}: name must be lowercase words joined by hyphens")
elif name != folder.name:
problems.append(f"{skill_file}: name '{name}' does not match folder '{folder.name}'")
if not isinstance(description, str) or not description.strip():
problems.append(f"{skill_file}: description is missing or empty")
return problems
def main(root: str) -> int:
problems = []
for folder in sorted(p for p in Path(root).iterdir() if p.is_dir()):
problems.extend(check_skill(folder))
for problem in problems:
print(problem)
return 1 if problems else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "."))Run it with the directory that holds your skill folders as the argument, for example python validate_skills.py .claude/skills. The path is only an example. Use wherever your tool stores skills. The script does not know your tool's schema, so treat it as a starting point and adjust the rules.
Common mistakes
- Name and folder mismatch. The skill is skipped or renamed by the tool. Keep them identical.
- Vague description. "Helps with docs" gives the agent nothing to match. The next chapter covers how to write descriptions that get selected.
- Everything in SKILL.md. A body of thousands of lines wastes context and buries the key steps. Split it.
- Deep reference chains. If
format.mdpoints to another file, which points to a third, the agent may read only part of the chain. Link every file directly fromSKILL.md. - Absolute paths. A path such as
/home/ana/skills/...breaks for every other person. Use paths relative to the skill folder. - Several jobs in one skill. A skill that writes changelogs, reviews code, and bumps versions has a muddy description. Make three skills.
Exercise
A teammate adds a skill folder named release-notes containing a file skill.md (lowercase). The frontmatter has name: release_notes and description: Use when: the user wants release notes. The agent never uses the skill. List the problems you can identify and the fix for each.
Show answer
There are four problems. (1) The file must be named SKILL.md with exact case, so rename it. (2) The name release_notes uses an underscore and does not match the folder release-notes, so change it to release-notes. (3) The description contains a colon followed by a space, which YAML can read as a nested mapping, so quote the value or use a >- block scalar. (4) The description says when to use the skill but not what it does, so rewrite it, for example "Drafts release notes from merged pull requests. Use when the user asks for release notes or a changelog." Because tools often skip a broken skill silently, check each of these before you change the body.
Exercise
Why should a long style guide go in reference/format.md instead of the SKILL.md body, and what must the body contain so the agent actually uses that file?
Show answer
The body loads into the context window whenever the skill is active, so a long guide costs context even on tasks that do not need it. A reference file is read only when needed. The body must link to the file with a relative path and say when to read it, for example "If the change touches the public API, read reference/format.md."