Skip to content

Lesson 17 of 40Agents

Writing Skills

Package know-how as a Claude Code skill, write a description that triggers at the right time, and keep it lean with reference files and scripts.

15 min read0/4 questions

You will notice yourself typing the same instructions again and again: "when you write a Playwright test, look at the existing tests first, use role-based locators, run it before you say it is done." A skill turns those instructions into a reusable package that Claude loads only when the task calls for it. Skills are how you teach an agent your team's way of doing a job without stuffing every rule into every session. This lesson shows what a skill is made of, how it stays cheap, how to write the one line that decides when it runs, and walks through a complete skill for writing Playwright tests.

What a skill is

A skill is a folder with a SKILL.md file in it. SKILL.md has YAML frontmatter (a name and a description) and a Markdown body with the instructions. The folder can also hold anything the instructions need: longer reference documents, templates, and scripts.

Where you put the folder decides who gets it:

LocationWho gets it
.claude/skills/<name>/SKILL.mdEveryone working in this project (commit it)
~/.claude/skills/<name>/SKILL.mdYou, in every project (a personal skill)
Inside a pluginEveryone who installs that plugin

Use project skills for team conventions ("how we write migrations here"). Use personal skills for your own habits ("how I like commit messages written"). A plugin bundles skills, subagents, hooks and MCP servers so a team can install a whole set together.

A skill runs in two ways. You can call it directly as a slash command, /skill-name followed by any arguments. Or Claude loads it automatically when your request matches its description. If a skill should only ever run when you ask (a deploy, say), add disable-model-invocation: true to its frontmatter.

How is that different from the other places instructions live? CLAUDE.md is always loaded, so it is for facts every task needs. A subagent is a separate worker with its own context. A skill is know-how that sits on the shelf until a matching task comes along, then loads into the conversation that needs it.

Progressive disclosure

The trick that makes skills cheap is progressive disclosure: information loads in layers, only as it is needed.

