Skip to main content
Claude Code provides a powerful command system that allows you to interact with the AI assistant through natural language or structured commands.

Command Types

Claude Code supports three types of commands:

Built-in Commands

Core commands that ship with Claude Code

Slash Commands

User-defined commands in .claude/commands/

Plugin Commands

Commands provided by installed plugins

Command Execution

Interactive Mode

In interactive mode, commands are executed in the terminal session:
# Start Claude Code
claude

# Execute a command
/help
/model
/commit

Headless Mode

You can execute commands directly from the command line:
# Run a command with a prompt
claude -p "Analyze the codebase structure"

# Resume a previous session
claude --resume

# Start in a specific directory
claude --workdir /path/to/project

Command Structure

Commands are defined using markdown files with YAML frontmatter:
---
description: Brief description of what the command does
allowed-tools: Bash(git:*), Read, Write
---

Command instructions and context for Claude.

You can use:
- $ARGUMENTS for all arguments
- $ARGUMENTS[0] for the first argument
- !\`command\` for inline command execution
The frontmatter controls command permissions and behavior, while the body provides instructions to Claude.

Command Arguments

Commands can accept arguments that are passed to Claude:

Full Arguments

Access all arguments using $ARGUMENTS:
# In your command file
Analyze the following: $ARGUMENTS
# Usage
/analyze src/main.js and src/utils.js
# Claude receives: "Analyze the following: src/main.js and src/utils.js"

Indexed Arguments

Access specific arguments using bracket notation:
# In your command file
Compare $ARGUMENTS[0] with $ARGUMENTS[1]
# Usage
/compare file1.js file2.js
# Claude receives: "Compare file1.js with file2.js"

Inline Command Execution

Commands can execute shell commands inline and include their output:
---
description: Show current git status
allowed-tools: Bash(git:*)
---

## Current Status

Branch: !\`git branch --show-current\`

Changes:
!\`git status --short\`
Inline commands (!`…`) execute immediately when the command is loaded. Use them for gathering context, not for making changes.

Permission Model

Commands can specify which tools Claude is allowed to use:
allowed-tools
string | string[]
List of tools the command can use. Examples:
  • Bash(git:*) - Only git commands
  • Bash(./scripts/gh.sh:*) - Only specific script
  • Read, Write, Edit - File operations
  • Bash - All bash commands (requires user approval)

Tool Permission Syntax

# Allow only specific commands
allowed-tools: Bash(git status:*), Bash(git diff:*)

# Allow a specific script with any arguments
allowed-tools: Bash(./scripts/deploy.sh:*)

# Allow multiple tool types
allowed-tools: Bash(git:*), Read, Write, Grep

# Allow all bash (requires approval)
allowed-tools: Bash

Session ID Variable

Commands can access the current session ID:
---
description: Log current session
---

Session ID: ${CLAUDE_SESSION_ID}

This is useful for:
- Creating session-specific files
- Logging and tracking
- Integration with external tools

Best Practices

Each command should do one thing well. If a command becomes too complex, consider breaking it into multiple commands or using an agent instead.
Command names should clearly indicate what they do. Use kebab-case for multi-word commands: /commit-push-pr instead of /cpp.
Only grant the minimum permissions needed. Use specific command patterns like Bash(git:*) instead of Bash.
When using inline execution (!`…`), add comments explaining what information is being gathered.
Test your commands with various argument combinations to ensure they handle edge cases properly.

Next Steps

Built-in Commands

Explore all built-in commands available in Claude Code

Create Slash Commands

Learn how to create your own custom commands

Build docs developers (and LLMs) love