beginner·
10 min

Your first slash commands

Automate repetitive actions with a single command

What are slash commands?

Slash commands are Markdown files that Claude executes when you invoke them with /. They live in your project under .claude/commands/ and contain instructions Claude follows every time you call them. Think of them as intelligent macros.

Slash command structurebash
.claude/
└── commands/
    ├── optimize.md      → /optimize
    ├── pr.md            → /pr
    ├── commit.md        → /commit
    └── review.md        → /review

Anatomy of a slash command

Each file has two parts: YAML frontmatter with metadata, and the body with instructions for Claude.

.claude/commands/commit.mdmarkdown
---
name: commit
description: Generate a commit message following Conventional Commits
---

Analyze the staged changes (git diff --staged) and generate a commit message that:

1. Follows Conventional Commits format: type(scope): description
2. Uses types: feat, fix, chore, docs, refactor, test, style
3. Description in present tense, maximum 72 characters
4. Adds body if changes are complex

Most common types:
- feat: new feature
- fix: bug fix
- chore: build changes, dependencies
- refactor: refactor with no behavior change

The 6 most useful slash commands

  • /commit — generate commit messages with Conventional Commits
  • /pr — create Pull Request description with full context
  • /review — review code focusing on bugs, security, and performance
  • /optimize — suggest performance improvements in selected code
  • /docs — generate inline documentation for functions and modules
  • /test — generate unit tests for selected code
TIP

You can use $ARGUMENTS in the command body to accept parameters. Example: /review security specifically evaluates vulnerabilities.

How to invoke them

In Claude Code CLIbash
# Invoke directly in chat
/commit

# With arguments
/review security

# See all available commands
/help
INFO

Project slash commands (.claude/commands/) are local to the repository. Personal commands (~/.claude/commands/) are available across all your projects.

exercise

Create your first slash command

Create the file .claude/commands/standup.md in your project with the content below. Then invoke it with /standup in Claude Code.

prompt
---
name: standup
description: Generate the daily standup report based on recent commits
---

Check commits from the last 24 hours with: git log --since="24 hours ago" --oneline

Generate a standup report in this format:

**Yesterday:**
- [list of what I did based on commits]

**Today:**
- [suggested next logical steps based on recent work]

**Blockers:**
- None (unless you see something in the code suggesting a problem)

Maximum 5 points per section. Professional, concise tone.
Next lesson