Iqraa.tech

Claude Code Slash Commands Guide

Claude Code slash commands provide a way to control Claude directly from the prompt, including built-in commands, custom skills, plugins, and MCP prompts. Users can type / to view available commands and filter them by typing characters, with commands organized into categories like context management, session tools, and configuration.

The guide explains how to create custom skills using the .claude/skills/ directory structure, pass arguments with $ARGUMENTS, and inject live shell output with !`command` syntax. Commands range from basic utilities like /clear and /rename to advanced features like /code-review and /security-review for pre-ship reviews.

Claude Code Slash Commands — This guide to Claude Code slash commands covers the built-in commands, custom skills, plugin commands, and MCP prompts that let you control Claude directly from the prompt.

Claude Code Slash Commands

Claude Code Slash Commands: What You’ll Learn

In this guide to Claude Code Slash Commands, you’ll work through practical, hands-on steps with real examples. Claude Code Slash Commands is explained from the ground up so you can apply it immediately in your own projects.

Slash commands provide the quickest way to steer Claude Code’s behavior during an interactive session. Simply type / at any prompt to view the complete list, or type a few characters to narrow it down. This lesson covers the built-in commands you’ll rely on daily.

Discovering Commands

Type / at the prompt and a menu appears with all available commands. Start typing to filter — /co narrows to /compact, /color, /config, /context, /cost, /copy. Arrow keys navigate, Enter selects. Commands that aren’t available for your current setup are hidden automatically, so you only see what works.

New to Claude Code? Try /powerup — it runs interactive lessons with animated demos that walk you through key features right inside the CLI.

Some commands accept arguments directly: /compact focus on the API layer, /model opus, /effort high, /rename auth-refactor. Others like /context, /cost, and /status run immediately with no arguments.

/compact focus on the payment service

Command Categories

Built-in commands group into a few categories. Knowing the categories helps you find the right command without memorizing all of them.

Context Management

These commands control how much of the conversation Claude can see.

Session Tools

These commands let you manage and revisit work.

Configuration

These commands adjust Claude’s behavior mid-session.

Diagnostics

These commands help when something isn’t working.

Pre-Ship Reviews

These commands check your work before it leaves your branch.

/context
/compact keep the auth refactor plan
/model opus
/effort high
/cost
/code-review high
/code-review --comment

Real-World Code Examples: Slash Commands

Example 1: Git Commit Command

A slash command that automatically creates conventional commits using live git context:

---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*), Bash(git diff:*)
argument-hint: [message]
description: Create a git commit with context
---

## Context

- Current git status: !`git status`
- Current git diff: !`git diff HEAD`
- Current branch: !`git branch --show-current`
- Recent commits: !`git log --oneline -10`

## Your task

Based on the above changes, create a single git commit.
If a message was provided via arguments, use it: $ARGUMENTS
Otherwise, analyze the changes and create an appropriate commit message
following conventional commits format (feat:, fix:, docs:, refactor:, test:, chore:).

Example 2: Code Optimization Analyzer

A skill that reviews code for performance issues and suggests optimizations:

---
description: Analyze code for performance issues and suggest optimizations
---

# Code Optimization

Review the provided code for the following issues in order of priority:

1. Performance bottlenecks - identify O(n-squared) operations, inefficient loops
2. Memory leaks - find unreleased resources, circular references
3. Algorithm improvements - suggest better algorithms or data structures
4. Caching opportunities - identify repeated computations
5. Concurrency issues - find race conditions or threading problems

Format your response with:
- Issue severity (Critical/High/Medium/Low)
- Location in code
- Explanation
- Recommended fix with code example

Example 3: Pull Request Preparation

A comprehensive slash command for PR preparation with restricted tool access:

---
description: Clean up code, stage changes, and prepare a pull request
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git diff:*), Bash(npm test:*), Bash(npm run lint:*)
---

# Pull Request Preparation Checklist

1. Run linting: prettier --write .
2. Run tests: npm test
3. Review git diff: git diff HEAD
4. Stage changes: git add .
5. Create commit message following conventional commits
6. Generate PR summary including what changed, why, testing, and impacts

