Skip to content

Slash Commands

Estimated time: ~25 minutes

Prerequisite: Module 4.2 (CLAUDE.md — Project Memory)

Outcome: After this module, you will know every slash command available in Claude Code, when to use each one, and how they fit into efficient workflows — especially context management commands that are critical for long sessions.


You’re 45 minutes into a complex refactoring session. Claude’s responses are getting slower. The context window is full. You need to compress the conversation history to keep working, but what’s the command? Is it /compact? /compress? /summarize? You type /help and realize you’ve been using Claude Code for months but only know 2-3 commands. You’re flying blind through a feature-rich system. Most developers never learn the full command set and waste hours restarting sessions or working with degraded performance. This module gives you the complete picture — every verified slash command, when to use it, and how they fit together into efficient workflows.


Slash commands are built-in commands that start with / and control Claude Code’s behavior during a session. Unlike your regular prompts (which ask Claude to do work), slash commands change the session state, display information, or trigger system-level actions.

Think of them as the control panel for your AI session. Regular prompts are what you want built. Slash commands are how you maintain the building environment.

Claude Code’s slash commands fall into three main categories:

CategoryPurposeCommands
Context ManagementControl conversation history and memory/compact, /clear
InformationInspect session state and costs/help, /cost
Project SetupInitialize project-specific configuration/init

When should you use each command? Here’s the mental model:

graph TD
A[Problem?] --> B{Session feels slow?}
A --> C{Starting new topic?}
A --> D{Want to check spending?}
A --> E{New project setup?}
A --> F{Forgot what commands exist?}
B -->|Yes| G[/compact]
C -->|Yes, unrelated to current work| H[/clear]
D -->|Yes| I[/cost]
E -->|Yes| J[/init]
F -->|Yes| K[/help]
G --> L[Continue working with freed context]
H --> M[Fresh start, all context erased]
I --> N[Review usage, decide if need /compact]
J --> O[CLAUDE.md created, configure project]
K --> P[See all available commands]

The /compact command is your most critical tool for long sessions. Here’s how it works:

What it does:

  • Summarizes the conversation history up to this point
  • Compresses verbose exchanges into concise summaries
  • Frees up context window space for new work
  • Preserves key decisions, architectural choices, and important code snippets

When to use it:

  • Every 30-40 minutes in active sessions
  • Before starting a new sub-task within the same project
  • When you notice responses becoming less precise or slower
  • When /cost shows you’re approaching token limits

What it preserves vs. summarizes:

  • ✅ Preserves: Recent decisions, active file contents, key architectural choices
  • 📝 Summarizes: Step-by-step implementation details, verbose explanations, redundant exchanges
  • ⚠️ May lose: Exact wording of earlier code snippets, nuanced reasoning from early in session

Pro tip: /compact is not destructive — it’s more like “save and compress” than “delete”. Use it liberally. The only downside is losing some verbatim detail from earlier exchanges.

⚠️ Needs verification — Claude Code may support custom slash commands defined in CLAUDE.md or through configuration files. Test in your environment before relying on this feature.


Let’s walk through a realistic long coding session using every verified slash command.

Scenario: You’re building a new REST API service. This is your first time working on this project, and you expect the session to run 60+ minutes.


Step 1: Start session and check available commands

Terminal window
$ claude

You’re in the session. First, see what’s available:

/help

Expected output:

Available commands:
/help - Show this help message
/compact - Compress conversation history to free context space
/clear - Clear all conversation history and start fresh
/cost - Show token usage and estimated cost for this session
/init - Initialize CLAUDE.md for current project
Type a command or describe what you want to build.

Why this matters: You now have a reference. Bookmark this mentally — /help is your lifeline when you forget syntax.


Step 2: Initialize project configuration

You’re starting fresh on a new project. Set up project memory:

/init

Expected output:

Creating CLAUDE.md in current directory...
I've created a starter CLAUDE.md file. Let me open it so we can configure
it for your project.
[CLAUDE.md opens with template content]
What kind of project is this? I'll help you customize the configuration.

