YouTip LogoYouTip

Claude Code Custom Slash

Claude Code Custom Slash Commands |

\n\n

Skills (skills) are Claude Code’s extension mechanism, enhancing Claude’s capabilities through custom slash commands (e.g., /deploy, /explain-code).

\n\n

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\n

Custom 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.

\n\n

Essentially, .claude/commands/ is a shorthand for Skills; both directory structures are fully equivalent.

\n\n
\n\n

Why Use Custom Slash Commands

\n\n

The 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
\n

Anthropic’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
\n\n

File Structure

\n\n

Each Skill is a directory containing a required SKILL.md file:

\n\n
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\n

The 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
\n\n

Create Your First Custom Slash Command

\n\n

1. Create the Skill Directory

\n\n

Create the skill directory at an appropriate location. The location determines the command’s scope:

\n\n
mkdir -p ~/.claude/skills/explain-code\n# Or create within a project:\nmkdir -p .claude/skills/explain-code\n
\n\n

2. Write the SKILL.md File

\n\n

Create SKILL.md in the directory, including YAML frontmatter and instructions:

\n\n

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\n

3. Use the Custom Command

\n\n

Invoke directly in Claude Code:

\n\n
/explain-code src/auth/login.ts\n
\n\n

Claude will automatically match skills matching the description, or you may invoke explicitly.

\n\n
\n\n

Configuration Fields Explained

\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
FieldDescription
nameDisplay name; becomes the slash command (format: lowercase letters, digits, hyphens; max 64 chars)
descriptionSkill functionality and when to use it (recommended; Claude’s auto-invocation relies on this)
argument-hintHint shown during auto-completion (e.g., )
disable-model-invocationSet to true to prevent Claude from auto-invoking; only manual invocation works
user-invocableSet to false to hide from / menu; only Claude can invoke
allowed-toolsList of tools Claude may use without asking
contextSet to fork to run in a forked sub-agent
agentSub-agent type used when context: fork
pathsList of glob patterns limiting file scope for skill activation
\n\n
\n\n

Invocation Control

\n\n

Control who can invoke the skill via frontmatter:

\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
ConfigurationYou can invokeClaude can invoke
(default)YesYes
disable-model-invocation: trueYesNo
user-invocable: falseNoYes
\n\n
\n\n

Variable Substitution

\n\n

Use variables in skill content; Claude replaces them automatically:

\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
VariableDescription
$ARGUMENTSAll arguments passed during invocation
$ARGUMENTSAccess specific argument by 0-based index
$NShorthand for $ARGUMENTS
${CLAUDE_SESSION_ID}Current session ID
${CLAUDE_SKILL_DIR}Directory containing the skill’s SKILL.md file
\n\n
\n\n

Skill Storage Locations

\n\n

Skills can reside in multiple locations, each with different scopes:

\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
LocationPathScope
Enterprise-wideDetermined by hosting settingsAll users in the organization
Personal~/.claude/skills/<skill-name>/SKILL.mdAll projects
Project-level.claude/skills/<skill-name>/SKILL.mdCurrent project only
Plugin<plugin>/skills/<skill-name>/SKILL.mdScope of plugin activation
\n\n
\n

Files in .claude/commands/ remain valid and support the same frontmatter. If a skill and command share a name, the skill takes precedence.

\n
\n\n
\n\n

Advanced Examples

\n\n

Example 1: Deployment Command (Manual Invocation Only)

\n\n

Example

\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\n

Example 2: Component Migration Command with Arguments

\n\n

Example

\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\n

Example 3: PR Summary Command with Dynamic Context

\n\n

Example

\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\n

Claude Code provides several built-in commands out of the box:

\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
CommandFunction
/batch <instruction>Orchestrate large-scale changes across the codebase
/claude-apiLoad API reference materials
/debug Enable debug logging
/loop <prompt>Repeat prompt execution at intervals
/simplify Review code quality issues
\n\n
\n\n

Best Practices

\n\n

1. How to Write description

\n\n

The description is the basis for Claude’s auto-invocation β€” make it clear:

\n\n
    \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
\n\n

2. Single Responsibility Principle

\n\n

Each 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
\n\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
\n\n

4. Leverage allowed-tools for Permission Control

\n\n

Assign minimal permissions for security-critical operations:

\n\n

Example

\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\n

Commit project-level skills to Git for team sharing:

\n\n
my-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\n

Reference and describe project-specific skills in CLAUDE.md:

\n\n

Custom Slash Commands

\n\n

This 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
\n\n

For detailed usage instructions, refer to @.claude/skills/README.md.

\n\n
\n\n

Frequently Asked Questions

\n\n

Q: What’s the difference between skills and commands directories?

\n\n

There 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.

\n\n

Q: How to pass multiple arguments during invocation?

\n\n

Wrap multiple arguments in quotes: /migrate SearchBar "from:React to:Vue", then use $ARGUMENTS in the skill to retrieve the full string.

\n\n

Q: Can skills be used in sub-agents?

\n\n

Yes. By setting context: fork and the agent field, the skill runs in an independent context within a sub-agent.

\n\n

Q: How to make Claude remember commonly used skills?

\n\n

List all available custom commands and their use cases in CLAUDE.md; Claude will automatically match appropriate skills based on descriptions.

← Claude Code Git WorkflowClaude Code Permission β†’