Skip to content

Slash Commands Mastery

Slash commands transform Claude Code from a conversational assistant into a powerful automation platform. Master these commands to standardize workflows, eliminate repetitive tasks, and share best practices across your team.

CommandPurposePro Tips
/clearReset conversation contextUse between unrelated tasks to save tokens
/compact [instructions]Compress conversation historyAdd focus instructions: /compact Focus on test results
/costView token usage and costsCheck regularly to optimize spending
/resumeResume previous conversationMaintains full context from earlier sessions
Terminal window
# Example: Compact with specific focus
/compact Keep only code changes and error messages
# Check costs before expensive operations
/cost
Terminal window
# Configure MCP servers
/mcp
# Typical workflow:
# 1. View configured servers
# 2. Check connection status
# 3. Authenticate OAuth servers
# 4. Test available tools
Terminal window
# Install GitHub app for automated reviews
/install-github-app
# View PR comments in current branch
/pr_comments
# This enables @claude mentions in GitHub

Custom commands are Markdown files in specific directories:

  • Directory.claude/
    • Directorycommands/
      • deploy.md (becomes /deploy)
      • test.md (becomes /test)
      • Directoryfrontend/
        • component.md (becomes /frontend:component)
  • Directory~/.claude/
    • Directorycommands/
      • personal-workflow.md (becomes /personal-workflow)
.claude/commands/feature.md
# Create New Feature
Please implement a new feature with the following specifications:
$ARGUMENTS
Requirements:
- Follow our coding standards in CLAUDE.md
- Include comprehensive tests
- Update documentation
- Create or update API endpoints as needed
- Ensure backward compatibility
Steps:
1. Analyze existing code structure
2. Plan the implementation
3. Write tests first (TDD)
4. Implement the feature
5. Update documentation
6. Prepare commit with descriptive message

Usage: /feature User authentication with OAuth

.claude/commands/fix-issue.md
---
allowed-tools: Bash(gh:*), Edit, MultiEdit, WebSearch
description: Fix GitHub issue with full workflow
argument-hint: issue-number
---
## Current Context
- Git status: !`git status --short`
- Current branch: !`git branch --show-current`
- Recent commits: !`git log --oneline -5`
## Task
Fix GitHub issue #$ARGUMENTS by:
1. Fetching issue details with `gh issue view $ARGUMENTS`
2. Understanding the problem and requirements
3. Searching codebase for relevant files
4. Implementing the fix with tests
5. Creating descriptive commit referencing the issue
6. Opening a PR with explanation
## Standards
- All changes must pass: !`cat .github/pre-push-checks.sh`
- Follow patterns in: @docs/coding-standards.md
.claude/commands/analyze-performance.md
---
allowed-tools: Bash(npm:*), Bash(lighthouse:*), WebFetch
description: Analyze and improve performance
---
## Performance Analysis for: $ARGUMENTS
### Current Metrics
!`npm run build -- --stats`
### Bundle Analysis
!`npm run analyze`
### Lighthouse Scores (if URL provided)
!`[[ "$ARGUMENTS" =~ ^https?:// ]] && lighthouse $ARGUMENTS --output=json --quiet | jq '.categories'`
## Your Task
Based on the above metrics:
1. Identify performance bottlenecks
2. Suggest specific optimizations
3. Implement improvements
4. Measure impact
Focus on:
- Bundle size reduction
- Load time optimization
- Runtime performance
- Memory usage
.claude/commands/release.md
---
allowed-tools: Bash(git:*), Bash(npm:*), Edit
description: Automated release workflow
argument-hint: major|minor|patch
---
# Release Workflow - $ARGUMENTS
## Pre-release Checks
- Current version: !`node -p "require('./package.json').version"`
- Uncommitted changes: !`git status --porcelain`
- Current branch: !`git branch --show-current`
- CI status: !`gh run list --limit 1`
## Release Tasks
Please execute the following release workflow:
1. Ensure we're on main branch and up to date
2. Run all tests and ensure they pass
3. Update version using `npm version $ARGUMENTS`
4. Generate changelog from commits since last tag
5. Update CHANGELOG.md with generated content
6. Commit changes
7. Create annotated tag
8. Push changes and tags
9. Create GitHub release with changelog
Abort if any step fails.