Pro Tips


Hands-On Challenge: Build Your First Custom Slash Command

Task: Create a custom /lint-check slash command (as a skill) that runs your project’s linter, reports errors, and asks Claude to fix them automatically.

Steps

  1. Create the directory .claude/skills/lint-check/ in your project
  2. Add a SKILL.md file with YAML frontmatter (name: lint-check, a clear description, and allowed-tools: Bash(npm *))
  3. In the body, instruct Claude to: (a) run your linter with dynamic context via !`npm run lint 2>&1`, (b) parse the output, (c) fix each error, and (d) re-run the linter to confirm a clean pass
  4. Save the file and invoke /lint-check in a new Claude Code session
  5. Verify Claude runs the linter, reads the output, and proposes fixes

Expected Outcome

Typing /lint-check should trigger Claude to run your linter, display the results, and offer to fix any reported issues — all without you pasting lint output manually.

Hint: Use the !`command` syntax in your SKILL.md body to inject live shell output. For example: - Lint output: !`npm run lint 2>&1`. Claude sees the result, not the command.


Knowledge Check: Slash Commands in Claude Code

Test your understanding with these quiz questions. Try to answer each question before revealing the answer.

1. What are the four types of slash commands in Claude Code?

  1. Built-in, skills, plugin commands, MCP prompts
  2. Built-in, custom, hook commands, API prompts
  3. System, user, plugin, terminal commands
  4. Core, extension, macro, script commands

Correct Answer: A. Claude Code has built-in commands (like /help, /compact), skills (SKILL.md files), plugin commands (namespaced plugin-name:command), and MCP prompts (/mcp__server__prompt).

2. How do you pass all user-provided arguments to a skill?

  1. Use ${args}
  2. Use $ARGUMENTS
  3. Use $@
  4. Use $INPUT

Correct Answer: B. $ARGUMENTS captures all text after the command name. For positional args, use $0, $1, etc.

3. How do you inject live shell output into a skill’s prompt?

  1. Use $(command) syntax
  2. Use !`command` (backtick with !) syntax
  3. Use @shell:command syntax
  4. Use {command} syntax

Correct Answer: B. The !`command` syntax runs a shell command and injects its output into the skill prompt before Claude sees it.

4. What is the correct directory structure for a new custom skill called “deploy”?

  1. .claude/commands/deploy.md
  2. .claude/skills/deploy/SKILL.md
  3. .claude/skills/deploy.md
  4. .claude/deploy/SKILL.md

Correct Answer: B. Skills live in a directory under .claude/skills/ with a SKILL.md file inside. The directory name matches the command name.

5. How do plugin commands avoid name conflicts with user commands?

  1. They use a plugin-name:command-name namespace
  2. They have a special .plugin extension
  3. They are prefixed with p/
  4. They override user commands automatically

Correct Answer: A. Plugin commands use a namespace like pr-review:check-security to avoid conflicts with standalone user commands.

Test Your Knowledge

/5

Lesson 2 Quiz: Slash Commands

Test your knowledge of Claude Code slash commands - types, arguments, and dynamic context injection.

1 / 5

When both a skill (.claude/skills/name/SKILL.md) and a legacy command (.claude/commands/name.md) exist with the same name, which takes priority?

Skills take precedence over legacy commands with the same name. The skill system supersedes the older command system.

2 / 5

How do you pass all user-provided arguments to a skill?

captures all text after the command name. For positional args, use $0, $1, etc.

3 / 5

How do you inject live shell output into a skill's prompt?

The !`command` syntax runs a shell command and injects its output into the skill prompt before Claude sees it.

4 / 5

What are the four types of slash commands in Claude Code?

Claude Code has built-in commands (like /help, /compact), skills (SKILL.md files), plugin commands (namespaced plugin-name:command), and MCP prompts (/mcp__server__prompt).

5 / 5

What does disable-model-invocation: true do in a skill's frontmatter?

disable-model-invocation: true means only the user can trigger the command via /command-name. Claude will never auto-invoke it.

Your score is

0%

Additional Resources

