Claude Code Skills: Build Custom Slash Commands That Actually Work (2026 Guide)
The complete guide to creating Claude Code skills: custom slash commands powered by SKILL.md files, with build, share, and chain steps.
#Skills Are Claude Code's Killer Feature
Most developers use Claude Code like a chatbot — they type a request, get an answer, and repeat. But the people getting 3-5x more value from it have figured out something: skills turn Claude Code from a one-shot tool into a repeatable workflow engine.
A skill is a SKILL.md file that teaches Claude Code how to do a specific task. Create one, and it becomes a /slash-command you can invoke anytime. Skills can run automatically when Claude detects they are relevant, or you can call them directly. They persist across sessions, work across projects, and can be shared with your team.
If you have ever found yourself typing the same detailed prompt for the third time — "review this code for security issues, check for SQL injection, XSS, auth bypasses, output a table..." — that prompt should be a skill.
#Skills vs Commands: What Changed
If you have been using Claude Code for a while, you might remember the old .claude/commands/ system. Here is what happened: custom commands have been merged into skills. Both systems create slash commands, and your existing command files still work.
The difference is that skills give you more:
| Feature | Old Commands (.claude/commands/) | Skills (.claude/skills/) |
|---|---|---|
| Slash command | ✅ | ✅ |
| Frontmatter metadata | ❌ | ✅ |
| Auto-invocation by Claude | ❌ | ✅ |
| Supporting files in directory | ❌ | ✅ |
| Subagent execution | ❌ | ✅ |
| Dynamic context injection | ❌ | ✅ |
| Shareable via npm/git | Limited | ✅ |
If you are starting fresh, use skills. If you have existing commands, they keep working — you can migrate them when it makes sense.
Want step-by-step guides for this and more?
ClawDocx Pro includes 500+ curated prompts, setup guides, SKILL.md files, and templates — everything to make your AI agent unstoppable.
See plans & pricing#Your First Skill in 60 Seconds
Let us build a skill that generates a pull request description from your staged changes. This is one of those tasks you do constantly but never quite prompt the same way twice.
#Step 1: Create the Directory
Skills live in one of two places:
- Personal skills:
~/.claude/skills/— available in every project - Project skills:
.claude/skills/in your repo — shared with your team via git
For a PR description generator, personal makes sense:
mkdir -p ~/.claude/skills/pr-describe#Step 2: Write SKILL.md
Create ~/.claude/skills/pr-describe/SKILL.md:
---name: pr-describedescription: Generate a pull request description from staged or recent changes. Use when the user asks to write a PR description, prepare a PR, or describe their changes.---Generate a pull request description by analyzing the current changes:1. Run `git diff --staged` (or `git diff HEAD~1` if nothing is staged)2. Identify the type of change: feature, bugfix, refactor, docs, or chore3. Write the PR description in this format:## WhatOne sentence summary of what changed.## WhyBrief context on why this change was needed.## Changes- Bullet list of specific changes, grouped by file or area- Include new dependencies, config changes, or migration steps## TestingHow to verify this works. Include specific commands if applicable.## NotesAnything reviewers should pay attention to.#Step 3: Use It
In any Claude Code session:
/pr-describeThat is it. Claude reads the skill, runs the git commands, analyzes the diff, and produces a structured PR description. Every time, same format, no re-prompting.
#Anatomy of a SKILL.md File
Every skill has two parts: frontmatter (YAML between --- markers) and content (Markdown instructions).
#Frontmatter Fields
---name: my-skill # Required. Becomes the /slash-command namedescription: | # Required. Tells Claude when to auto-invoke What this skill does and when to use it. Be specific — vague descriptions lead to false triggers.invocation: user # Optional. "user" = only via slash command # "agent" = only auto-invoked (default: both)subagent: true # Optional. Run in isolated context window---The name and description fields are the most important. The name is what you type after /, and the description is what Claude uses to decide whether to load the skill automatically.
Pro tip: Write descriptions like you are explaining to a coworker when they should use this tool. "Use when reviewing code for security issues" is better than "security review skill."
#Content: The Instructions
The Markdown content after frontmatter is your skill's playbook. Write it as clear instructions that Claude should follow. You can include:
- Step-by-step workflows
- Code blocks with commands to run
- Output format templates
- Conditional logic ("if X, do Y")
- References to files in the skill directory
Think of it as writing a runbook for a junior developer — be explicit about what to do, in what order, and what the output should look like.
#Six Skills Every Developer Should Build
Here are practical skills that pay for themselves immediately. Copy them, modify them, make them yours.
#1. Code Reviewer with Your Standards
---name: reviewdescription: Review code changes against team standards. Use when the user asks for a code review, CR, or to check their changes.---Review the staged changes (or recent commits if nothing staged) against these standards:**Must check:**- Error handling: Are errors caught, logged, and handled gracefully?- Input validation: Is user input validated before use?- Security: SQL injection, XSS, auth checks, secret exposure- Performance: N+1 queries, unnecessary loops, missing indexes- Types: Are types correct and specific (no unnecessary `any`)?**Style checks:**- Functions under 50 lines- Descriptive variable names (no single-letter except loop counters)- Comments explain "why", not "what"**Output format:**For each issue found:- 🔴 **Critical** — Must fix before merge- 🟡 **Warning** — Should fix, not a blocker- 🟢 **Suggestion** — Nice to haveEnd with a summary: total issues by severity, overall assessment (approve / request changes), and one thing done well.#2. Test Generator
---name: gen-testsdescription: Generate tests for a file or function. Use when the user asks to write tests, add test coverage, or test a specific function.---Generate tests for the specified file or function:1. Read the source file and identify all exported functions/methods2. For each function, create tests covering: - Happy path (expected inputs → expected outputs) - Edge cases (empty inputs, null, undefined, boundary values) - Error cases (invalid inputs, network failures, timeouts)3. Use the project's existing test framework (check package.json, pytest.ini, etc.)4. Follow existing test patterns in the codebase (check the test directory)5. Include setup/teardown if the function has side effects6. Name tests descriptively: "should [expected behavior] when [condition]"Run the tests after writing them. Fix any failures.#3. Explain This Codebase
---name: explaindescription: Explain how a codebase, file, or function works with diagrams and analogies. Use when the user asks how something works, wants an overview, or is onboarding to a project.---When explaining code:1. **Start with the big picture**: What does this code accomplish in one sentence?2. **Draw a diagram**: Use ASCII art to show data flow, component relationships, or the call chain3. **Walk through it**: Explain step by step, referencing specific line numbers4. **Highlight the clever parts**: What design decisions were made and why?5. **Flag the gotchas**: What would confuse someone reading this for the first time?Use analogies from everyday life. "This middleware is like a bouncer checking IDs before letting requests into the club."Adjust depth to scope: a single function gets a focused explanation, a full codebase gets an architecture overview with links to key files.#4. Dependency Auditor
---name: audit-depsdescription: Audit project dependencies for security issues, outdated packages, and unused imports. Use when the user asks to check dependencies, audit packages, or clean up imports.---Audit the project's dependencies:1. **Security**: Run the package manager's audit command (`npm audit`, `pip audit`, `cargo audit`, etc.)2. **Outdated**: Check for packages more than one major version behind3. **Unused**: Scan source files for imports and cross-reference with installed packages. Flag packages in the dependency file that are never imported.4. **Duplicates**: Check for multiple versions of the same package in the lock file5. **License**: Flag any packages with non-permissive licenses (GPL, AGPL) if the project uses MIT/ApacheOutput a summary table:- 🔴 Security vulnerabilities (with severity)- 🟡 Outdated packages (current → latest)- ⚪ Unused packages (safe to remove)- 📋 License concernsEnd with recommended actions, prioritized by risk.#5. Migration Planner
---name: migratedescription: Plan and execute a code migration. Use when the user asks to migrate, upgrade, convert, or transition from one technology to another.---When asked to migrate code:1. **Assess scope**: How many files are affected? Run a search for imports/usage of the source technology.2. **Create a plan**: Break the migration into phases that can be merged independently. Each phase should leave the codebase in a working state.3. **Identify risks**: What could break? Are there runtime behaviors that differ between source and target?4. **Write a checklist**: Numbered steps with estimated file counts per step5. **Ask before executing**: Present the plan and wait for approval before making changesDuring execution:- Migrate one file/module at a time- Run tests after each change- Keep a running log of decisions and edge cases encountered- If a pattern repeats more than 3 times, create a helper functionAfter completion, summarize what changed, what was skipped, and any manual steps remaining.#6. Documentation Generator
---name: gen-docsdescription: Generate or update documentation for code. Use when the user asks to document, add docs, write a README, or update API docs.---Generate documentation based on what is requested:**For a README:**- Project name and one-line description- Prerequisites and installation steps (test that they work)- Quick start example (working code)- Configuration options (from env vars, config files)- Available scripts/commands- Contributing guidelines (if CONTRIBUTING.md does not exist)**For API documentation:**- Every endpoint: method, path, description- Request parameters with types and examples- Response format with example JSON- Error codes and their meanings- Authentication requirements**For inline documentation:**- JSDoc/docstrings for all exported functions- Parameter descriptions with types- Return value description- Usage example for complex functions- Note any side effectsAlways read existing docs first. Update rather than overwrite. Match the existing documentation style.#Advanced Patterns
#Supporting Files in the Skill Directory
Skills are not limited to a single SKILL.md. You can include supporting files — templates, reference docs, example outputs — in the skill directory:
~/.claude/skills/pr-describe/├── SKILL.md├── templates/│ ├── feature-pr.md│ ├── bugfix-pr.md│ └── breaking-change-pr.md└── examples/ └── good-pr-example.mdReference them from your SKILL.md:
Use the appropriate template from the `templates/` directory based on the change type.Refer to `examples/good-pr-example.md` for the expected quality level.Claude reads files relative to the skill directory, so these references just work.
#Controlling Who Invokes the Skill
By default, skills can be invoked both by you (via /command) and by Claude automatically. Use the invocation field to restrict this:
---name: deploydescription: Deploy the application to productioninvocation: user # Only runs when you explicitly type /deploy---Use invocation: user for anything destructive or expensive. You do not want Claude auto-deploying to production because it detected the word "deploy" in conversation.
Use invocation: agent for background utilities — things like "check if tests pass" that Claude should do without being asked.
#Running Skills in Subagents
For skills that are context-heavy, add subagent: true to run them in an isolated context window:
---name: deep-reviewdescription: Thorough code review with full codebase contextsubagent: true---This prevents the skill's work from consuming your main session's context. The subagent reads the entire relevant codebase, does its analysis, and returns only the results to your main session.
Use subagents for:
- Reviews that need to read many files
- Documentation generation
- Dependency audits
- Anything that generates lots of intermediate output you don't need to see
#Dynamic Context Injection
Skills can inject context that Claude loads at session start. Add context: true to your frontmatter:
---name: project-standardsdescription: Team coding standards and conventionscontext: true---## Our Standards- Use TypeScript strict mode- All API routes must have input validation with Zod- Database queries go through the repository pattern- Error responses follow RFC 7807 (Problem Details)With context: true, Claude loads this skill's content into every session in the project automatically. Use it sparingly — every context skill consumes tokens on every interaction.
#Organizing Your Skills Library
As your collection grows, keep things findable:
~/.claude/skills/├── review/ # Code review├── gen-tests/ # Test generation├── gen-docs/ # Documentation├── pr-describe/ # PR descriptions├── explain/ # Code explanations├── audit-deps/ # Dependency audit├── migrate/ # Migration planner└── deploy/ # Deployment (user-only)#Personal vs Project Skills
| Location | Scope | Version controlled | Best for |
|---|---|---|---|
~/.claude/skills/ | All projects | No (unless you dotfile it) | Personal workflows, general tools |
.claude/skills/ | This repo only | Yes (committed to git) | Team standards, project-specific tasks |
Rule of thumb: If the skill references project-specific files, conventions, or tools, it belongs in the project. If it is something you use everywhere, it goes in your personal directory.
#Sharing Skills
Project skills are automatically shared when you commit .claude/skills/ to your repository. Anyone who clones the repo gets the skills.
For cross-project sharing, Claude Code skills follow the Agent Skills open standard. You can publish skills as npm packages or git repositories and install them in any project that supports the standard.
#Common Mistakes to Avoid
Vague descriptions. "Helpful coding skill" tells Claude nothing. Be specific about when the skill should activate: "Use when reviewing Python code for type safety issues and mypy compliance."
Skills that are too broad. A single skill that handles code review, testing, documentation, and deployment will do all of them poorly. One skill, one job.
Missing output format. Without explicit output instructions, Claude will format results differently every time. Define exactly what the output should look like.
Forgetting error cases. Your skill should handle "what if there are no staged changes?" or "what if the project has no tests?" Include fallback instructions.
Auto-invoking destructive skills. Any skill that modifies external state (deploys, sends emails, publishes packages) should use invocation: user so it only runs when you explicitly ask for it.
#Skills + OpenClaw: The Full Picture
If you are using OpenClaw as your AI agent platform, you already know skills — they are the foundation of the agent's capability system. Claude Code skills use the same Agent Skills open standard, which means:
- Skills you build for Claude Code work in OpenClaw (and vice versa)
- The ClawHub marketplace has hundreds of ready-made skills
- You get the same
SKILL.mdformat, the same frontmatter fields, and the same auto-invocation behavior
The difference is scope: Claude Code skills focus on development workflows, while OpenClaw skills cover everything from smart home control to email management to financial tracking. But the authoring experience is identical.
If you are building development skills and want them available beyond the terminal, publishing to ClawHub makes them instantly accessible to thousands of OpenClaw agents.
#Start With One Skill
Do not try to build a library of 20 skills on day one. Think about the prompt you typed most often last week. The thing where you kept saying "review this code" or "write tests for this" or "explain how this module works."
That is your first skill.
Build it in 60 seconds using the template above. Use it for a day. Refine the instructions based on what Claude gets right and wrong. Then build your second one.
Within a week, you will have a personal toolkit that makes Claude Code feel like it was custom-built for the way you work — because it was.