Slash Commands: A Deep Dive

Beginner-Friendly Teaching Edition  ·  Claude Code's hidden levers
What you will learn
The slash commands (typed with a leading /) that go far beyond /help and /clear: context management, safety nets, efficiency and cost control, project memory, code quality, and advanced operations — plus how to combine them into workflow patterns.
ContextSafety netsEfficiencyMemoryQualityCombos

The Big Idea

Most people use Claude Code with two things: typing requests directly, and occasionally running /help. The book's analogy: "like buying a car and only ever driving straight — never discovering reverse, cruise control, or lane assist."

Easy way to remember:
Slash commands are not a feature list — they are workflow infrastructure. Combined into patterns, they change your efficiency qualitatively, the way add + commit + push together form version control.

Why This Topic Matters

  • The context window is finite; a multi-hour session pushes against the limit. How well you manage context decides whether you can finish complex tasks.
  • Mistakes are not fatal if you know the rollback commands — you can work faster and more boldly.
  • Without /cost and /model, you have no sense of what a session costs or how to spend less.

Category 1 — Context Management

/compact — smart compression, not deletion

Compresses conversation history into a distilled summary, freeing context space. The key word is smart: it uses AI to summarise — keeping key decisions, code-change records, and your stated preferences, discarding only redundant intermediate steps.

When to use it:

  • After 20+ rounds — every exchange resends the full history, so the longer it gets, the more tokens you burn.
  • When shifting task direction — Feature A → Feature B: compact away the A-specific noise.
  • When Claude feels slower — longer context means slower responses; compacting speeds it up.

Advanced usage — tell it what to keep:

/compact Keep all architecture decisions and bug fix records; compress away the detailed code
Remember: don't wait until context is full. Compact after each milestone — finish requirements → compact → code → compact → test. Each phase starts with plenty of context space.

/context — see where your tokens are going

Shows a detailed breakdown of the current context: system prompts, CLAUDE.md, Skills, and conversation history. Its value is visibility — when you suspect the context is nearly full, run it first to see what is consuming space (a large CLAUDE.md, too many MCP tools, or an overgrown history). You need the data to make the right call.

/clear — a clean slate

Wipes the entire conversation history and returns to the initial state — equivalent to closing and reopening claude, just faster. Recommendation: before an unrelated new task, always /clear first. Chaining Feature A and Feature B in one session leaves A's context taking up space; /clear is free and the tokens it saves are real.

Category 2 — Safety Nets

/rewind — surgical-precision rollback

Press Esc twice or type /rewind. Three options:

OptionWhat it does
Rewind conversationUndo the last few exchanges and restart from a specific point
Rewind codeKeep the conversation, but restore files to their previous state
Rewind everythingRoll back both conversation and code together

"Rewind code but keep conversation" is the most powerful. If Claude modified 10 files and the direction was wrong, restore the files but keep the discussion. You can then say: "That approach didn't work. Let's try a different angle; this time only touch the 3 core files." Claude still knows what you discussed and why the first attempt failed, so the second attempt is usually much better.

/fork — parallel-universe exploration

Branches the current conversation into a new independent thread. Both branches share the prior history but develop independently from that point.

You: Help me design a user authentication system
Claude: Option A is JWT stateless authentication...
You: /fork
(New branch begins)
You: Let's set aside the JWT approach. What about Session + Redis?
Claude: Option B is session-based authentication...
(Both branches run in parallel; compare and pick the better fit)

There is no cost to "going down the wrong path" — explore multiple directions at once and choose the best at the end.

Category 3 — Efficiency Tools

/cost — how much have you spent

Shows token consumption and approximate cost for the current session. The book says it "changed how I use Claude Code": a long session might run $2–5, a large refactor $10+. The point is not to be frugal — it is to consciously decide whether a task is worth that many tokens. Check it before a large task, when a conversation feels too long, and at the end of the day.

/model — switch models on the fly

/model sonnet   <- everyday tasks (fast and cheap)
/model opus     <- complex architecture decisions, large-scale refactoring

Sonnet costs roughly 1/5 of Opus, and for most coding — CRUD, simple bug fixes, boilerplate — it is more than sufficient. Switch to Opus only for problems requiring deep reasoning.

/fast — toggle fast mode

Uses the same model but produces output more quickly. If you don't need deep thinking and just want a well-defined task done fast, fast mode gives a noticeable speed boost.

/btw — a side question without breaking the flow

(Claude is refactoring your code...)
/btw What's the difference between readonly and const in TypeScript?
(Claude answers quickly, then continues refactoring)

Key detail: /btw responses don't enter the conversation history. They are one-time — they don't pollute context or consume extra tokens. Perfect for sudden small questions mid-task.

Category 4 — Project Management / Memory