Why this matters: You’re setting up project-specific context early. Claude will now remember your stack, conventions, and constraints across sessions.


Step 3: Work for 20 minutes, then check token usage

You’ve implemented the first two API endpoints. Time to check cost:

/cost

Expected output:

Session Token Usage:
Input tokens: 12,847
Output tokens: 8,392
Total tokens: 21,239
Estimated cost: $0.18
Context window: ~21% full
💡 Tip: Context is healthy. Continue working normally.

Why this matters: You now know your burn rate. You’re fine to continue without compacting yet.


Step 4: Work another 20 minutes, quality feels degraded — compress context

You’re 40 minutes in. Responses feel slightly less precise. Check cost again, then compact:

/cost

Expected output:

Session Token Usage:
Input tokens: 38,291
Output tokens: 24,103
Total tokens: 62,394
Estimated cost: $0.52
Context window: ~62% full
⚠️ Consider using /compact to free context space.

Now compact:

/compact

Expected output:

Compacting conversation history...
✓ Compressed 62,394 tokens → 18,203 tokens (71% reduction)
✓ Preserved:
- Current CLAUDE.md configuration
- API endpoint implementations (users, products)
- Database schema decisions
- Error handling patterns
You can continue working. Context window freed.

Why this matters: You just got ~44k tokens back. You can work another 30-40 minutes before needing to compact again.


Step 5: Finish API work, switch to completely different task — clear context

The API is done. Now you need to work on a React dashboard (totally different codebase). Clear everything:

/clear

Expected output:

Are you sure you want to clear all conversation history? This cannot be undone.
Type 'yes' to confirm, or anything else to cancel.
yes

Expected output:

✓ Conversation history cleared.
✓ Context window reset.
Starting fresh. What would you like to work on?

Why this matters: You’ve completely reset. No API context will bleed into your dashboard work. Clean mental slate for both you and Claude.


Goal: Experience the full lifecycle of context management in a long session.

Instructions:

  1. Start a new Claude session
  2. Pick a meaty task (multi-file refactoring, new feature, bug investigation)
  3. Work for 10 minutes, then run /cost — note the token count
  4. Work another 10 minutes, run /cost again — observe growth rate
  5. Continue working until /cost warns you or responses feel slower
  6. Run /compact and note the token reduction
  7. Continue working for another 20 minutes
  8. Run /cost one final time — compare to pre-compact numbers

Expected result:

  • You should see token reduction of 60-80% after /compact
  • Responses should feel crisper after compacting
  • You should develop an intuition for when compaction is needed (the “sluggish” feeling)
💡 Hint

Most developers wait too long to compact. If you’re doing complex work, compact every 30 minutes even if responses still feel OK — it’s preventative maintenance.

✅ Solution

There’s no single “correct” answer here — the goal is to internalize the rhythm. But here’s a typical pattern:

  • 0-10 min: ~8k tokens
  • 10-20 min: ~18k tokens (growth rate high, lots of code generation)
  • 20-30 min: ~32k tokens (context warning threshold on some models)
  • After /compact: ~12k tokens (preserves recent work, summarizes early exploration)
  • 30-50 min post-compact: ~28k tokens
  • Key insight: Without compacting, you’d have hit limits around 35 minutes. With compacting, you can work 60+ minutes continuously.

Goal: Understand the difference between /compact (summarize) and /clear (reset).

Instructions:

  1. Start a session, implement a small feature (e.g., validation function)
  2. Run /compact
  3. Ask Claude “What did we just build?” — note the response
  4. Now run /clear and confirm
  5. Ask Claude “What did we just build?” again

Expected result:

  • After /compact: Claude remembers the validation function (summarized)
  • After /clear: Claude has no idea, context fully reset
💡 Hint

Use /compact when switching sub-tasks within the same project. Use /clear only when switching to a completely unrelated project or when you want to eliminate all prior context (rare).

