Examples

Essential Slash Commands - Examples

SFEIR Institute

Claude Code's slash commands form a set of essential shortcuts for driving your AI assistant directly from the terminal. This guide offers 12 concrete, copyable examples - from /help to /doctor - ranked by difficulty level, to master each slash command and optimize your daily workflow.

The essential slash commands in Claude Code are the primary mechanism for quick interaction between the developer and the AI agent in the command line. Claude Code (compatible with Node.js 22) offers dozens of native slash commands covering configuration, context management, cost tracking, and diagnostics.

These commands significantly accelerate interaction compared to a traditional graphical interface.

How to use /help to discover all available commands?

Open your terminal and launch Claude Code. The /help command displays the complete list of slash commands with a short description of each. You do not need any additional arguments.

$ claude
> /help

The expected result shows a summary table of all commands, their syntax, and their description. In practice, /help is the first command to run when you start with Claude Code.

The /help command takes no arguments. It directly displays the complete list of available commands. For a complete onboarding, check the installation and first launch tutorial which guides you step by step.

CommandDescriptionArgument Required
/helpDisplays all commandsNo

Key takeaway: /help is your entry point - run it systematically during your first session.

How to initialize a project with /init?

The /init command creates a CLAUDE.md file at the root of your project. This file serves as persistent memory: it contains the conventions, critical paths, and instructions that Claude Code reads at each session.

$ cd my-project
$ claude
> /init

Claude Code analyzes your directory structure, detects configuration files (package.json, tsconfig.json, .eslintrc), and generates a pre-filled CLAUDE.md. A project initialized with /init gets more relevant responses from the first interaction.

Check the generated content and customize it according to your team conventions:

$ cat CLAUDE.md

To dive deeper into customizing this file, check the CLAUDE.md memory system tutorial which details each configurable section.

Generated ElementTypical ContentEditable
Tech stackNode.js, TypeScript, etc.Yes
Code conventionsLinter, formattingYes
Build commandsnpm run build, npm testYes

Key takeaway: run /init once per project, then keep the CLAUDE.md up to date manually.

How to use /clear to reset a conversation?

The /clear command erases the current conversation history without leaving Claude Code. You keep your active session, but the previous context is deleted. This is useful when you change topics or when the context window approaches its limit.

> /clear

In practice, Claude Code frees conversation memory immediately. The Claude Opus 4.6 context window reaches 200,000 tokens. A long conversation exceeding 150,000 tokens slows responses by 15 to 30%.

Use /clear before starting a different task in the same project. To understand the complete slash commands reference, browse the essential slash commands guide.

SituationRecommended Action
Topic change/clear
Conversation > 100,000 tokens/compact first, /clear if insufficient
Starting a new feature/clear

Key takeaway: /clear deletes all context - prefer /compact if you want to keep a summary.

How to optimize context with /compact?

The /compact command compresses the current conversation into a structured summary, then replaces it. You keep key information while reducing context size by 50 to 70%. This is the most strategic command for long sessions.

> /compact

You can also specify a focus to guide the compression:

> /compact focus on the refactoring

This variant asks Claude Code to prioritize refactoring-related elements in the summary. The instruction after /compact is free-form natural language text. Specifically, a 120,000-token context drops to approximately 40,000 tokens after compaction.

For advanced context management strategies, check the context management examples which illustrate real-world cases.

MetricBefore /compactAfter /compact
Tokens used120,00040,000
Response time8 s3 s
Key information100%90%

Key takeaway: launch /compact when your session exceeds 80,000 tokens - you will gain speed without losing the thread.

How to track your spending with /cost?

The /cost command displays the cumulative cost of your current session. In 2026, the Claude Opus 4.6 rate is $15 per million input tokens and $75 per million output tokens. Check your spending regularly to avoid surprises.

> /cost

The result shows the number of tokens consumed (input and output) and the estimated cost in dollars. In practice, a 2-hour intensive development session costs between $0.50 and $3 depending on task complexity.

You can check the slash commands tips to learn how to reduce your costs by optimizing your prompts.

ModelInput Cost (1M tokens)Output Cost (1M tokens)
Claude Opus 4.6$15$75
Claude Sonnet 4.6$3$15
Claude Haiku 4.5$0.80$4

Key takeaway: run /cost after each heavy task to keep control of your API budget.

How to configure Claude Code with /config and /model?

The /config command opens the Claude Code configuration panel. You adjust permissions, theme, notifications, and output preferences. The /model command lets you change models mid-session.

> /config

To switch to a faster and cheaper model:

> /model sonnet

To switch back to the most capable model:

> /model opus

Specifically, switching from Opus to Sonnet divides the cost by 5 while maintaining 85% of quality on standard code tasks. Sonnet 4.6 correctly handles 92% of refactoring tasks under 500 lines.

The quick start guide details the configuration options available from installation.

Key takeaway: switch to Sonnet for simple tasks and reserve Opus for complex architectural problems.

How to manage authentication with /login and /logout?

The /login and /logout commands manage your connection to the Anthropic API. Use /login to authenticate with your API key or via OAuth.

> /login

Claude Code offers two authentication methods:

? Authentication method:
 > API Key (ANTHROPIC_API_KEY)
 > OAuth (browser)