What a skill costs, layer by layer
  1. name + descriptionalways in context, every session
  2. SKILL.md bodyloads when the skill is used
  3. references/*.mdloads only if the body points there and the task needs it
  4. scripts/*runs; its code never enters context

Claude always sees each skill's name and description, a line or two. This is how it knows the skill exists. Thirty skills cost about as much as one medium file.

1/4

Run the numbers for a team with 30 skills:

Python
# 30 installed skills. Rough token sizes for each part.skills = [{"name": f"skill-{i}", "description": 60, "body": 2500, "references": 6000} for i in range(30)] always_loaded = sum(s["description"] for s in skills)everything = sum(s["description"] + s["body"] + s["references"] for s in skills) print(f"loaded every turn (names + descriptions): {always_loaded:,} tokens")print(f"if every skill were fully loaded: {everything:,} tokens") # A request matches one skill: its body loads. Only one reference is needed.used = always_loaded + skills[0]["body"] + 1500print(f"this turn, one skill used + one reference: {used:,} tokens")print(f"saved vs loading everything: {100 - used * 100 // everything}%")
Output
Press Run (⌘ Enter) to see what happens.

That is why you can install many skills without slowing every session down, and also why the description has to be good: it is the only part Claude sees when deciding.

Quick check
Which part of a skill is in Claude's context in every session, even when the skill is never used?
Need a nudge? A hint rules out a wrong answer.

Writing a description that triggers

The description decides when the skill runs, so it is the most important line you will write. Lead with the use case: the situations and words that should trigger it.

Weak descriptionWhy it fails
Playwright helper.Says nothing about when to use it
Our testing standards and conventions for the frontend, including various best practices.Vague; does not match how people ask
Write or fix Playwright end-to-end tests. Use when asked for an e2e test, a browser test, a Playwright spec, or to check that a UI flow works.Names the job and the phrases people actually use

Good descriptions:

  • Start with the task, in plain verbs: "Write or fix Playwright tests".
  • List trigger phrases users really type: "e2e test", "browser test", "check the signup flow works".
  • Stay specific. A description that matches everything ("helps with code") fires at the wrong times and gets in the way.
  • Stay short. It is loaded every session. One or two sentences.
Match the pairs0/4 matched

Match each part of a skill folder to its job.

Choose an item, then its match on the other side.

A complete skill: writing a Playwright test

Playwright is a tool that drives a real browser to test web pages end to end. (The testing lesson later in the course covers it properly.) Here is a project skill that teaches Claude how this team writes Playwright tests.

The skill folder
  • my-app/
  • .claude/
  • skills/
  • write-playwright-test/
  • SKILL.mdfrontmatter + short instructions
  • references/
  • locators.mdhow to pick locators, with examples
  • templates/
  • example.spec.tsa spec in house style
  • scripts/
  • run-test.shruns one spec, prints failures
  • tests/
  • e2e/
  • playwright.config.ts
.claude/skills/write-playwright-test/SKILL.md
---
name: write-playwright-test
description: Write or fix a Playwright end-to-end test for a page or user flow. Use when asked for an e2e test, a browser test, a Playwright spec, or to check that a UI flow works.
---
 
# Write a Playwright test
 
1. Read `playwright.config.ts` and two existing specs in `tests/e2e/` first.
   Match their file naming, fixtures and helpers. Do not invent new helpers
   if one already exists.
2. Start from `templates/example.spec.ts`. One user flow per test, named
   after what the user does: `test("guest can check out with a card", ...)`.
3. Locate elements the way a user would: `getByRole`, `getByLabel`,
   `getByText`. Never use CSS classes or XPath. For hard cases, read
   `references/locators.md`.
4. Assert what the user sees, with web-first assertions like
   `await expect(...).toBeVisible()`. Never use fixed waits such as
   `waitForTimeout`.
5. Run the test with `${CLAUDE_SKILL_DIR}/scripts/run-test.sh <spec-path>`.
   If it fails, read the error, fix the test or report a real app bug.
   Do not say you are done until it passes.
6. Report: the file you created, what it covers, and the final run output.
.claude/skills/write-playwright-test/scripts/run-test.sh
#!/usr/bin/env bash# Run one Playwright spec and print a short result line per test.set -euo pipefailnpx playwright test "$1" --reporter=line

Look at what made it into each file:

  • The body is about 20 lines of steps. It tells Claude what to do and in what order, and how to know it is finished (step 5).
  • The locator guide is long and only needed in hard cases, so it lives in references/locators.md and the body points to it.
  • The template shows house style better than a paragraph could.
  • Running the test is a script, referenced with ${CLAUDE_SKILL_DIR} so the path works wherever the skill is installed. Deterministic jobs (running, formatting, checking) belong in scripts: they behave the same every time, and their code never fills the context.

Keep SKILL.md well under about 500 lines. If it is growing, that is a sign the detail should move into reference files.

Testing a skill

A skill is code for an agent, so test it like code:

  1. Does it trigger? Try prompts that should match ("add an e2e test for login") and check that Claude loads the skill. Try phrasings real teammates would use.
  2. Does it stay quiet? Try nearby prompts that should not match ("write a unit test for this function"). If it fires there, narrow the description.
  3. Run it directly. /write-playwright-test checkout flow skips the matching step, so you can test the body on its own.
  4. Check the output, not the vibes. Did the test actually run and pass? Did it follow the locator rule? Read the generated file.
  5. Iterate. When Claude misreads a step, rewrite that step, not the whole skill. Commit changes so the team gets the fix.

Common mistakes to look for when a skill misbehaves:

  • The body repeats CLAUDE.md. Rules every task needs belong in project memory once, not copied into each skill.
  • No definition of done. Without a step like "run it and show the output", Claude may stop at "here is a test" without ever running it.
  • Too many skills that overlap. Two skills with similar descriptions compete, and Claude may load the wrong one. Merge them or make each description name what the other does not cover.
  • Hidden assumptions. A skill written on your laptop may assume tools or paths a teammate does not have. Have someone else try it.

The /skills command lists the skills available in a session. Since skill features are still evolving, check the official docs for the current details.

Put it in order5 steps

Put what happens in order when a user asks for an e2e test.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Quick check
Your skill tells Claude to run a 12-step release checklist the same way every time. What is the best structure?
Need a nudge? A hint rules out a wrong answer.
Key terms
skill
A folder with a SKILL.md (and optional references and scripts) that teaches an agent how to do a specific task.
SKILL.md
The skill's main file: YAML frontmatter with name and description, then Markdown instructions.
progressive disclosure
Loading information in layers: description always, body on use, reference files only when needed.
description
The frontmatter line that decides when a skill triggers. Lead with the use case.
reference file
A longer document in the skill folder that Claude reads only when the body sends it there.
plugin
A package that bundles skills, subagents, hooks and MCP servers for a team to install together.