Build a custom Claude Skill from scratch
Build a working api-endpoints skill from empty directory to shipped-in-the-repo. This tutorial covers activation, file layout, and the mistakes to avoid on your first skill.
Prerequisites
- Claude Code installed
- A project with domain conventions you want to encode (any codebase will work — the API-endpoints example generalizes)
- Familiarity with basic Claude Code file layout (
.claude/directory) - Read the companion blog post for background (optional but helpful)
What you'll learn
- The difference between skills, commands, and subagents (and when skills are the right choice)
- How to design activation conditions that don't over- or under-fire
- How to structure a skill so Claude loads only what it needs
- How to write conventions Claude will actually follow
- How to test and iterate on a skill before rolling out to the team
A Claude Skill is a folder of context that gets activated for a specific class of tasks. When Claude works on API endpoint code, an API-endpoints skill gives Claude the house conventions, reference examples, and pre-commit checklist. When Claude works on database code, a different skill activates. The rest of the time, none of that content loads.
Skills are the pattern for "Claude should know this whenever it's doing X." They're newer than commands, subagents, or hooks — and they're easy to get wrong. This tutorial walks through building one right, using the example of an API-endpoints skill for a Node.js/Express codebase. The pattern generalizes to any domain.
Skills are the least-used primitive and the most-misused. Before building one, verify the shape of your problem matches.
Use a skill when: (1) there's a class of tasks where Claude should have specific knowledge, (2) that knowledge doesn't change per invocation (unlike a command's parameters), (3) the knowledge is too much for CLAUDE.md but too tied to specific tasks to belong there.
Use CLAUDE.md when: the knowledge applies to every task in the codebase. Repo topology, universal conventions, cross-cutting standards.
Use a command when: you want Claude to do something specific ("generate tests for this file"). Skills provide context; commands trigger actions.
Use a subagent when: the work is delegatable and extended. Skills activate during any relevant task; subagents are invoked explicitly.
If you find yourself repeatedly explaining the same domain conventions to Claude across many sessions, you probably want a skill. If you find yourself repeatedly running the same multi-step task, you probably want a command or subagent.
Before creating any files, answer four questions in a text file or comment:
- When should this skill activate? (specific paths, filenames, keywords — not "any code task")
- What knowledge does it provide? (list 3-6 categories)
- What NOT to include? (out-of-scope explicitly)
- What's the "before you're done" checklist? (concrete verification steps)
For our API-endpoints example:
ACTIVATION
- Files under src/api/ or src/handlers/
- Files matching *.route.ts, *.handler.ts
- Keywords: endpoint, route, handler, API
KNOWLEDGE
1. Naming conventions
2. Error response format
3. Success response envelope
4. Auth patterns (JWT vs session vs API key — when each)
5. Input validation approach (zod schemas)
6. Reference examples for common endpoint types
NOT INCLUDED
- Database access patterns (that's data-access skill)
- Business logic patterns (that's domain-model skill)
- Deployment and ops concerns
PRE-COMMIT CHECKLIST
- Handler separated from route
- Auth declared at top
- Input validated
- Standard error shape
- Standard success envelope
- No console.log
- Has at least one testThis sketch is the design contract for the skill. If you can't articulate it clearly, don't start building yet — you'll build a scope-creep skill that dies within a month.
mkdir -p .claude/skills/api-endpoints/{patterns,examples,checklists}
touch .claude/skills/api-endpoints/SKILL.md
touch .claude/skills/api-endpoints/conventions.md
touch .claude/skills/api-endpoints/patterns/auth.md
touch .claude/skills/api-endpoints/patterns/validation.md
touch .claude/skills/api-endpoints/patterns/errors.md
touch .claude/skills/api-endpoints/patterns/responses.md
touch .claude/skills/api-endpoints/examples/simple-get.ts
touch .claude/skills/api-endpoints/examples/auth-protected.ts
touch .claude/skills/api-endpoints/checklists/pre-commit.mdThe structure isn't magic — this is just what worked. The important properties: SKILL.md at the root as an entry point, subdirectories for related content, small focused files rather than one big one.
Claude only reads what it needs. If your entire skill is one 500-line SKILL.md, all 500 lines load every time the skill activates. If it's SKILL.md (entry) + specific files for specific concerns, Claude reads SKILL.md first and pulls only the files relevant to the current task.
The entry file defines when the skill activates and what's in it. Keep it short — 30-60 lines.
---
name: api-endpoints
description: House conventions and patterns for API endpoint code
activates_on:
- path: src/api/**
- path: src/handlers/**
- filename: "*.route.ts"
- filename: "*.handler.ts"
- keywords: [endpoint, route, handler, API, REST]
---
# API endpoints skill
## What this provides
- House conventions for endpoint code (`conventions.md`)
- Auth patterns (`patterns/auth.md`)
- Validation patterns (`patterns/validation.md`)
- Error response format (`patterns/errors.md`)
- Success response envelope (`patterns/responses.md`)
- Reference examples (`examples/`)
- Pre-commit checklist (`checklists/pre-commit.md`)
## When writing new endpoint code
1. Read `conventions.md` first
2. Pick the closest example from `examples/`
3. Read the relevant pattern file for anything non-standard:
- Auth needed? → `patterns/auth.md`
- Complex validation? → `patterns/validation.md`
- Non-trivial errors? → `patterns/errors.md`
## When reviewing endpoint code
Run through `checklists/pre-commit.md` before signing off.
## What this skill does NOT do
- Does NOT cover database access (see `data-access` skill)
- Does NOT cover business logic patterns (see `domain-model` skill)
- Does NOT cover deployment or observability concerns
The "does NOT" section is where scope gets protected over time. Without it, someone will add a section about database access in six months, and the skill will slowly become the "everything about the backend" skill.
This is the file Claude loads whenever it works on endpoint code. Keep it dense: rules Claude wouldn't figure out on its own, in the order they're most relevant.
# API endpoint conventions
## Naming
- Handler functions: `handleXVerb` — e.g. `handleGetUser`, `handleCreateOrder`
- Route files: `x.route.ts` (routing wiring only)
- Handler files: `x.handler.ts` (the logic)
- Never put business logic in route files
## Response format
**Success**: Use the envelope from `patterns/responses.md`.
Never return raw model objects; always shape via a serializer.
**Error**: Use the shape from `patterns/errors.md`.
Never leak internal messages to clients (sanitize with `sanitizeError`).
## Auth
- Every endpoint declares its auth requirement at the top of the handler
- Use middleware, never manual token verification in handlers
- See `patterns/auth.md` for the specific patterns per auth type
## Validation
- Every non-GET endpoint validates its input via a zod schema
- Schemas live next to the handler, named `xSchema`
- Never reach for `any` on request bodies
## Invariants
- Handlers must be functions of (request) → (response)
- Side effects go through repository/service layers
- Never call `console.log` — use `logger`
- Every endpoint must have at least one test
## What NOT to do
- No inline route definitions (breaks OpenAPI generation)
- No global mutable state in endpoint files
- No throwing raw errors — use `TypedError` subclasses
- No hardcoded URLs or credentials — use `config`
Notice what's not here: no explanation of why. No history. No aspirational content. Just rules, in the form "do X" or "don't do Y." Rationale belongs in ADRs; this file is for what Claude needs to follow the conventions.
For each common endpoint shape, add one reference implementation. Real code — not pseudocode.
// Reference: simple authenticated GET endpoint
// Retrieves a single resource by ID
import { Router } from 'express';
import { authRequired } from '@/middleware/auth';
import { getUserByIdSchema } from './users.schema';
import { userRepo } from '@/repositories/user-repo';
import { logger } from '@/lib/logger';
import { NotFoundError, sanitizeError } from '@/lib/errors';
// route
export const router = Router();
router.get('/:id', authRequired, handleGetUser);
// handler
export async function handleGetUser(req, res) {
const { params } = getUserByIdSchema.parse({
params: req.params,
});
const user = await userRepo.findById(params.id);
if (!user) {
throw new NotFoundError('user', params.id);
}
logger.info({ userId: params.id }, 'user retrieved');
return res.json({
ok: true,
data: serializeUser(user),
});
}
function serializeUser(user) {
return {
id: user.id,
email: user.email,
displayName: user.displayName,
// never expose: password_hash, mfa_secret, session_tokens
};
}
Real code shows exactly what house style looks like. Pseudocode would show what "an endpoint" is; this shows what "our endpoints" look like. Big difference.
Add 2-4 examples covering the common cases (simple GET, auth-protected, file upload, etc.). Resist adding more — three good examples beat fifteen edge-case ones.
Before committing the skill, verify it works. Open Claude Code in your repo and try a task that should activate the skill:
> Add a GET endpoint for retrieving an order by ID at
src/api/orders.route.ts. It should require auth.Check the output. It should:
- Match your naming conventions (handleGetOrder, not getOrder)
- Use your standard response envelope
- Include auth middleware
- Have a zod schema for validation
- Not put logic in the route file
If it does — the skill is working. If it doesn't — the conventions.md needs more specificity, or the skill isn't activating (check activation criteria in SKILL.md).
Try a task that should NOT activate the skill (e.g., "add a database migration"). Verify the skill's content doesn't appear in Claude's reasoning. Both directions matter — false positives cost context; false negatives miss conventions.
git add .claude/skills/api-endpoints/
git commit -m "chore: add api-endpoints skill
Encodes house conventions for API endpoint code so Claude
follows them automatically. Activates on src/api/ and src/handlers/."The skill is now versioned with the codebase. Team members pulling the repo get it automatically — no separate install step. When conventions change, update the skill in the same PR. When someone new joins the team, the skill tells Claude the conventions so the new person's code follows them from day one.
When you ship a new skill, tell the team what it activates on and what it enforces. Otherwise people don't know it's there, they don't update it when conventions change, and it rots.
Recap
You built a complete Claude Skill from empty directory to shipped-in-the-repo. The workflow: sketch on paper first, structure with split files, keep SKILL.md as a short entry point, dense conventions.md, real-code examples, actual test before commit.
This same pattern applies to any domain. A database-access skill for repository conventions. A testing skill for test structure and mocking patterns. A CLI skill for command-line tool conventions. Each with its own activation criteria, focused knowledge, and explicit non-goals.
The single most important habit: revisit the skill quarterly. Skills that get maintained stay valuable; skills that don't get abandoned. Add "review .claude/skills/" to your quarterly maintenance checklist alongside CLAUDE.md review.
Common gotchas
- Skill activates on everything and pollutes every session: Activation criteria too broad. Narrow the paths, filenames, or keywords. Prefer specific over inclusive — you can broaden later if teammates report the skill not activating when it should.
- Skill has activated but Claude ignores its conventions: Conventions.md is probably vague ("prefer good naming"). Replace with specifics ("handler functions named handleXVerb"). Rules Claude can verify → rules Claude follows.
- Examples get out of date and Claude produces outdated code: Include examples in the "modify skill on convention change" process. Or better: pull examples from real code paths (with a link) rather than duplicating.
- Skill grows to 15 files and 3000 lines: Scope creep. Split into multiple skills with narrower activation. Or aggressively trim the current one — most oversized skills have 60% content that doesn't belong.
- Skill file layout drift over time: Enforce structure with a README in the skills folder describing the standard layout. Or a hook that checks new skills against the template.
Get cctk to skip the boilerplate
Everything in this tutorial is already scaffolded in cctk — commands, subagents, hooks, MCP configs. Install and customize instead of starting from scratch.