CLAUDE CODE

SKILL.md for Claude Code: How to Write One That Works

You wrote a skill, dropped it in a folder, and Claude Code ignored it. Or it fired on everything and flooded the context with instructions you only wanted once a week. Either way you lost an hour, and the skill still is not doing the job you built it for. Nearly every case comes back to the same small file.

A SKILL.md file is the entry point of a Claude Code skill: a markdown file that starts with YAML frontmatter (a name and a description) and then holds the instructions Claude follows when the skill applies. This guide covers the structure, a complete example you can copy, and a way to check it works before you rely on it.

What goes in a SKILL.md file?

A SKILL.md file has two parts: frontmatter that Claude Code reads up front, and a markdown body that it reads only when the skill is chosen. The frontmatter needs a name and a description. Everything below the closing --- is the body.

The split matters because of how skills are loaded. According to Anthropic's Claude Code documentation on skills, Claude sees each skill's name and description first and pulls in the full file only when the request matches. That makes the description the only part of your skill that is always in play, and the body something that costs context only when it earns it.

A skill is a folder, not a single file. The folder holds SKILL.md plus anything the instructions refer to: a template, a checklist, a script. Project skills live in .claude/skills/<skill-name>/ inside the repo, and personal skills live in ~/.claude/skills/<skill-name>/ in your home directory. If you are still deciding whether you need a skill at all, the difference between a skill and a plain prompt is covered in the Claude Code posts on the BuyCoded blog.

How do you write the description so the skill triggers?

Write the description as a statement of when to use the skill, not as a label for what it is. Claude matches your request against that text, so it needs the words a person would actually type, plus the situations that should activate it.

Compare three descriptions for the same skill:

DescriptionWhat Claude can tell from itLikely result
API helperNothing specific. No task, no trigger.Rarely chosen, or chosen for unrelated work
Standards for API routesThe topic, but not when to act.Chosen inconsistently
Create or edit a Next.js API route handler. Use when the user asks to add an endpoint, change a route, or validate request input.The task, the verbs, and the trigger phrases.Chosen when someone asks for an endpoint

The third version names the artifact (a route handler), the actions (create, edit) and the phrasing people use (add an endpoint). That is the pattern: one sentence for what the skill does, one sentence starting with "Use when".

Keep the name lowercase with hyphens, and make it match the folder name. Keep the description specific enough that two of your skills cannot both claim the same request. If two skills overlap, Claude has to guess, and a guess is the usual cause of a skill that fires at the wrong moment.

What does a complete SKILL.md look like?

A complete SKILL.md is short: frontmatter, a one-line purpose, a numbered procedure, and a pointer to any side files. This example adds API routes to a Next.js project.

---
name: add-api-route
description: Create or edit a Next.js API route handler. Use when the user asks to add an endpoint, change a route, or validate request input.
---

# Add an API route

Follow the project's route conventions every time.

## Steps

1. Find the closest existing route under app/api and copy its structure.
2. Define a zod schema for the request body in the same folder.
3. Parse the body with the schema and return a 400 with the issues on failure.
4. Return JSON with an explicit status code. Never return a bare object.
5. Add a test next to the route that covers one valid and one invalid body.

## Reference

For error response shapes, read error-shapes.md in this folder.

Notice what the example leaves out. It does not explain what zod is, restate general TypeScript advice, or describe the whole project. Claude already knows those things, and every extra paragraph competes with the instructions that are specific to your codebase.

The last section is the useful trick. Instead of pasting every error shape into the body, the skill points to error-shapes.md in the same folder. Claude reads that file only when the task needs it, so a simple route change does not pay for the reference material.

How long should a SKILL.md be?

Keep the body under roughly 100 to 150 lines and give it one job. That is a working rule of thumb, not a documented limit, and the reasoning is simple: a skill that does two procedures will match two kinds of requests and handle neither well.

Split by procedure, not by topic. "Add an API route" and "add a database migration" are separate skills even though both touch the backend. Each gets its own description, so each triggers on its own phrasing.

Use this check when a skill grows:

  1. Read the description aloud and list the requests it should match.
  2. If the list has two unrelated items, split the skill in two.
  3. Move any block longer than about 30 lines of reference text into a side file.
  4. Keep the numbered procedure in SKILL.md so Claude always sees the order of operations.
  5. Delete any sentence that restates what the model already does without being told.

How do you test that a SKILL.md actually works?

Test it with three requests: one that should trigger it, one phrased differently that should also trigger it, and one that should not. If all three behave correctly, the description is doing its job.

Start a fresh Claude Code session so nothing is carried over, then ask for the task in plain words, for example "add an endpoint that accepts a project name". Check whether Claude announces or uses the skill and whether the output follows your numbered steps. Then rephrase the request without any word from the description, such as "I need a new POST handler for projects". A good description survives the rewording.

The negative test matters just as much. Ask for something nearby, like a CSS change, and confirm the skill stays out of the way. A skill that fires on everything is as broken as one that never fires, because it spends context on every turn. When a test fails, change the description first and the body second, since the description decides whether the body is ever read.

Should you write every skill yourself?

Write the skills that encode your own conventions, and start from a tested package for the generic ones. The frontmatter and structure above take minutes. What takes time is the iteration: finding the phrasing that triggers reliably, trimming the body, and confirming it does not collide with your other skills.

That iteration is the part BuyCoded's Claude Code Skills Pack is meant to save. It gives you ready-made skill folders to install and then adapt, so you begin from a working description and a tested layout instead of an empty file. Use it as a reference for how a finished skill is laid out even if you end up rewriting most of it for your stack.

The honest objection is that skills are only text files, and you could write all of them. That is true. If you have a clear convention that only your team knows, write it yourself; no pack can know it. A pack is worth it for the common jobs where you would otherwise spend an evening tuning descriptions that someone else has already tuned.

What should you do next?

Pick one task you repeat every week, write a SKILL.md for it using the example above, and run the three-request test. When you want working skill folders to compare against or build on, browse the BuyCoded product catalog, open the Claude Code Skills Pack page, and check what it includes before you buy. Downloads are instant, so you can install a skill and test it the same day.

For the underlying format, the primary source is Anthropic's own Claude Code skills documentation, which is worth rereading whenever the loading behavior changes.

Frequently asked questions

What is a SKILL.md file in Claude Code?

A SKILL.md file is the main file of a Claude Code skill. It begins with YAML frontmatter containing a name and a description, followed by markdown instructions. Claude Code reads the description to decide when the skill applies, and loads the instructions only when a request matches that description.

Where do I put a SKILL.md file?

Put it inside a folder named after the skill. For a project skill, use .claude/skills/<skill-name>/SKILL.md in the repository so teammates get it with the code. For a personal skill, use the same layout under ~/.claude/skills/ in your home directory, which applies across all your projects.

Why is my SKILL.md never used?

The description is usually too vague. Claude matches your request against the description text, so a label like 'API helper' gives it nothing to match. Rewrite it as what the skill does plus a sentence starting 'Use when', using the words people actually type, then retest in a fresh session.

How long should a SKILL.md be?

Aim for one procedure and roughly 100 to 150 lines at most. That figure is a practical guideline rather than an official limit. If a skill needs long reference material, move it into a separate file in the same folder and point to it, so Claude reads it only when needed.

Can a skill include other files?

Yes. A skill is a folder, so it can hold templates, checklists and scripts next to SKILL.md. Reference them by filename in the body. Claude opens those files when the task calls for them, which keeps the always-loaded part of the skill small and the context cost low.