CommandWhat it does
/initScans the project (package.json, README, code structure) and auto-generates an initial CLAUDE.md. A starting point, not a finished product — layer in your own rules.
/memoryLists all memory files currently loaded: project CLAUDE.md, user ~/.claude/CLAUDE.md, and the auto-generated CLAUDE.local.md (Claude's own notebook of build commands, debugging patterns, architecture decisions). Check it periodically — sometimes what it recorded is wrong or outdated and needs manual correction.
/permissionsManages permissions — pre-authorize operations (e.g. allow npm test) or restrict others (e.g. prohibit file deletion). Beginners: start with defaults (every action prompts), open up gradually for high-frequency operations.

Category 5 — Code Quality

/review — automated code review

After a set of changes, type /review and Claude audits all uncommitted modifications and suggests improvements — "a 24/7 code reviewer on call." It checks for:

  • Potential bugs (null checks, boundary conditions)
  • Performance issues (unnecessary loops, large data-set operations)
  • Security problems (SQL injection, XSS, hardcoded secrets)
  • Code style (naming consistency, file organization)

/simplify — three-angle code refinement

Launches three parallel agents that each review your changes from a different angle — reusability, quality, efficiency — then consolidates the findings and auto-applies the fixes. It directly modifies your code; when done, you review the diff and confirm.

Category 6 — Advanced Operations

CommandWhat it does
/doctorDiagnostic checks: CLI up to date? authentication valid? required tools installed? environment variables correct? Run it first when something inexplicable goes wrong — the problem is often the environment, not Claude.
/vimEnables Vim key bindings in the input box (motions like d, c, y, w) — no switching to an editor to modify your prompt.
/terminal-setupConfigures your terminal so Shift+Enter inserts a newline instead of sending. Supports VS Code terminal, iTerm2, Alacritty, Warp, and others.
/exportExports the current session as plain text — useful for documentation, retrospectives, or sharing a conversation with a colleague.

Command Combinations: Workflow Patterns

Pattern 1 — Long Session Management

1. /clear          <- clean starting point
2. Complete Phase 1
3. /compact        <- compress Phase 1 details
4. Complete Phase 2
5. /compact        <- compress again
6. Complete Phase 3
7. /cost           <- check total consumption

Extends a 30–60 minute session into several hours while keeping Claude's understanding of the project intact.

Pattern 2 — Exploratory Development

1. Discuss requirements, align on direction
2. /fork           <- Branch A: Approach One
3. (Implement Approach One in Branch A)
4. Return to original branch
5. /fork           <- Branch B: Approach Two
6. (Implement Approach Two in Branch B)
7. Compare both results, choose the better one

Pattern 3 — Safe Refactoring

1. /review         <- audit current code state first
2. Have Claude begin refactoring
3. If direction is wrong -> press Esc twice -> /rewind to roll back code
4. Refactoring complete -> /simplify  <- three-angle refinement
5. /review         <- final audit
6. git commit

Pattern 4 — Economy Mode

1. /model sonnet   <- cheaper model for everyday tasks
2. Hit a complex problem -> /model opus  <- switch to the stronger model
3. Problem solved -> /model sonnet  <- switch back
4. /cost           <- see how much you saved

Visual Mental Model: Commands as Systems

CONTEXT MANAGEMENT      /compact  +  /context  +  /clear
SAFE EXPLORATION        /fork     +  /rewind
COST CONTROL            /cost     +  /model    (+ /fast)
PROJECT MEMORY          /init     +  /memory   +  /permissions
CODE QUALITY            /review   +  /simplify
HEALTH / SETUP          /doctor   +  /terminal-setup  +  /vim  +  /export

Important Comparisons

/compact/clear
What survivesAn AI summary: key decisions, code changes, your preferencesNothing — full reset
Use whenSame task continuing, but history is longStarting an unrelated task
/fork/rewind
PurposeExplore multiple approaches from one point, in parallelUndo — roll back conversation, code, or both
Prior historyShared by both branchesRestored to an earlier state
/review/simplify
OutputSuggestions onlyThree parallel agents (reuse / quality / efficiency) that auto-apply fixes
Changes your code?NoYes — you then review the diff
/btwA normal question
Enters history?No — one-timeYes
Effect on the current taskClaude answers, then resumes where it left offBecomes part of the ongoing thread

Common Beginner Mistakes

  • Only ever using /help and /clear — ignoring the rest.
  • Waiting until context is full to /compact, instead of compacting per milestone.
  • Chaining unrelated tasks in one session without /clear.
  • Guessing what's eating context instead of running /context.
  • Fearing wrong turns instead of using /fork to explore freely.
  • Never checking /cost, so a task's price is invisible.
  • Running everything on Opus when Sonnet handles most coding at ~1/5 the cost.
  • Interrupting a working Claude with a side question instead of /btw.
  • Trusting /init's output as final rather than a starting point.
  • Debugging Claude when /doctor would show an environment problem.

Best Practices

  • Compact per milestone; pass instructions to /compact about what to keep.
  • /clear before every unrelated task — it's free.
  • Run /context before assuming what's full.
  • Use /fork to compare approaches instead of committing early.
  • Prefer "rewind code, keep conversation" so Claude remembers why attempt one failed.
  • Check /cost before big tasks, on long sessions, and end of day.
  • Default to Sonnet, switch to Opus only for deep reasoning, then switch back.
  • Use /btw for stray questions.
  • /init then edit; audit /memory periodically.
  • Beginners: default permissions, open up high-frequency ops over time.
  • /review before and after a refactor; /simplify to apply fixes.
  • /doctor first when something inexplicable breaks.
  • Combine commands into the four workflow patterns.

Interview / Revision Questions

  1. Why is /compact called "smart" compression? What does it keep and drop?
  2. When should you /compact, and why not wait until context is full?
  3. What does /context show, and why is that valuable?
  4. What are the three /rewind options, and why is "rewind code, keep conversation" the strongest?
  5. What does /fork do, and what does "no cost to a wrong path" mean?
  6. Why did checking /cost change how the author works?
  7. When should you use /model opus versus /model sonnet, and what is the cost ratio?
  8. What is special about /btw responses?
  9. What does /init generate, and why is it "not a finished product"?
  10. What three files does /memory list, and what is CLAUDE.local.md?
  11. How does /simplify differ from /review?
  12. Describe the Safe Refactoring pattern step by step.

Practice Exercises

Exercise 1: In a long session, run /context, then /compact with an instruction about what to keep, then /context again and compare.
Exercise 2: Practise "rewind code, keep conversation": make a change you dislike, roll back the files only, and redirect Claude.
Exercise 3: Use /fork to explore two designs for the same feature, then compare and choose.
Exercise 4: Run /cost before and after a medium task; note the number.
Exercise 5: Do a task on /model sonnet, switch to opus for one hard part, switch back, and check /cost.
Exercise 6: Run the Safe Refactoring pattern end to end: /review → refactor → /simplify/review → commit.

Quick Memory Map

Slash Commands: A Deep Dive
│
├── Context          /compact (smart, per-milestone, can be instructed)
│                     /context (what's eating space)  /clear (full reset)
├── Safety nets      /rewind (conversation | code | both; "code-only" is best)
│                     /fork (parallel approaches, no cost to wrong paths)
├── Efficiency       /cost (know the price)  /model sonnet<->opus (~1/5 cost)
│                     /fast (same model, faster)  /btw (one-time, no history)
├── Memory           /init (draft CLAUDE.md)  /memory (audit files)
│                     /permissions (pre-authorize / restrict)
├── Quality          /review (suggestions)  /simplify (3 agents, auto-apply)
├── Advanced         /doctor  /vim  /terminal-setup  /export
│
└── Patterns
    1 Long session:  /clear -> phase -> /compact -> ... -> /cost
    2 Exploratory:   discuss -> /fork A -> /fork B -> compare
    3 Safe refactor: /review -> refactor -> (/rewind) -> /simplify -> /review -> commit
    4 Economy:       /model sonnet -> /model opus (hard bit) -> sonnet -> /cost

Complete Chapter Revision

  1. Slash commands are workflow infrastructure, not a feature list.
  2. Context: /compact (smart summary, per milestone, instructable), /context (visibility), /clear (full reset before unrelated tasks).
  3. Safety: /rewind rolls back conversation, code, or both — "code-only, keep conversation" is the most powerful; /fork explores multiple approaches in parallel at no cost.
  4. Efficiency: /cost makes price visible; /model switches Sonnet↔Opus (~1/5 cost); /fast speeds the same model; /btw answers stray questions without touching history.
  5. Memory: /init drafts a CLAUDE.md; /memory audits loaded memory files including CLAUDE.local.md; /permissions pre-authorizes or restricts operations.
  6. Quality: /review gives suggestions; /simplify runs three agents (reuse / quality / efficiency) and auto-applies fixes.
  7. Advanced: /doctor, /vim, /terminal-setup, /export.
  8. Four validated patterns: Long Session Management, Exploratory Development, Safe Refactoring, Economy Mode.
  9. Combos form systems: /compact+/context+/clear = context management; /fork+/rewind = safe exploration; /cost+/model = cost control.

Final Takeaway

The chapter's central lesson:

Each slash command looks small alone, but combined into workflow patterns they change your efficiency qualitatively — the same way add, commit, and push together form an entire version-control system. Learn the combos, not just the list.

This teaching edition is based on the supplied April 2026, 2nd edition of Claude Code: The Complete Guide (§14, "Slash Commands: A Deep Dive"). Command names, behaviours, model pricing ratios and terminal support reflect that edition and may change over time.