/
. These commands can be sent through the SDK to perform actions like clearing conversation history, compacting messages, or getting help.
Discovering Available Slash Commands
The Claude Code SDK provides information about available slash commands in the system initialization message. Access this information when your session starts:Sending Slash Commands
Send slash commands by including them in your prompt string, just like regular text:Common Slash Commands
/compact
- Compact Conversation History
The /compact
command reduces the size of your conversation history by summarizing older messages while preserving important context:
/clear
- Clear Conversation
The /clear
command starts a fresh conversation by clearing all previous history:
Creating Custom Slash Commands
In addition to using built-in slash commands, you can create your own custom commands that are available through the SDK. Custom commands are defined as markdown files in specific directories, similar to how subagents are configured.File Locations
Custom slash commands are stored in designated directories based on their scope:- Project commands:
.claude/commands/
- Available only in the current project - Personal commands:
~/.claude/commands/
- Available across all your projects
File Format
Each custom command is a markdown file where:- The filename (without
.md
extension) becomes the command name - The file content defines what the command does
- Optional YAML frontmatter provides configuration
Basic Example
Create.claude/commands/refactor.md
:
/refactor
command that you can use through the SDK.
With Frontmatter
Create.claude/commands/security-check.md
:
Using Custom Commands in the SDK
Once defined in the filesystem, custom commands are automatically available through the SDK:Advanced Features
Arguments and Placeholders
Custom commands support dynamic arguments using placeholders: Create.claude/commands/fix-issue.md
:
Bash Command Execution
Custom commands can execute bash commands and include their output: Create.claude/commands/git-commit.md
:
File References
Include file contents using the@
prefix:
Create .claude/commands/review-config.md
:
Organization with Namespacing
Organize commands in subdirectories for better structure:Practical Examples
Code Review Command
Create.claude/commands/code-review.md
:
Test Runner Command
Create.claude/commands/test.md
:
See Also
- Slash Commands - Complete slash command documentation
- Subagents in the SDK - Similar filesystem-based configuration for subagents
- TypeScript SDK reference - Complete API documentation
- SDK overview - General SDK concepts
- CLI reference - Command-line interface