Sub topic 12
Bundling scripts and reference files
This chapter assumes you know the layout of a skill folder and its SKILL.md frontmatter. It also assumes you know that skills load in stages: metadata first, then instructions, then resources. Here you will see how supporting files fit into that model.
Why bundle files at all
A skill's SKILL.md is read in full whenever the skill is selected. Long format rules, large examples, and lookup tables make that read expensive. Bundled files solve this. You keep SKILL.md short and move detail into separate files. The agent opens a file only when a step tells it to.
There are two kinds of bundled file:
- Reference files are text the agent reads, such as format rules, templates, or glossaries.
- Scripts are programs the agent runs. Only their output enters the context, not their source.
A typical layout
changelog-entry/
├── SKILL.md
├── reference/
│ └── format.md
└── scripts/
└── check_format.pyPointing to files from SKILL.md
The agent only knows a file exists if SKILL.md says so. Name the file and say when to use it:
## Steps
1. Read the latest entries in CHANGELOG.md to match the format.
2. Draft the entry. If a change does not fit Added, Changed, Fixed, or Removed,
read reference/format.md before deciding.
3. Run `python scripts/check_format.py CHANGELOG.md` and fix any reported problems.Use paths relative to the skill folder. Keep references one level deep: SKILL.md points to format.md, and format.md should not send the agent on to more files.
Writing a useful script
A script is worth bundling when a check must be exact or repeatable. A model can misjudge a format rule, but a script applies it the same way every time. This one checks that each changelog line sits under a known heading:
import re
import sys
ALLOWED = {"Added", "Changed", "Fixed", "Removed"}
def main(path):
problems = []
section = None
with open(path, encoding="utf-8") as f:
for number, line in enumerate(f, start=1):
heading = re.match(r"^###\s+(\w+)\s*$", line)
if heading:
section = heading.group(1)
if section not in ALLOWED:
problems.append(f"line {number}: unknown section '{section}'")
elif line.startswith("- ") and section is None:
problems.append(f"line {number}: entry is not under a section")
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]))Good scripts print short, clear messages and use a non-zero exit code on failure. The agent reads that output and can fix the problem.
Common errors
- Unreferenced files. A file that
SKILL.mdnever mentions is not used. - Vague pointers. "See the docs folder" gives no trigger. Name the file and the condition.
- Duplicated rules. If a rule lives in both
SKILL.mdand a reference file, the two copies drift apart. Keep it in one place. - Hidden dependencies. A script that needs a package the machine lacks will fail. State requirements in
SKILL.md, or use only the standard library. - Unsafe scripts. A script runs with your permissions. Review bundled scripts as you would any code, a point the security chapter returns to.
Exercise
Why does the changelog skill tell the agent to run check_format.py instead of describing the format rules in SKILL.md and asking the model to check them?
Show answer
A script applies the rules exactly and the same way each time, and only its short output enters the context. Describing the rules in SKILL.md would use context on every selection and leave the check to the model's judgment.
Exercise
A skill has reference/api-errors.md, but the agent never reads it. What is the most likely cause, and how do you fix it?
Show answer
SKILL.md probably never mentions the file. Add a step that names reference/api-errors.md and says when to read it, for example "If the request fails, read reference/api-errors.md."