Action-Oriented

  • /deploy-staging
  • /run-tests
  • /fix-lint

Resource-Focused

  • /update-database
  • /clean-cache
  • /build-docker

Workflow-Based

  • /morning-routine
  • /pre-commit
  • /post-deploy

Use subdirectories for logical grouping:

  • Directory.claude/commands/
    • Directorytesting/
      • unit.md
      • integration.md
      • e2e.md
    • Directorydeployment/
      • staging.md
      • production.md
      • rollback.md
    • Directorydatabase/
      • migrate.md
      • seed.md
      • backup.md
<!-- Using split pattern -->
# Deploy to $ARGUMENTS
Parse arguments:
- Environment: First word before space
- Version: Everything after first space
Example: /deploy staging v2.1.0
<!-- Handling optional parameters -->
# Build project
Target: ${ARGUMENTS:-production}
This builds for production by default,
or the specified target if provided.

MCP servers can expose their own slash commands:

Terminal window
# Format: /mcp__<server>__<command>
# Examples:
/mcp__github__create_pr
/mcp__database__run_migration
/mcp__browser__take_screenshot
  1. Run /mcp to see connected servers
  2. Check each server’s available prompts
  3. Commands appear in /help when server is active
  4. Use tab completion for discovery

Create commands that call other commands:

.claude/commands/full-test.md
# Comprehensive Test Suite
Please run the following test sequence:
1. First, run unit tests: `/test:unit all`
2. If successful, run integration: `/test:integration`
3. Finally, run E2E tests: `/test:e2e critical`
4. Generate coverage report
Stop if any stage fails.
.claude/commands/smart-fix.md
---
allowed-tools: Bash(git:*), Read, Edit
---
# Intelligent Fix Based on Context
## Determine Issue Type
- Last commit: !`git log -1 --oneline`
- Changed files: !`git diff --name-only HEAD~1`
- CI status: !`[[ -f .github/workflows/ci.yml ]] && echo "CI configured"`
## Apply Appropriate Fix
Based on the context above:
- If test files changed: Run affected tests
- If source files changed: Run tests and lint
- If CI files changed: Validate workflow syntax
- If docs changed: Check markdown and links
$ARGUMENTS

Share commands via version control:

Terminal window
# In your repository
git add .claude/commands/
git commit -m "Add team Claude Code commands"
git push
# Team members automatically get commands
  1. Identify repetitive tasks in your workflow
  2. Create initial command with basic structure
  3. Test and iterate on the command
  4. Add context and checks for robustness
  5. Document and share with your team

Starting with a simple need:

<!-- Version 1: Basic -->
Run our test suite

Evolving to production-ready:

<!-- Version 2: Robust -->
---
allowed-tools: Bash(npm:*), Read
description: Run test suite with smart detection
argument-hint: [specific-test-file] [--watch]
---
# Test Runner
## Environment Check
- Node version: !`node --version`
- Test framework: !`[[ -f jest.config.js ]] && echo "Jest" || echo "Unknown"`
- Previous test results: !`[[ -f coverage/lcov-report/index.html ]] && echo "Coverage available"`
## Run Tests
Target: ${ARGUMENTS:-all tests}
Please:
1. Clear test cache if needed
2. Run tests matching: $ARGUMENTS
3. If failures, analyze and suggest fixes
4. Generate coverage report
5. Highlight any new uncovered code
Use --watch flag if specified in arguments.
  • Preload context in commands with ! bash execution
  • Use file references with @ for consistent context
  • Limit bash output with head, tail, or jq
  • Cache expensive operations in command output

Now that you’ve mastered slash commands:

  1. Implement Hooks for event-driven automation
  2. Optimize Memory Management for large codebases
  3. Share your commands with the Claude Code community