To cleanly disconnect at the end of a shared session:

> /logout

This command revokes the local session token. It does not delete your global API key. If you are working on a shared workstation, always run /logout before leaving.

For hands-on training on all these commands, SFEIR Institute offers the Claude Code one-day training. You will practice each slash command in guided labs, with progressive exercises on a real project.

The slash commands FAQ answers frequently asked questions about authentication and connection errors.

Key takeaway: run /logout systematically on shared or CI/CD environments.

How to use /memory to drive persistent memory?

The /memory command opens and directly edits your project's CLAUDE.md file from the Claude Code session. You add instructions without leaving the terminal.

> /memory

Claude Code opens the CLAUDE.md in interactive editing mode. You can add rules such as:

# Project conventions
- Use ESM imports (no require)
- Tests with Vitest, not Jest
- Commits in English, conventional format

To verify that your rules are properly loaded, launch a related question:

> What test framework should I use?
# Claude responds "Vitest" if memory is correct

You can also use /memory to record architectural decisions. The CLAUDE.md memory system tutorial explains the memory file hierarchy (project, user, organization).

Key takeaway: populate /memory after each team decision so that Claude Code stays aligned with your conventions.

How to correct a Claude Code error?

To undo an action performed by Claude Code, use standard git commands. This is the most reliable way to restore your files.

# Undo changes to a file
> git checkout -- src/auth.ts

# Or ask Claude Code directly
> Undo the changes you just made to auth.ts

In practice, git commands are essential when Claude Code modifies a file incorrectly. You can also use git stash to set aside all current changes.

Check the common slash command errors section to learn about the most common troubleshooting scenarios.

SituationCommandEffect
Wrong file editgit checkout -- Restores the file
Incorrect code generatedRephrase the requestNew attempt
Multiple files to restoregit stash or git checkout.Restores everything

Key takeaway: git commands (git checkout, git stash, git reset) are your safety net for undoing Claude Code's actions.

How to diagnose a problem with /doctor?

The /doctor command runs a series of checks on your Claude Code installation. It tests API connectivity, Node.js version, project configuration, and file system permissions.

> /doctor

The result looks like this:

Node.js v22.0.0 detected
Anthropic API connection OK (latency: 120 ms)
CLAUDE.md file found
Write permissions OK
Git hooks not configured

Each check returns a status (pass or fail) with actionable details. In practice, /doctor detects many problems in under 5 seconds.

If you encounter installation issues, start with the installation tutorial then launch /doctor to validate each step.

Key takeaway: run /doctor whenever unexpected behavior occurs - it is your first diagnostic reflex.

How to combine slash commands for advanced workflows?

For intermediate and advanced developers, combining multiple slash commands creates powerful workflows.

Here is a complete session-start workflow:

$ claude
> /model opus
> /init # First time only
> /memory # Check conventions
> /cost # Spending starting point

For a mid-session workflow when context saturates:

> /cost # Check consumption
> /compact # Compress the context
> /cost # Verify compression effect

Specifically, this 3-command workflow takes under 10 seconds and optimizes your token consumption.

To go further, the AI-Augmented Developer 2-day training covers advanced workflows, Git integration, and cost optimization strategies. If you already master the basics, the AI-Augmented Developer - Advanced one-day training dives deeper into automation techniques and CI/CD pipelines.

Check the Git integration examples to see how slash commands integrate with Git operations.

Key takeaway: combine /cost, /compact, and /cost in a 3-command workflow to keep control of your long sessions.

What are the lesser-known shortcuts and variants of slash commands?

Some slash commands accept optional arguments that modify their behavior. Here are the most useful variants you will encounter in practice:

CommandVariantEffect
/compact/compact focus on the testsPrioritizes test context (free text)
/model/model haikuUltra-fast model
/model/model opusMost capable model

Claude Haiku 4.5 generates a response in under 500 ms on average, versus 2 to 4 seconds for Opus 4.6. For simple code generation tasks (boilerplate, unit tests), Haiku costs 95% less than Opus.

Check the slash commands tips and the complete FAQ to discover other variants.

To dive deeper into your first interactions with Claude Code, the tutorial on your first conversations shows you how to structure your prompts for precise results.

Key takeaway: argument variants turn simple commands into precision tools - explore them one by one.

You will sometimes encounter errors when using slash commands. Here are the most common cases and their immediate resolution.

"Command not found" error:

> /comapct
# Error: Unknown command "/comapct". Did you mean "/compact"?

Claude Code v1.0.x includes an automatic corrector that suggests the closest command. Check the spelling and try again.

Expired session error:

> /cost
# Error: Session expired. Run /login to re-authenticate.
> /login

In practice, sessions expire after 24 hours of inactivity. The common errors guide documents 15 frequent errors with their solution.

ErrorCauseSolution
Unknown commandTypoFix the spelling
Session expiredInactivity > 24 h/login
Context too large> 190,000 tokens/compact or /clear
Model unavailableUnauthorized model/model to an available model

Key takeaway: /doctor then /login resolves 90% of session problems - keep this reflex in mind.

Recent articles about Claude

Claude Code Training

This topic is covered in Module 6 of our Claude Code training

Useful Commands and Tips

1-day training • 60% hands-on labs • Expert instructors

View full program