Claude Code Slash Commands — How to Create Custom Skills

6 min read · Claude Code configuration · Updated April 2026

Claude Code lets you define custom slash commands — type /debug, /code-review, or /plan and Claude runs a predefined workflow. Anthropic has merged the earlier .claude/commands/ flat-file format and the newer .claude/skills/ directory format into one system, so a slash command is a skill. You define the workflow once, install it, and reuse it across every project.

Custom commands and skills are now the same feature. A file at .claude/commands/deploy.md and a directory at .claude/skills/deploy/SKILL.md both register /deploy and behave identically. Your existing .claude/commands/ files keep working. The skill directory form adds optional features (supporting files, per-skill tool permissions, automatic invocation by Claude) and is the recommended format for anything non-trivial.

Where Claude Code looks for slash commands

Claude Code checks four scopes, higher-priority scopes winning when names overlap:

Precedence runs enterprise > personal > project. If a skill and a legacy command share a name at the same scope, the skill wins. Adding, editing, or removing a skill inside a watched directory takes effect during the current session without restarting; creating a brand-new top-level skills directory requires a Claude Code restart so the filesystem watcher can pick it up.

Creating your first slash command

The skill directory form is the recommended shape. Create the directory and a SKILL.md inside it — the directory name becomes the command:

mkdir -p ~/.claude/skills/code-review
$EDITOR ~/.claude/skills/code-review/SKILL.md

Then put this inside SKILL.md:

---
name: code-review
description: Review staged changes for security issues, bugs, and quality problems.
---

Review the current code changes for:

**Security (check first)**
- SQL injection, XSS, CSRF, path traversal
- Hardcoded secrets or API keys
- Improper input validation

**Correctness**
- Logic errors and edge cases not handled
- Null/undefined handling gaps
- Async misuse or race conditions

**Quality**
- Functions doing more than one thing
- Misleading variable or function names

Output format:
🔴 CRITICAL — [issue] at [file:line] — [fix]
🟡 WARNING — [issue] at [file:line] — [fix]
🔵 NOTE — [suggestion]

End with: APPROVE / APPROVE WITH FIXES / BLOCK

Now type /code-review in any Claude Code session and Claude runs this exact workflow.

The directory name becomes the slash command for the skill format; the filename does the same job for the legacy .claude/commands/*.md form. A name: frontmatter field is optional — when present it overrides the directory or filename.

Before you write your own, check the bundled ones. Claude Code ships a set of bundled skills in every session — /debug, /simplify, /batch, /loop, and /claude-api among others. These behave like custom skills but are maintained by Anthropic. Type / in Claude Code to see what's already available before creating one with the same name, and see the commands reference for the full list.

Useful frontmatter fields

All frontmatter is optional, but a good description: is what lets Claude decide to invoke a skill automatically when it matches your request. Fields worth knowing:

The allowed-tools list composes with your settings.json permissions: tools you pre-approve here are granted only while the skill is active. Everything else still goes through your active permission settings across all four scopes — managed, personal (~/.claude/settings.json), project (.claude/settings.json), and local (.claude/settings.local.json) — following Claude Code's precedence rules (managed wins, then CLI args, then local, then project, then personal).

Legacy flat-file form

If you prefer the shorter .claude/commands/<name>.md form, it still works and supports the same frontmatter fields — no directory or SKILL.md needed. Skills just give you a folder for supporting files and a few extra features.

10 slash commands worth having

/code-review

Security audit + quality check before every commit. Outputs prioritized findings with severity ratings and specific fixes.

/debug

Scientific-method debugging: form hypothesis → identify evidence → propose targeted fix. Stops Claude from trying random solutions.

/plan

Forces Claude to produce a step-by-step implementation plan before writing any code. Essential for any change touching 3+ files.

/write-tests

Generates tests using Testing Trophy methodology — mostly integration tests, no implementation-detail assertions, real mocking strategy.

/refactor

Cleans up code with zero behavior change. Explicit constraints prevent Claude from accidentally changing logic while "improving" code.

/security-check

OWASP Top 10 audit of a specific endpoint or file — auth, data exposure, injection, business logic flaws.

/commit

Reviews what changed, classifies the commit type, writes a conventional commit message, and stages specific files (never git add -A blindly).

/explain

Explains code, errors, or architecture at the right depth — brief for simple questions, structured for complex systems.

/api-design

Designs a full REST API contract (methods, paths, request/response schemas, error codes) before writing any implementation.

/ship

Pre-PR checklist covering code quality, tests, security, documentation, and scope. Pass/fail per item with explanations.

Tips for writing effective skills

Be specific about output format

Vague instructions get vague results. If you want a bulleted list of findings with severity ratings, describe exactly that format in the skill body.

Include what NOT to do

A /refactor skill that doesn't say "zero behavior change" will have Claude accidentally changing logic. Constraints are as important as instructions.

Keep each skill to one job

A /review-and-fix skill that both reviews and applies fixes is harder to control than /code-review followed by targeted edits. Single responsibility applies to skills too.

Frequently asked questions

What is a slash command in Claude Code?

A slash command is a reusable workflow you invoke by typing a forward slash followed by its name. Anthropic merged slash commands and skills into a single system, so a file at .claude/commands/deploy.md and a directory at .claude/skills/deploy/SKILL.md both register /deploy and behave the same way. The skill directory form is recommended because it supports supporting files, per-skill tool permissions, and optional automatic invocation by Claude.

Where do slash command files live?

Claude Code looks in four scopes: enterprise-managed paths, personal-level at ~/.claude/skills/<name>/SKILL.md (also ~/.claude/commands/<name>.md for the legacy flat-file form), project-level at .claude/skills/<name>/SKILL.md inside the repo, and plugin-scoped paths. Enterprise beats personal beats project; plugin skills use a plugin-name:skill-name namespace so they cannot collide. If a skill and a legacy command share a name, the skill wins.

Do slash commands work across different projects?

Yes — anything under ~/.claude/skills/ or ~/.claude/commands/ is available in every Claude Code session on your machine. Adding, editing, or removing a skill inside a watched directory takes effect live. Creating a new top-level skills directory that did not exist when the session started requires restarting Claude Code so the filesystem watcher can pick it up.

What should a slash command body contain?

Clear instructions for the task, explicit constraints (what NOT to do), and a specified output format. Vague bodies produce vague output; specific bodies produce consistent, reusable workflows. For skills in the directory form, move long reference material into sibling files and link to them from SKILL.md so they load only when needed.

Can slash commands call other tools like MCP servers or hooks?

Yes. A slash command is just context for Claude. If your project has MCP servers connected or PostToolUse hooks configured, Claude uses them while executing the skill body. The skill frontmatter also supports an allowed-tools field so Claude can run specific tools (like Bash(git commit *)) without per-use approval when the skill is active.

Get all 10 skills pre-written

The Claude Code Starter Kit includes all 10 slash command templates above, plus 5 CLAUDE.md project templates, a hooks cookbook, settings profiles, and 20 power prompts — free download.

Download free →

Using GitHub Copilot? Copilot's closest equivalent to slash commands is reusable .prompt.md prompt files — see the Copilot Customization Starter Kit for 5 ready-made prompt files (code review, debug, refactor, write-tests, security-check).

Saved you time? Tip the maker in BTC — no account, no signup, just paste.

BTC bc1qs04leape97ner4wqa98n94l9n0gv9aa84eg4ux