Sub topic 8
Agent skills: capabilities loaded on demand
This chapter assumes you have used an AI coding assistant, can read Markdown and simple YAML frontmatter, know basic Git and repository layout, and understand what a context window is. Earlier chapters covered prompt files and custom agents. Here you will learn what a skill is, how it loads, and where it goes wrong. File names and frontmatter fields differ between products, so check your tool's documentation before copying anything.
What a skill is
An agent skill is a folder of instructions that an agent can load when a task needs it. The entry point is a file called SKILL.md. Frontmatter at the top gives the skill a name and a description. The body holds the instructions. The folder can also hold reference files and scripts.
The key property is that the agent, not you, decides when to use a skill. A prompt file runs when you invoke it. A custom agent runs when you select it or when another agent delegates to it. A skill sits unused until the agent judges that the current task matches its description.
This matters because of the context window. Persistent project instructions are loaded every time, so each line costs space in every conversation. Skills let you keep many specialized procedures available without paying for all of them in every session.
A minimal skill
This is the example skill used throughout the tutorial.
---
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 file has three parts.
nameidentifies the skill. Many tools expect it to match the folder name and to use lowercase letters and hyphens.descriptionsays what the skill does and when to use it. This is the text the agent reads to decide whether the skill applies.- The body is the procedure. It is read only after the skill is selected.
The last line points to reference/format.md. That file is not read until the instructions send the agent there.
How a skill loads
A skill loads in stages. This is called progressive disclosure, and the next chapters treat it in detail. The short version follows.
- At startup, the tool scans the skill folders and puts only each skill's name and description into the context. A skill costs a sentence or two at this point.
- When a task matches, the agent reads the full
SKILL.mdbody. - While following the body, the agent reads reference files or runs scripts only if a step requires it.
The result is that the description is always in context, the body is in context only when relevant, and the bundled files are in context only when a specific step needs them.
Folder layout
A skill with supporting files usually looks like this.
changelog-entry/
├── SKILL.md
├── reference/
│ └── format.md
└── scripts/
└── check_format.pySKILL.md is the only required file. Reference files hold detail that most runs do not need, such as long format rules, schemas, or examples. Scripts hold steps that are better done by code than by the model, such as validating output.
Where the folder lives depends on the product. Common choices are a directory inside the repository, which the whole team shares through Git, and a directory in your home folder, which is personal. Some tools support both and define which one wins when names collide.
Skill, prompt file, or custom agent
The three mechanisms differ mainly in who triggers them and what they change.
| Mechanism | Triggered by | What it changes | Context cost when idle |
|---|---|---|---|
| Prompt file | You, explicitly | The task you send | None |
| Custom agent | You or a delegating agent | The role, instructions, and tools for a session | Usually none until selected |
| Skill | The agent, from the description | Adds a procedure to the current session | Name and description |
A skill does not normally change which tools the agent may use or which role it plays. It adds knowledge and procedure to whatever agent is already running. Some tools let a skill list pre-approved tools in its frontmatter, but this is product-specific, so verify it before relying on it.
Writing the body
A skill body is a set of instructions the agent follows once selected. These habits keep it reliable.
- Write steps, not essays. A numbered procedure is easier to follow than a paragraph of background.
- State the output. Say what the finished result looks like, such as a file section or a list.
- Point instead of paste. If a detail is needed in only some runs, move it to a reference file and link to it from the step that needs it.
- Keep the body short. Many tools recommend keeping
SKILL.mdto a few hundred lines. Once it is selected, every line occupies the context. - Use relative paths. Refer to
reference/format.md, not an absolute path on your machine, so the skill works for teammates.
Common errors
The skill never triggers. The description is the usual cause. A description such as "Helps with changelogs" gives the agent little to match against. Say what the skill produces and list the phrases a user is likely to use: "add, draft, or update a changelog or release note". The next chapters cover description writing in more detail.
The skill triggers on the wrong tasks. A description that is too broad ("Helps with documentation") fires when another skill or a plain request would be better. Narrow it by naming the specific artifact and situation.
The agent skips the reference file. The body says "see reference/format.md" but never says when. Write the condition into the step: "If the entry touches a breaking change, read reference/format.md before writing."
The skill is not found at all. Check the folder location, the file name, and the frontmatter. Many tools require the file to be named exactly SKILL.md, with the casing shown, and require valid YAML between the --- lines. An unquoted colon inside a description is a frequent YAML error. Quote the value if it contains one.
Two skills overlap. If two descriptions both match a request, the agent may pick either or load both. Give each skill a distinct trigger, or merge them.
The skill is too big. A body that tries to cover several workflows costs context whenever any one of them is needed. Split it into separate skills.
Scripts in a skill
A script can do work that the model would do slowly or inconsistently. The changelog skill could ship scripts/check_format.py, and the body could say: "After writing the entry, run python scripts/check_format.py CHANGELOG.md and fix any reported problems."
Here is a small version of that script.
import re
import sys
ALLOWED = {"Added", "Changed", "Fixed", "Removed"}
def main(path: str) -> int:
problems = []
with open(path, encoding="utf-8") as f:
for number, line in enumerate(f, start=1):
match = re.match(r"^### (.+)$", line.rstrip())
if match and match.group(1) not in ALLOWED:
problems.append(f"line {number}: unknown section '{match.group(1)}'")
for problem in problems:
print(problem)
return 1 if problems else 0
if __name__ == "__main__":
if len(sys.argv) != 2:
print("usage: check_format.py CHANGELOG.md")
sys.exit(2)
sys.exit(main(sys.argv[1]))Run it from the skill's folder or give the agent a path that works from the repository root. The script exits with 0 when the file is valid, 1 when it finds problems, and 2 for a usage error. Clear exit codes and short messages let the agent act on the result.
A script is also code that the agent will execute. Read any script in a skill you did not write before you allow it to run. The security chapter returns to this point.
When a skill is the right choice
A skill fits when the procedure is specialized, used in some sessions but not all, and long enough that loading it every time would waste context. It also fits when the same procedure should be available across several agents or projects, and when you want the agent to find it without being told.
A skill is a poor fit for a rule that applies to every task, which belongs in persistent instructions. It is also a poor fit for a one-off request you trigger by hand, which a prompt file handles more predictably. The chapter on choosing a mechanism compares all three in detail.
Exercise
A teammate writes a skill whose description is "Helps with releases." The agent almost never loads it, even when someone asks for release notes. Give two changes that would make it load more reliably, and say where a long list of formatting rules should go.
Show answer
First, make the description say what the skill does and when to use it, for example "Drafts release notes from merged pull requests in the project's format. Use when the user asks to write, update, or review release notes or a changelog." Second, include the words users actually say, and narrow the scope so it does not overlap with other skills. The long formatting rules belong in a separate reference file, such as reference/format.md, linked from the step that needs them. That keeps SKILL.md short and loads the rules only when required.
Exercise
At startup, which parts of a skill are placed in the model's context, and which parts are read only later?
Show answer
At startup only the name and description from the frontmatter are placed in the context. The body of SKILL.md is read when the agent decides the task matches the skill. Reference files and scripts are read or run only when a step in the body calls for them.