If every working session with Claude starts by pasting the same instructions (the project conventions, the release procedure, the format of a review), that is what a skill is for: a folder with a SKILL.md file that Claude loads on its own when the request justifies it, or that you call yourself with /name. It is not a plugin that adds functions to the model and it is not a protocol: it is instructions, plus optional files and scripts, that stay out of the context until they are needed. Here we build the reasoning on a real skill, one that reviews the Flyway migrations of a test project.
What a skill is, and what it is not
The Claude Code documentation defines it like this: you create a SKILL.md file with instructions and Claude adds it to its repertoire; it uses it when it is relevant, or you invoke it directly with /skill-name. The typical case is the colleague who explains the same procedure to you for the third time: you write it down once, in one place, and from then on it is part of the work. That is why a skill should be compared with three nearby things that are often confused with it.
| Tool | What it is | When it acts | Guarantee |
|---|---|---|---|
| Skill | Instructions in Markdown, with supporting files and scripts | When Claude judges it relevant or when you invoke it | None: Claude may not follow it |
| Hook | A command the client runs on an event (for example before editing a file) | Every time the event occurs | Deterministic: it does not depend on the model |
| MCP server | A process that exposes tools and data through a protocol | When Claude calls one of its tools | Depends on the server, not on the skill |
| CLAUDE.md | Instructions always present in the project context | Always, in every session | Costs context even when it is not needed |
The column that matters is the last one. A skill is a request, not a constraint: the same documentation, in its troubleshooting section, says that if a rule must hold every time, even when Claude is not following the skill, it should be moved into a hook. A check that must fire on every file edit is not skill material. Hooks are covered in the last article of this series; the MCP protocol, which a skill can live alongside but which is a different thing, is in the third, and for the basics of the protocol there is the dedicated series, starting from Introduction to the Model Context Protocol.
How it is loaded: three levels, and a cost you always pay
What makes skills useful is staged loading, which the Agent Skills documentation calls progressive disclosure. At the first level there are only the name and description of each skill, which are always in the context: the platform documentation estimates about 100 tokens per skill. At the second level there is the body of SKILL.md, which enters the context only when the skill is activated, and for which the Agent Skills specification recommends fewer than 5,000 tokens. At the third level there are the supporting files and scripts: documents enter the context when Claude reads them, while scripts are executed and only what they print enters the context.
The practical reasoning is this: the description is the only thing Claude sees of a skill before deciding whether to use it, so it is the part to write best, and also the part you pay for on every turn. Claude Code makes this explicit with three numbers, all taken from its documentation. The description combined with when_to_use is truncated at 1,536 characters in the listing; the whole listing has a budget equal to 1% of the model's context window, and when it goes over, it drops descriptions starting from the skills you use least; after a compaction of the conversation, the first 5,000 tokens of every skill already invoked are re-attached, with an overall cap of 25,000. A writing rule follows: put the most important instruction at the top of the file, because at the bottom it may not survive.
How Claude actually decides whether a description matches the request is not documented: the documentation says only that the description serves this purpose and that it is worth putting in the words a user would really use. Anyone who writes that the mechanism is an embedding comparison with a configurable threshold is describing a hypothesis, not a fact. The useful consequence is a different one: testing a skill is pragmatic (you ask for something that should activate it and see whether it starts), as we will see in the next article.
Anatomy of a real skill
Here is the skill we will use throughout the series. It is designed for a test project with Flyway migrations on PostgreSQL: given an SQL file, it runs a script that flags the dangerous statements and asks Claude to propose rewrites. The file is this one, and every line of the frontmatter answers a precise question.
---
name: revisione-migration
description: Reviews a Flyway migration for PostgreSQL before the merge and flags the statements that block writes or lose data. Use when the user asks to review, check or approve a V__*.sql file.
argument-hint: [path-of-the-sql-file]
allowed-tools: Bash(python3 ${CLAUDE_SKILL_DIR}/scripts/check_migration.py *)
---
Review the migration `$ARGUMENTS`.
1. Run `python3 ${CLAUDE_SKILL_DIR}/scripts/check_migration.py $ARGUMENTS` and read the result: each line is a finding with line number, severity and reason.
2. For every `HIGH` finding, propose the rewrite without applying it.
3. Do not declare the migration safe. The script does not know the size of the tables or the traffic: say what it checked and what it did not.
The rules and their sources are in [regole.md](regole.md).
The first line of the frontmatter, name, is missing on purpose: for skills in the .claude/skills/ folders the default name is the name of the folder, so /revisione-migration works anyway. The description says what the skill does and, in the second sentence, when to use it, with the words a user would really write ("review", "check", "approve"). argument-hint is only the hint that appears in autocompletion; $ARGUMENTS in the body is the placeholder that becomes whatever you type after the name, so /revisione-migration src/db/V12__ordini_stato.sql substitutes the path. Had I left the placeholder out, Claude Code would have appended a line ARGUMENTS: ... at the end.
The most delicate field is allowed-tools. It says which tools Claude may use without asking you for permission during the turn in which the skill is invoked, and the permission expires at the next message. It does not restrict the available tools: all of them remain callable, and your permission rules still apply to the ones not listed. Here it grants exactly one thing, running that script with any arguments. ${CLAUDE_SKILL_DIR} is replaced with the skill's folder both in the body and in the rule, so the rule matches exactly the command the body orders to run, and the skill behaves identically from any working directory. The value is narrow for a reason: a wider permission, such as all of Bash, would turn a review skill into a way of running any command without confirmation.
The fields you will change most often, with the values they take if you do not write them, are these:
description: recommended but not required in Claude Code; if missing, the documentation says the first non-empty line of the body is used.disable-model-invocation: defaults tofalse; withtrueClaude does not load the skill on its own and its description leaves the context.user-invocable: defaults totrue; withfalsethe skill disappears from the/menu and only Claude can load it.paths: absent by default; with globs the skill activates on its own only when you work on matching files.context: fork: absent by default; with this value the skill runs in a subagent that does not see the conversation.
These five fields govern three distinct decisions: who can start the skill, when Claude considers it, where it runs. A frequent mistake is leaving the default values on a skill with side effects, such as a release or sending a message: the documentation gives exactly this example and recommends disable-model-invocation: true, because you do not want Claude to decide to publish just because the code looks ready to you. At the opposite end, a knowledge-only skill (such as the context of a legacy system) makes sense with user-invocable: false.
The full folder structure is this. Everything that is not SKILL.md is optional, and the point is precisely that it stays out of the context until someone reads or runs it.
revisione-migration/
├── SKILL.md (required: frontmatter + instructions)
├── regole.md (read only if needed: the rules and their sources)
└── scripts/
└── check_migration.py (executed: only what it prints enters the context)
The check_migration.py script is written and tested in the next article; here it is enough to see what enters the context when it runs. Executed on a test file built for the purpose, with four dangerous statements, it prints four lines, and only those four lines reach Claude, not the code of the script.
$ python3 revisione-migration/scripts/check_migration.py campioni/V12__ordini_stato.sql
# Output:
# 2 HIGH R3 NOT NULL without DEFAULT fails if the table already has rows
# 3 HIGH R2 without CONCURRENTLY it blocks writes to the table until the index is ready
# 4 MEDIUM R4 usually rewrites the table and its indexes: check whether the type change is binary-compatible
# 5 HIGH R1 deletes data: the migration cannot be undone with another migration
The test file is a project invented for the occasion (a table ordini, Italian for "orders", that exists nowhere), and the lines are the real ones from the run. Exit code 1 signals the presence of a high-severity finding. Notice what the script does not say: it does not know how many rows the table has, so it cannot say how long the lock lasts. That is why the body of the skill orders Claude not to declare the migration safe: a deterministic, limited check, accompanied by honesty about what it cannot see, is worth more than a confident, unverifiable judgment.
Checking the frontmatter before it fails silently
The frontmatter is where it is easiest to go wrong without noticing. The documentation says so bluntly: a field name must match the table exactly, hyphens included, and Claude Code ignores a field it does not recognize without reporting errors; if the YAML cannot be parsed, the skill still loads, but with no fields set; and the frontmatter exists only if --- is the first line of the file. In all three cases the skill seems to work and does not do what you wanted. The small validator below encodes these rules, plus the limits of the Agent Skills specification.
"""Validates the frontmatter of a SKILL.md against the Claude Code documentation and the Agent Skills specification."""
import re
import sys
import yaml
CAMPI_CLAUDE_CODE = {
"name", "description", "when_to_use", "argument-hint", "arguments",
"disable-model-invocation", "user-invocable", "allowed-tools",
"disallowed-tools", "model", "effort", "context", "agent", "background",
"hooks", "paths", "shell", "metadata", "license", "compatibility",
}
CAMPI_CARICAMENTO = {"name", "description", "license", "compatibility", "metadata", "allowed-tools"}
def leggi_frontmatter(testo):
"""The frontmatter exists only if the first line is '---'; otherwise the whole file is body."""
righe = testo.splitlines()
if not righe or righe[0].strip() != "---":
return None, testo
for i in range(1, len(righe)):
if righe[i].strip() == "---":
return yaml.safe_load("\n".join(righe[1:i])) or {}, "\n".join(righe[i + 1:])
return None, testo
def valida(testo):
fm, corpo = leggi_frontmatter(testo)
esiti = []
if fm is None:
return ["ERROR frontmatter missing: the first line must be '---'"]
if not isinstance(fm, dict):
return ["ERROR the frontmatter is not a YAML mapping"]
for chiave in sorted(set(fm) - CAMPI_CLAUDE_CODE):
esiti.append(f"WARNING unknown field '{chiave}': Claude Code ignores it without errors")
for chiave in sorted((set(fm) & CAMPI_CLAUDE_CODE) - CAMPI_CARICAMENTO):
esiti.append(f"NOTE field '{chiave}' is valid in Claude Code, rejected by claude.ai and the Skills API")
nome = fm.get("name")
if nome is not None and (not re.fullmatch(r"[a-z0-9]+(-[a-z0-9]+)*", str(nome)) or len(str(nome)) > 64):
esiti.append(f"WARNING name '{nome}' outside the Agent Skills specification (a-z, 0-9, hyphens, max 64)")
desc = str(fm.get("description", ""))
if not desc:
esiti.append("WARNING description missing: Claude has no criterion for loading the skill")
if len(desc) > 1024:
esiti.append(f"WARNING description of {len(desc)} characters: above 1024 the Agent Skills specification rejects it")
if len(desc) + len(str(fm.get("when_to_use", ""))) > 1536:
esiti.append("WARNING description + when_to_use above 1536 characters: the listing truncates them")
if len(corpo.splitlines()) > 500:
esiti.append("WARNING the body exceeds 500 lines: move the details into supporting files")
return esiti or ["OK no findings"]
if __name__ == "__main__":
with open(sys.argv[1], encoding="utf-8") as f:
for riga in valida(f.read()):
print(riga)
There are three things to look at. leggi_frontmatter applies the first-line rule: if the file does not start with ---, it returns None and the whole file is treated as body. The two sets at the top, CAMPI_CLAUDE_CODE and CAMPI_CARICAMENTO, are copied from the fields table and from the one on use outside Claude Code: the six fields of the specification are the only ones that claude.ai and the Skills API accept, and any other blocks the upload with an error instead of being ignored. Finally valida uses the documented thresholds: 1,024 characters for the description in the specification, 1,536 for description plus when_to_use in the Claude Code listing, 500 lines of body. It does not replace claude plugin validate, which the documentation points to for finding files with unreadable YAML: it complements it for the rules that command is not documented to check.
You need PyYAML (pip install pyyaml). I try it on three files: the skill of this article, the frontmatter this series originally published (with triggers and permissions, fields that do not exist) and a file without the correct first line.
$ python3 valida_skill.py revisione-migration/SKILL.md
# Output:
# NOTE field 'argument-hint' is valid in Claude Code, rejected by claude.ai and the Skills API
$ python3 valida_skill.py campioni/skill_vecchia.md
# Output:
# WARNING unknown field 'permissions': Claude Code ignores it without errors
# WARNING unknown field 'triggers': Claude Code ignores it without errors
$ python3 valida_skill.py campioni/skill_senza_apertura.md
# Output:
# ERROR frontmatter missing: the first line must be '---'
Read the result like this. Our skill has no blocking findings, and the only note reminds you that argument-hint is a Claude Code field: if you uploaded the same folder to claude.ai or the Skills API, the documentation says the upload would fail with an error on that field. The old frontmatter produces two warnings: triggers and permissions are not documented fields, so those lines did nothing, and the skill activated (if it activated) only thanks to the description. The third file shows the subtlest error, because it produces no message in Claude Code: without --- on the first line, name and description become body text.
Where a skill lives, and where it does not reach
Where you save the folder decides who sees it. In the Claude Code documentation there are four paths, and the practical difference is between what travels with the repository and what stays on your machine.
~/.claude/skills/<name>/SKILL.md: personal, valid in all your projects on this machine..claude/skills/<name>/SKILL.mdinside the project: everyone working in the repository sees it, if you commit it.skills/<name>/SKILL.mdinside a plugin: active wherever the plugin is enabled, with the/plugin:skillprefix.- The managed settings folder: for skills an organization distributes to all its users.
The default choice is the project one: a team convention that lives in the repository is reviewed in pull requests like any other file. One limit remains that surprises anyone expecting a single catalog. The platform documentation is explicit: custom skills do not sync across surfaces. A skill uploaded to claude.ai must be uploaded again to the API, and a Claude Code folder is separate from both. The execution conditions change too: on the API, skills run in a container with no network access and no package installation, while in Claude Code they have the same access as any program on your machine. A script that calls an external service works locally and fails on the API.
The risk: installing a skill is installing software
A skill carries instructions and code, and the platform documentation treats it as such: use only skills you wrote yourself or that come from trusted sources, because a malicious skill can make Claude call tools or run code in ways that do not match the stated purpose, with data exfiltration as a possible outcome. It adds an observation that holds for honest skills too: if they read content from external URLs, that content may contain instructions, and an external dependency that changes over time can make a previously safe skill dangerous. It is the same family of risk as instruction injection through the content that is read, which we will meet again for MCP tools.
Claude Code adds two concrete facts worth knowing before opening someone else's repository. The first: the allowed-tools of a project skill also applies in a non-interactive run in a folder you have never approved, because folder approval does not govern it; a skill can therefore grant itself wide permissions, and the field should be reread before working in the repository. The second: the !`command` syntax, which runs a shell command before Claude sees the text, runs on your machine; it can be disabled for user, project and plugin skills with the disableSkillShellExecution setting, and it is designed for managed settings, where users cannot change it. Skills synced from claude.ai never run those commands on your machine.
The countermeasures, then, are small and verifiable:
- read someone else's skill in full (files, scripts, resources) before installing it, looking for network calls and file accesses unrelated to its purpose;
- keep
allowed-toolsto a single command and never to all ofBash; - set
disable-model-invocation: trueon anything with side effects; - disable shell execution in skills where the organization's policy requires it.
None of these measures protects against a skill whose stated purpose is already dangerous, because in that case the abuse is not a defect but the function: that is why the first item is a human reading, not a tool. For a broader picture of Claude Code security see Security and Privacy with Claude Code.
When it is not a skill
Three clues tell you that you are using the wrong tool. If the rule must always hold, you need a hook. If you need data or an action Claude cannot do on its own (reading a database, opening a ticket), you need an MCP server, and possibly a skill that explains how to use it. If the instructions are short and apply to the whole project, they belong in CLAUDE.md, because a skill that always loads has no reason to be a skill. The choice of how to structure a large skill is also covered in Skill design pattern: progressive disclosure of the Claude Code Workflow series, and for a shorter introduction there is Agent Skills: Building Modular Capabilities for Claude.
Frequently asked questions
Can a skill contain tools with a JSON schema?
No, not by itself. Tools with a schema are tools of the Anthropic API or tools exposed by an MCP server. A skill can run scripts present in its own folder and can explain to Claude how to use those tools, but the schema does not live in SKILL.md.
Do skills work without Claude Code?
Yes, with different limits on each surface. On the API you need the code execution tool and a container without network; on claude.ai custom skills are uploaded as a zip archive; in Claude Code they are folders. The SKILL.md format is common, the accepted fields are not: outside Claude Code only the six of the specification are valid.
How much context do they cost?
Descriptions always cost, the body costs only while the skill is active and then stays in the conversation. The Claude Code command /skill-doctor shows the cost of each skill and how many times it has been used, and it is the right way to decide which to switch off; the number depends on your skills, so there is no point giving it in the abstract.
What you can do now
You can tell a skill apart from a hook, an MCP server and CLAUDE.md, and so you know when not to write one. You know which frontmatter fields really exist, what they are worth if you omit them and what happens with an invented field. You have a frontmatter validator to adapt to your folders and a complete skill to work on. In the next article we build it for real, with the script and a test that is actually run.
Later in the series you will also find skills, plugins and MCP servers in an organization.
Sources
- Extend Claude with skills (Claude Code documentation) - frontmatter fields, paths,
allowed-tools, command injection, listing limits (1,536 characters, 1% of the context, 5,000 and 25,000 tokens after compaction), troubleshooting. Consulted on 2026-11-13. - Agent Skills overview (platform documentation) - the three loading levels, about 100 tokens per skill, execution environments, no syncing across surfaces, security warnings. Consulted on 2026-11-13.
- Agent Skills specification - required fields and limits (name up to 64 characters, description up to 1,024, body under 500 lines, fewer than 5,000 tokens recommended). Consulted on 2026-11-13.

Commenti
Caricamento commenti...
Sign in to comment