✅ Solution

After /compact:

You: What did we just build?
Claude: We implemented an email validation function with regex pattern matching,
custom error messages, and edge case handling for plus-addressing and
internationalized domains.

After /clear:

You: What did we just build?
Claude: I don't have any context about what we built previously. The conversation
history was cleared. What would you like to work on?

This demonstrates that /compact is lossy summarization, while /clear is total amnesia.


CommandWhat It DoesWhen to UseExample
/helpList all available slash commandsWhen you forget syntax or want to see what’s availableStart of session, when stuck
/compactCompress conversation history, free context spaceEvery 30-40 min, before new sub-task, when responses degrade/compact → continue working
/clearErase ALL conversation history, start freshSwitching to unrelated project, eliminating context bleed/clearyes → new task
/costShow token usage and estimated costEvery 20-30 min to track spending, before compactingCheck → decide if need /compact
/initInitialize CLAUDE.md for projectFirst time working on a new project/init → configure stack/rules

These may exist but are not confirmed. Test in your environment:

CommandPossible FunctionVerification Needed
/modelSwitch between Claude models (Haiku/Sonnet/Opus)⚠️ Verify syntax and availability
/statusShow current session state, active files⚠️ May not exist
/configModify session configuration⚠️ May be handled by CLAUDE.md only
/undoRevert last action⚠️ Verify if supported
/diffShow changes made in session⚠️ May be git-specific
/reviewRequest code review⚠️ May be prompt-based, not command

Combine commands for powerful workflows:

ComboWorkflowUse Case
/cost/compactCheck token usage, then compress if neededPreventative maintenance every 30 min
/clear/init → workFull reset, configure new project, start freshSwitching projects mid-day
/compact → continue → /costCompact, work more, verify token reductionLong sessions (60+ min)
/help → try command → /costLearn new command, test it, check impactExperimentation mode

❌ Mistake✅ Correct Approach
Using /clear when you meant /compact — losing all context when you just needed compressionUse /clear ONLY for unrelated new projects. Use /compact for same-project sub-tasks.
Never compacting until context is 100% full and responses are slowCompact proactively every 30-40 min. It’s free, fast, and prevents degradation.
Never checking /cost until the end of sessionRun /cost every 20-30 min. Develop intuition for token burn rate. Catch expensive patterns early.
Assuming /compact keeps verbatim code from 30 minutes ago/compact summarizes. If you need exact code, save it to a file or CLAUDE.md before compacting.
Using /clear for every sub-task (e.g., after implementing each function)/clear destroys context. Only use it when switching to a COMPLETELY different project. For sub-tasks, just continue or use /compact.
Ignoring /init for new projects, then wondering why Claude forgets your stack across sessionsAlways /init on new projects. CLAUDE.md is persistent memory. Slash commands are session memory.

Scenario: A senior backend engineer at a Vietnamese fintech startup was refactoring a payment microservice — 8 hours of work touching 30+ files across authentication, transaction processing, and reconciliation logic.

Problem: Before learning slash commands, his workflow was brutal: work for 45 minutes, notice degraded responses, restart Claude entirely, re-explain context for 10 minutes, work another 45 minutes, repeat. Four forced restarts per day. He estimated he lost 90 minutes daily just to context resets.

Solution: After this module, he implemented a slash command discipline:

  • /init at project start (CLAUDE.md captured service architecture)
  • /cost every 20 minutes (set a timer)
  • /compact every 40 minutes or when /cost showed >50% context usage
  • /clear only when switching to a different service

Result:

  • Zero forced restarts in an 8-hour session
  • Token usage dropped 30% (compacting freed space, no redundant re-explanations)
  • Subjective quality improvement: “Responses stayed sharp all day. The difference between sprinting with rest stops vs. running until you collapse.”

His team now includes slash command discipline in their onboarding docs: “If you’re not using /compact every 30 minutes, you’re doing it wrong.”


Next: Module 4.4: Memory System