Resource Type Link
Official Interactive Mode Docs Official Docs code.claude.com/docs/en/interactive-mode
Official Skills Documentation Official Docs code.claude.com/docs/en/skills
CLI Reference Official Docs code.claude.com/docs/en/cli-reference
Claude Code Slash Commands Anthropic Docs docs.anthropic.com — slash-commands
Claude Code Changelog GitHub CHANGELOG.md

Claude Code Slash Commands gives you a solid, repeatable workflow. Bookmark this Claude Code Slash Commands guide and revisit the steps whenever you need them.

Building a Custom Slash Command: A Step-by-Step Walkthrough

The fastest way to understand Claude Code Slash Commands is to build one. This walkthrough creates a /pr-prep command that stages changes, runs your test suite, and drafts a commit message — the kind of repetitive pre-ship routine that’s worth turning into a reusable command instead of retyping every time.

  1. Create the skill directory. Skills live under .claude/skills/, one directory per command. Run mkdir -p .claude/skills/pr-prep inside your project root.
  2. Write the SKILL.md file. Inside that directory, create SKILL.md with YAML frontmatter describing the command and the tools it’s allowed to touch:
    ---
    name: pr-prep
    description: Stage changes, run tests, and draft a commit message before opening a PR. Use when the user mentions shipping, preparing a PR, or wrapping up a change.
    allowed-tools: Bash(git add:*), Bash(git status:*), Bash(npm test:*)
    argument-hint: [scope]
    ---
  3. Inject live repository state. Below the frontmatter, use the !`command` syntax so the command always sees current state instead of a stale snapshot:
    ## Context
    - Git status: !`git status`
    - Test results: !`npm test 2>&1`
    
    ## Task
    Stage the relevant files, and if $ARGUMENTS was provided, scope the commit to that area. Draft a conventional-commit message summarizing the change.
  4. Pass arguments for reuse. $ARGUMENTS captures whatever text follows the command name, so /pr-prep auth module scopes the routine to a specific area without editing the file.
  5. Test it in a fresh session. Start a new Claude Code session in the project, type /pr-prep, and confirm it appears in the menu — Claude Code Slash Commands built as skills are picked up automatically, no restart or registration step required.
  6. Restrict side effects deliberately. Because allowed-tools only grants git add, git status, and npm test, the command physically cannot run git commit or git push on its own — you stay the one who approves the final commit.

If the command doesn’t appear in the / menu, the most common cause is a missing or malformed frontmatter block — SKILL.md requires the opening and closing --- delimiters, and a broken YAML value silently drops the command instead of raising an error. Run claude doctor to confirm your skills directory is being read correctly.

Once the command works, commit .claude/skills/pr-prep/ to git so the rest of the team gets the same shortcut. This is the general pattern behind every custom slash command: a directory, a frontmatter block that scopes tools and describes intent, and a body that mixes live shell context with instructions — the same shape used by the built-in /code-review and /security-review commands referenced earlier in this guide.

Claude Code Slash Commands: Common Mistakes to Avoid

Even experienced developers trip over the same issues when they start with Claude Code Slash Commands. Watch for these and you will save real debugging time.

Claude Code Slash Commands: Best Practices

Claude Code Slash Commands: Frequently Asked Questions

What’s the difference between a skill and a legacy command?

Both appear as Claude Code Slash Commands in the / menu, but skills (.claude/skills/) support directories, auto-invocation, and bundled reference files, while legacy commands (.claude/commands/) are single markdown files without those extras.

Can Claude invoke a slash command automatically?

Yes, if the description field describes when to use it and disable-model-invocation isn’t set to true. Side-effect commands like /deploy should set that field so only a human can trigger them.

How many arguments can a command accept?

As many as you pass after the command name. $ARGUMENTS captures everything as one string, or use $0, $1, and so on for positional access to individual arguments.

Do plugin slash commands ever collide with my own?

No — plugin commands are namespaced as plugin-name:command, so a plugin’s /review command never overwrites a project’s own /review command.

Where should I store commands I want the whole team to use?

In .claude/skills/ or .claude/commands/ inside the project, then commit them to git — anyone who clones the repository gets the same commands immediately.

Exit mobile version