Skip to content
Back to Blog
Agentic AI6 min read

Claude Code Slash Commands: The Complete Reference Guide

Every Claude Code slash command explained with usage examples — from /compact for context management to /review for code reviews and /init for project setup.

Understanding Slash Commands

Slash commands are built-in operations in Claude Code that you invoke by typing a forward slash followed by the command name. They control Claude Code's behavior, manage your session, and trigger specialized workflows. Unlike natural language prompts, slash commands execute specific predefined actions.

You can type /help at any point to see the full list of available commands in your current version.

Session Management Commands

/compact

Purpose: Compress the conversation context to free up token space.

Claude Code operates within a context window (200K tokens for Claude Opus 4.6). As conversations grow — especially when reading many files or making numerous edits — you approach this limit. The /compact command summarizes the conversation history, preserving key decisions and context while discarding verbatim tool outputs.

/compact

When to use it:

  • After completing a major task before starting another
  • When Claude Code warns about approaching context limits
  • After extensive file reading or debugging sessions
  • Before starting a new feature in the same session

Best practice: Use /compact proactively. Do not wait until you hit the limit. A good rhythm is to compact after every 2-3 completed tasks.

You can also provide a custom summary prompt:

/compact Focus on the database schema changes and API endpoint patterns we established

This tells Claude Code what to prioritize in the compressed context.

/clear

Purpose: Reset the conversation completely.

Unlike /compact, which preserves a summary, /clear starts a fresh conversation with no history. Claude Code will re-read your CLAUDE.md files on the next message.

/clear

When to use it:

  • When switching to a completely unrelated task
  • When the conversation has gone off track and you want a fresh start
  • After finishing a major piece of work

/cost

Purpose: Display current session costs and token usage.

/cost

Output shows:

  • Total input tokens consumed
  • Total output tokens generated
  • Cache read and write tokens
  • Estimated cost in USD
  • Session duration

This is essential for monitoring spend on API-billed plans. For Max subscription users, it helps you understand your usage patterns.

Project Configuration Commands

/init

Purpose: Generate a starter CLAUDE.md file for your project.

/init

Claude Code analyzes your project structure — package.json, requirements.txt, Dockerfiles, directory layout, existing configs — and generates a CLAUDE.md tailored to your stack. The generated file includes:

  • Detected tech stack and frameworks
  • Project structure overview
  • Build and test commands
  • Coding conventions inferred from existing code

Important: Always review and customize the generated CLAUDE.md. Claude Code makes reasonable guesses, but you know your project best.

/permissions

Purpose: View and modify tool permission settings.

/permissions

Shows the current permission configuration:

  • Which tools are allowed without confirmation
  • Which Bash command patterns are auto-approved
  • The current permission mode (default, permissive, or restrictive)

You can also modify permissions interactively through this command.

/model

Purpose: Switch between Claude models mid-session.

/model

Displays available models and lets you switch. Common choices:

Model Best For Cost
Claude Opus 4.6 Complex tasks, architecture, debugging Higher
Claude Sonnet 4.6 Routine coding, fast iteration Lower

Switching models mid-session preserves your conversation history. You might start with Sonnet for exploration and switch to Opus for the critical implementation.

Code Quality Commands

/review

Purpose: Request a code review of recent changes.

/review

Claude Code examines your recent git changes (git diff) and provides a structured code review covering:

  • Correctness — Logic errors, edge cases, off-by-one errors
  • Security — SQL injection, XSS, authentication bypasses
  • Performance — N+1 queries, unnecessary allocations, missing indexes
  • Style — Naming conventions, code organization, dead code
  • Testing — Missing test coverage, weak assertions

You can scope the review:

/review Focus on security issues only
/review Check the database query performance
/review Review the error handling patterns

/doctor

Purpose: Diagnose environment and configuration issues.

/doctor

Checks:

  • Authentication status (API key validity)
  • Node.js version compatibility
  • CLAUDE.md file detection and parsing
  • MCP server connectivity
  • Permission configuration
  • Available disk space and memory

Run /doctor first when something seems wrong. It catches most common configuration issues.

Terminal and Display Commands

/terminal-setup

Purpose: Configure terminal integration features.

/terminal-setup

Configures terminal-specific features like:

  • Notification settings (sound, visual)
  • Theme compatibility (dark/light mode adjustments)
  • Terminal-specific key bindings

/help

Purpose: Display all available commands with brief descriptions.

/help

This is your reference when you forget a command name. It shows all slash commands available in your current Claude Code version.

Custom Slash Commands

Beyond built-in commands, Claude Code supports custom slash commands defined in your project. These are Markdown files stored in .claude/commands/:

.claude/
  commands/
    deploy.md
    test-suite.md
    db-migrate.md

Each Markdown file becomes a slash command:

<!-- .claude/commands/deploy.md -->
Run the deployment pipeline:
1. Run all tests: npm test
2. Build the production bundle: npm run build
3. Check for TypeScript errors: npx tsc --noEmit
4. If all pass, create a git tag with the current version from package.json
5. Push the tag to origin

Now you can run:

/deploy

Custom commands let you encode complex, repeatable workflows as simple slash commands that any team member can use.

Custom Command Variables

Custom commands support a $ARGUMENTS placeholder:

<!-- .claude/commands/migrate.md -->
Create a new database migration named "$ARGUMENTS":
1. Generate migration: alembic revision --autogenerate -m "$ARGUMENTS"
2. Review the generated migration file
3. Report any potential issues with the migration

Usage:

/migrate add_status_column_to_orders

Command Workflows: Combining Commands Effectively

Starting a New Session

/clear
# Start fresh with a clean context
# Claude Code re-reads CLAUDE.md automatically

After a Long Feature Implementation

/review
# Review everything you just built
/compact Focus on the feature architecture and API contracts
# Compress before starting the next task

Debugging a Cost Issue

/cost
# Check current spend
/model
# Switch to Sonnet for cheaper exploration
# ... do the work ...
/model
# Switch back to Opus for the final implementation

Setting Up a New Project

/init
# Generate starter CLAUDE.md
# Review and customize it
/doctor
# Verify everything is configured correctly

Slash Commands vs Natural Language

You might wonder when to use slash commands versus just asking in natural language. The rule is straightforward:

  • Use slash commands for session management, configuration, and predefined workflows
  • Use natural language for coding tasks, questions, and project-specific work

For example:

  • To review code: /review (not "please review my code")
  • To implement a feature: "Add pagination to the users endpoint" (not a slash command)
  • To manage context: /compact (not "please summarize our conversation")

Slash commands are faster and more reliable for their specific purposes because they trigger optimized, predefined behavior rather than relying on the model to interpret your intent.

Conclusion

Mastering Claude Code's slash commands makes you significantly more efficient. The most impactful ones for daily use are /compact (context management), /review (code quality), /init (project setup), and /cost (spend monitoring). Combined with custom project commands, they create a powerful, repeatable workflow system that scales across your team.

Share this article
N

NYC News

Expert insights on AI voice agents and customer communication automation.

Try CallSphere AI Voice Agents

See how AI voice agents work for your industry. Live demo available -- no signup required.