Sub topic 12
Bundling scripts and reference files
This chapter assumes you have read the chapters on skill structure, skill descriptions, and progressive disclosure. You should know that a skill is a folder with a SKILL.md file, that the frontmatter is loaded first, and that the body is loaded only when the skill is selected. Here we cover the third level: the extra files that sit next to SKILL.md and are read or run only when the instructions call for them.
File names, folder names, and the way a tool runs scripts differ between products. Treat the layout below as a common convention and check your tool's documentation.
Why bundle files at all
A skill body competes for space in the context window with everything else. If you put a 600-line style guide, a full API schema, and a validation routine into SKILL.md, the model pays for all of it every time the skill triggers, even when the task needs only one section.
Bundled files solve this in two ways:
- Reference files hold text the model reads only when needed. An unread file costs nothing, apart from the one line in
SKILL.mdthat mentions it. - Scripts hold logic the model can run instead of rewriting. Only the script's output enters the context, not its source.
The folder from the topic's earlier example looks like this:
changelog-entry/
├── SKILL.md
├── reference/
│ └── format.md
└── scripts/
└── check_format.pyThe three levels, applied to files
The key point is that the model decides, step by step, whether to open a file. The decision depends on what your SKILL.md says. If the body never mentions a file, the model has no reason to look for it.
Reference files
A reference file is plain Markdown, CSV, JSON, or text that supports the task. Good candidates are:
- Detailed format rules that apply to only some tasks.
- Lookup tables, such as error codes or naming conventions.
- Worked examples of good output.
- Domain background that most runs do not need.
Point to them precisely
A vague pointer produces vague behavior. Compare these two lines:
- Weak: "See the reference folder for more information."
- Strong: "If the change touches the public API, read
reference/api-rules.mdbefore writing the entry."
The strong version states the file and the condition. The model can then skip the read when the condition is false.
Keep references one level deep
Link to reference files directly from SKILL.md. If format.md says "see details/advanced.md", and that file links to a third, the model may read only part of each file or miss the chain. A flat layout is easier for the model to follow and easier for you to review.
Keep each file focused
Split by topic, not by size alone. One file per concern (api-rules.md, naming.md, examples.md) lets the model load one without the others. For a file longer than about 100 lines, add a short table of contents at the top. This helps the model find the right section when it reads only part of the file.
Scripts
A script is a program the skill asks the model to run. Use a script when a step is:
- Deterministic. The answer should be the same every time, such as checking a file format or computing a checksum.
- Error-prone when written ad hoc. Date arithmetic and parsing are examples.
- Repetitive. The model would otherwise regenerate the same code on every run.
Scripts also keep output short. A validator can read a 2,000-line file and print one line, so the model never needs the whole file in context.
A complete example
This script checks that a changelog follows the format. It uses only the Python standard library, takes the path as an argument, and prints clear messages with a meaningful exit code.
#!/usr/bin/env python3
"""Check that a changelog uses only the allowed section headings."""
import re
import sys
from pathlib import Path
ALLOWED = {"Added", "Changed", "Fixed", "Removed"}
HEADING = re.compile(r"^###\s+(.+?)\s*$")
def main(argv):
if len(argv) != 2:
print("usage: check_format.py CHANGELOG.md", file=sys.stderr)
return 2
path = Path(argv[1])
if not path.is_file():
print(f"error: {path} does not exist", file=sys.stderr)
return 2
problems = []
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
match = HEADING.match(line)
if match and match.group(1) not in ALLOWED:
problems.append(f"line {number}: unknown section '{match.group(1)}'")
if problems:
print("\n".join(problems))
return 1
print("ok: all section headings are valid")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))The matching instruction in SKILL.md names the exact command:
After drafting the entry, run `python scripts/check_format.py CHANGELOG.md`.
If it prints problems, fix them and run it again. Do not report the entry as
done until the script prints "ok".Make scripts easy for a model to use
- State the intent: run or read. Say "run
scripts/check_format.py" when you want execution. Say "readscripts/check_format.py" only if the model needs to understand or adapt the code. - Print actionable errors. "line 14: unknown section 'Misc'" tells the model what to fix. A bare stack trace does not.
- Use exit codes. Zero for success, non-zero for failure. Distinguish bad input (2) from a found problem (1) if that helps.
- Avoid prompts. A script that waits for keyboard input will hang an agent.
- Document dependencies. If a script needs a package, name it in
SKILL.mdor avoid the dependency. A script that fails on import wastes a turn. - Use relative paths from the skill folder and say where the command should run. Some tools run from the repository root, not the skill folder, so confirm how yours resolves paths.
Reference file or script?
| Need | Use | Why |
|---|---|---|
| Rules the model must interpret | Reference file | The model reads and applies judgment |
| A check with a yes or no answer | Script | Same result every run, small output |
| Examples of good output | Reference file | The model imitates the pattern |
| Converting or parsing data | Script | Avoids regenerating fragile code |
| Rarely needed background | Reference file | Costs nothing until read |
Common errors
- Orphaned files. A file is in the folder but
SKILL.mdnever mentions it. The model will not find it reliably. Every bundled file needs a pointer. - Duplicated rules. The same rule appears in
SKILL.mdand in a reference file, and the two drift apart. Keep each rule in one place. - Bloated body. Reference material pasted into
SKILL.mddefeats progressive disclosure. Move it out once the body grows past a few dozen lines of detail. - Scripts that need setup. A script that requires an unavailable interpreter or network access fails in other environments. Test in a clean checkout.
- Silent failure. A script that prints nothing on error leaves the model guessing. Always print a result.
Test your bundle
Before you rely on a skill, check these points:
- Run each script by hand, with good input, bad input, and a missing file.
- Ask the agent for a task that needs the reference file. Confirm from its output or tool log that it read the file.
- Ask for a task that does not need the reference file. Confirm that it did not read it.
- Rename a file and see whether the skill breaks loudly. A broken pointer should be easy to notice.
Exercise
A skill's SKILL.md contains the line "See the reference folder for details." The folder holds three files, but the model rarely reads them and often gets edge cases wrong. Name two changes that would help.
Show answer
First, name each file and the condition for reading it, for example "If the change removes a public function, read reference/breaking-changes.md." This tells the model when a read is worth it. Second, make sure every file is linked directly from SKILL.md, so none is orphaned and none sits behind a chain of other files. Splitting a large file by topic also helps.
Exercise
You want a skill to confirm that a generated JSON file matches a schema. Should the schema check be a reference file or a script, and what should the script print on failure?
Show answer
Use a script, because a schema check is deterministic and gives a yes or no answer. On failure it should print specific, actionable messages, such as the path of each invalid field and what was expected, and exit with a non-zero code. On success it should print a short confirmation so the model knows the check ran.