Claude Code Custom Slash Commands |
\n\nSkills (skills) are Claude Codeβs extension mechanism, enhancing Claudeβs capabilities through custom slash commands (e.g., /deploy, /explain-code).
Each custom command is essentially an independent Skill file, capable of encapsulating complex workflows, project specifications, and common operations for quick invocation in any session.
\n\nCustom commands have been integrated into the Skills system β both the command file at .claude/commands/deploy.md and the skill file at .claude/skills/deploy/SKILL.md create the /deploy command, functioning identically.
Essentially, .claude/commands/ is a shorthand for Skills; both directory structures are fully equivalent.
\n\n
Why Use Custom Slash Commands
\n\nThe core value of custom slash commands lies in standardization + reuse:
\n\n- \n
- Standardize workflows (Solidify workflows): Encapsulate multi-step operations (e.g., βdeploy to productionβ) into a single command \n
- Ensure team consistency (Ensure team consistency): Embed project standards (e.g., βcode review checklistβ) into commands to guarantee all team members follow the same criteria \n
- Reduce cognitive load (Reduce cognitive load): No need to memorize complex command sequences β a single phrase triggers the full workflow \n
- Minimize repetitive input (Reduce repetitive input): High-frequency tasks become single invocations instead of multi-step operations \n
\n\n\nAnthropicβs internal team experience: Tasks executed more than twice per day should be turned into Skills. Do it right once, and it works continuously.
\n
\n\n
File Structure
\n\nEach Skill is a directory containing a required SKILL.md file:
my-skill/\nβββ SKILL.md # Main instruction file (required)\nβββ template.md # Template filled by Claude\nβββ examples/\nβ βββ sample.md # Example demonstrating expected format\nβββ scripts/\n βββ validate.sh # Script executable by Claude\n\n\nThe file format consists of two parts:
\n\n- \n
- YAML frontmatter (between
---delimiters): For configuring metadata \n - Markdown body: Instructions Claude follows when invoking the skill \n
\n\n
Create Your First Custom Slash Command
\n\n1. Create the Skill Directory
\n\nCreate the skill directory at an appropriate location. The location determines the commandβs scope:
\n\nmkdir -p ~/.claude/skills/explain-code\n# Or create within a project:\nmkdir -p .claude/skills/explain-code\n\n\n2. Write the SKILL.md File
\n\nCreate SKILL.md in the directory, including YAML frontmatter and instructions:
Example
\n\n---\nname: explain-code\n\ndescription: Explain code using visual diagrams and analogies. Use when explaining how code works, walking through a codebase, or answering "how does this work?"\n---\n\nWhen explaining code, always include the following:\n\n1. **Start with an analogy**: Compare the code to something in everyday life\n2. **Draw a diagram**: Use ASCII art to illustrate flow, structure, or relationships\n3. **Step-by-step explanation**: Walk through what happens, line by line\n4. **Point out a pitfall**: What common errors or misconceptions exist?\n\n\n3. Use the Custom Command
\n\nInvoke directly in Claude Code:
\n\n/explain-code src/auth/login.ts\n\n\nClaude will automatically match skills matching the description, or you may invoke explicitly.
\n\n\n\n
Configuration Fields Explained
\n\n| Field | \nDescription | \n
|---|---|
name | \n Display name; becomes the slash command (format: lowercase letters, digits, hyphens; max 64 chars) | \n
description | \n Skill functionality and when to use it (recommended; Claudeβs auto-invocation relies on this) | \n
argument-hint | \n Hint shown during auto-completion (e.g., ) | \n
disable-model-invocation | \n Set to true to prevent Claude from auto-invoking; only manual invocation works | \n
user-invocable | \n Set to false to hide from / menu; only Claude can invoke | \n
allowed-tools | \n List of tools Claude may use without asking | \n
context | \n Set to fork to run in a forked sub-agent | \n
agent | \n Sub-agent type used when context: fork | \n
paths | \n List of glob patterns limiting file scope for skill activation | \n
\n\n
Invocation Control
\n\nControl who can invoke the skill via frontmatter:
\n\n| Configuration | \nYou can invoke | \nClaude can invoke | \n
|---|---|---|
| (default) | \nYes | \nYes | \n
disable-model-invocation: true | \n Yes | \nNo | \n
user-invocable: false | \n No | \nYes | \n
\n\n
Variable Substitution
\n\nUse variables in skill content; Claude replaces them automatically:
\n\n| Variable | \nDescription | \n
|---|---|
$ARGUMENTS | \n All arguments passed during invocation | \n
$ARGUMENTS | \n Access specific argument by 0-based index | \n
$N | \n Shorthand for $ARGUMENTS | \n
${CLAUDE_SESSION_ID} | \n Current session ID | \n
${CLAUDE_SKILL_DIR} | \n Directory containing the skillβs SKILL.md file | \n
\n\n
Skill Storage Locations
\n\nSkills can reside in multiple locations, each with different scopes:
\n\n| Location | \nPath | \nScope | \n
|---|---|---|
| Enterprise-wide | \nDetermined by hosting settings | \nAll users in the organization | \n
| Personal | \n~/.claude/skills/<skill-name>/SKILL.md | \n All projects | \n
| Project-level | \n.claude/skills/<skill-name>/SKILL.md | \n Current project only | \n
| Plugin | \n<plugin>/skills/<skill-name>/SKILL.md | \n Scope of plugin activation | \n
\n\n\nFiles in
\n.claude/commands/remain valid and support the same frontmatter. If a skill and command share a name, the skill takes precedence.
\n\n
Advanced Examples
\n\nExample 1: Deployment Command (Manual Invocation Only)
\n\nExample
\n\n---\nname: deploy\n\ndescription: Deploy the application to production\n\ndisable-model-invocation: true\n---\n\nDeploy $ARGUMENTS to production:\n\n1. Run the test suite\n2. Build the application\n3. Push to the deployment target\n\n\nExample 2: Component Migration Command with Arguments
\n\nExample
\n\n---\nname: migrate-component\n\ndescription: Migrate a component from one framework to another\n---\n\nMigrate the $0 component from $1 to $2.\n\nPreserve all existing behavior and tests.\n\nUsage: /migrate-component SearchBar React Vue\n\n\nExample 3: PR Summary Command with Dynamic Context
\n\nExample
\n\n---\nname: pr-summary\n\ndescription: Summarize changes in a Pull Request\n\ncontext: fork\n\nagent: Explore\n\nallowed-tools: Bash(gh *)\n---\n\n## Pull Request Context\n\n - PR diff: !`gh pr diff`\n - PR comments: !`gh pr view --comments`\n - Changed files: !`gh pr diff --name-only`\n\n## Your Task\n\nSummarize this Pull Request...\n\n\n\n\n
Built-in Slash Commands
\n\nClaude Code provides several built-in commands out of the box:
\n\n| Command | \nFunction | \n
|---|---|
/batch <instruction> | \n Orchestrate large-scale changes across the codebase | \n
/claude-api | \n Load API reference materials | \n
/debug | \n Enable debug logging | \n
/loop <prompt> | \n Repeat prompt execution at intervals | \n
/simplify | \n Review code quality issues | \n
\n\n
Best Practices
\n\n1. How to Write description
\n\nThe description is the basis for Claudeβs auto-invocation β make it clear:
- \n
- Specify trigger conditions: βInvoke when user requests code review / analysis / quality checkβ \n
- State prerequisites: βUse only after spec document is confirmedβ \n
- Define boundaries: Clarify when NOT to invoke \n
2. Single Responsibility Principle
\n\nEach skill should do one thing, with clear input/output:
\n\n- \n
/deploy: Deployment only \n /test: Testing only \n /review: Code review only \n
3. Set Invocation Permissions as Needed
\n\n- \n
- Dangerous operations (deploy, delete): Set
disable-model-invocation: true\n - Claude-assisted tasks: Set
user-invocable: false\n - General workflows: Use default configuration \n
4. Leverage allowed-tools for Permission Control
\n\nAssign minimal permissions for security-critical operations:
\n\nExample
\n\n---\nname: read-only-analyzer\n\ndescription: Read-only code analysis for review and understanding\n\nallowed-tools: Read, Grep, Glob, Bash(gh *) # Only these tools allowed\n---\n\nPerform read-only code analysis...\n\n\n\n\n
Team Sharing Strategy
\n\nCommit project-level skills to Git for team sharing:
\n\nmy-project/\nβββ .claude/\nβ βββ skills/\nβ β βββ deploy/\nβ β β βββ SKILL.md\nβ β βββ test/\nβ β β βββ SKILL.md\nβ β βββ review/\nβ β βββ SKILL.md\nβ βββ commands/ # Also supports commands/ directory\nβββ CLAUDE.md\n\n\nReference and describe project-specific skills in CLAUDE.md:
Custom Slash Commands
\n\nThis project provides the following custom slash commands:
\n\n- \n
/deployβ Deploy to specified environment (dev/staging/prod) \n /testβ Run test suite or specified module \n /reviewβ Perform standard code review \n
For detailed usage instructions, refer to @.claude/skills/README.md.
\n\n
Frequently Asked Questions
\n\nQ: Whatβs the difference between skills and commands directories?
\n\nThere is no essential difference. .claude/commands/ is shorthand for .claude/skills/; both work identically. If a skill and command share a name, the skill takes precedence.
Q: How to pass multiple arguments during invocation?
\n\nWrap multiple arguments in quotes: /migrate SearchBar "from:React to:Vue", then use $ARGUMENTS in the skill to retrieve the full string.
Q: Can skills be used in sub-agents?
\n\nYes. By setting context: fork and the agent field, the skill runs in an independent context within a sub-agent.
Q: How to make Claude remember commonly used skills?
\n\nList all available custom commands and their use cases in CLAUDE.md; Claude will automatically match appropriate skills based on descriptions.
YouTip