Get AI summaries of any video or article — Sign up free
Slash Commands in Claude Code | CampusX thumbnail

Slash Commands in Claude Code | CampusX

CampusX·
6 min read

Based on CampusX's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Slash commands are typed shortcuts inside Claude Code sessions that trigger predefined workflows without writing full prompts repeatedly.

Briefing

Slash commands in Claude Code are fast shortcuts typed inside a working session that trigger predefined actions and workflows—often without writing a full prompt. The practical payoff is less repetition: instead of re-explaining the same intent every time, developers can invoke reusable patterns with a short command, making Claude Code feel more like a programming assistant that supports repeatable development flows.

Claude Code supports two kinds of slash commands. Built-in commands ship with the tool and appear by default after installation. Custom slash commands can be created by users to match recurring project-specific workflows—useful when the same requirement keeps repeating across a particular kind of work.

A major portion of the walkthrough focuses on session-related commands, because sessions are the unit of work in Claude Code: each session is one conversation, starts when the user enters the Claude keyword in the command prompt, and ends when the user types /exit. Every session carries a unique ID and stores the full message history, including user messages, assistant responses, and tool messages. Sessions are automatically saved and can be resumed later even after closing the terminal.

Resuming is handled through the /resume flow. The user can resume a prior conversation by using Claude with a resume flag (described as “Claude -r”), which lists past conversations with timestamps. There’s also a /resume slash command that jumps between sessions so work can continue in the middle of switching contexts.

To keep projects organized, the walkthrough recommends a disciplined session strategy: plan and solve one task per session (for example, one session per website feature), close the session when that feature is done, and start a new session for the next feature to avoid mixing contexts. It also advises renaming sessions immediately after starting so the AI doesn’t generate unhelpful names based on early questions. The /rename command lets users set a clear label (e.g., “intro session”). When meaningful milestones are reached, frequent commits are encouraged to capture progress.

Beyond sessions, the walkthrough highlights /by the way (BTW) for side questions that shouldn’t pollute the main conversation history. This is positioned as a way to ask quick reference questions (like what Flask templating is in Python) while Claude continues the primary task; the side answer can be removed from the visible history using a space interaction.

For larger refactors, /export is recommended to save important past conversations into a Markdown file inside the project directory, so the content can be re-provided as context during code changes.

The guide also covers account and model management. /logout and login flows support switching between Claude Code accounts (including Anthropic console-based access). Model choice is framed as a cost/quality tradeoff: Opus for complex planning, Sonnet as the default balance, and HQ for fast, cheap repetitive tasks. A /model command enables switching models on demand, while /usage shows token consumption for the current session and weekly limits. If limits are reached, /extra usage supports midstream top-ups.

Finally, the walkthrough introduces analytics and control commands: /stats provides usage statistics, /insights generates a detailed HTML report after enough sessions to identify better usage patterns, and /config allows changing settings like thinking mode, verbosity, progress bar behavior, and language. /permissions governs tool access by allowing, asking, or denying tool usage (including adding rules for tools like web search or bash commands). The session ends with UI customization via /theme and hands-free prompting via /voice, plus a reminder that typing / and scrolling reveals the full command list.

Cornell Notes

Slash commands in Claude Code act as quick, reusable shortcuts typed inside a session, triggering predefined actions and workflows without rewriting full prompts. Sessions are the core work unit: each session is one conversation with a unique ID, saved automatically, and resumable after closing the terminal. Key session commands include /exit to end, /resume (and Claude -r) to continue prior work, /rename to prevent vague AI-generated names, and /export to save important conversation context for later refactoring. For context hygiene, /by the way (BTW) supports side questions that shouldn’t contaminate the main conversation history. Model and usage management commands—/model, /usage, and /extra usage—help balance quality, speed, and token limits while /stats and /insights track and improve how Claude Code is used.

What exactly does a slash command do in Claude Code, and why does it matter for programming workflows?

Slash commands are short shortcuts typed inside a Claude Code session. Starting with “/”, they trigger a predefined action or workflow immediately—typically without writing a full prompt. The workflow benefit is reuse: instead of repeatedly describing the same intent or pattern to the AI, developers can invoke a consistent, repeatable process with a single command, reducing prompt repetition and keeping development faster and more structured.

How do sessions work, and what commands control their lifecycle?

A session is one conversation in Claude Code. It starts when the user enters the Claude keyword in the command prompt and ends when the user types /exit. Each session has a unique ID and stores the full message history (user messages, assistant replies, and tool messages). Sessions are automatically saved and can be resumed later. Resuming can be done via Claude -r (which lists past conversations) or via the /resume slash command to jump between sessions.

Why rename sessions, and how does /rename help?

If a session isn’t renamed, Claude Code may generate a name based on the first questions asked—often not descriptive enough for later reference. The walkthrough recommends renaming immediately so the label matches the feature being built (e.g., login, registration, intro). The /rename command takes the desired name and updates the session label, making it easier to find the right conversation later.

What is /by the way (BTW), and how does it protect the main context?

/by the way (BTW) is for questions whose answers shouldn’t become part of the main conversation history. While Claude Code continues the primary task, BTW lets the user ask a side reference question (example given: what Flask templating is in Python) and receive an answer without polluting the main context. The walkthrough also notes that the BTW question/answer can be removed from visible history by pressing space after reading.

When should /export be used, and what does it produce?

/export is recommended before major refactoring or large code changes. It saves an important past conversation into a Markdown file (example: a file like .md) inside the project directory. During refactoring, that exported file can be used as a source of context so the AI can apply the prior decisions and details while changing code.

How do model choice and token limits interact, and which commands manage that?

Model choice affects speed, quality, and token cost. Opus is the most powerful but expensive, Sonnet is the default balance, and HQ is the fastest and cheapest for simple repetitive tasks. A /model command switches models interactively. The /usage command shows token usage for the current session and weekly limits (with reset timing). If limits are hit, /extra usage supports a midstream top-up so work doesn’t have to wait for reset.

Review Questions

  1. How would you structure a multi-feature project using sessions to avoid context mixing, and which commands support that workflow?
  2. What’s the difference between asking a question in the main session versus using /by the way (BTW), and what problem does BTW prevent?
  3. Describe a practical workflow for planning with one model and implementing with another, including how you would verify token usage during development.

Key Points

  1. 1

    Slash commands are typed shortcuts inside Claude Code sessions that trigger predefined workflows without writing full prompts repeatedly.

  2. 2

    Claude Code sessions store complete message history, are automatically saved, and can be resumed later using Claude -r or /resume.

  3. 3

    Use /exit to end a session, /rename to set meaningful session names immediately, and frequent commits to capture milestones.

  4. 4

    Keep the main context clean with /by the way (BTW) for side reference questions that shouldn’t become part of the primary conversation history.

  5. 5

    Before major refactors, use /export to save important conversations into Markdown files inside the project directory for later context.

  6. 6

    Manage cost and performance by switching models with /model (Opus for complex planning, Sonnet for implementation, HQ for simple repetitive tasks) and monitor limits with /usage.

  7. 7

    Control tool behavior with /permissions by allowing, asking, or denying tool usage (including rules for tools like web search and bash commands).

Highlights

Sessions are resumable units of work: they store full message history under a unique ID and continue even after closing the terminal.
/by the way (BTW) enables side questions that don’t contaminate the main conversation context, while Claude continues the primary task.
A practical model strategy is to plan with Opus and implement with Sonnet, switching via /model when needed.
/permissions can permanently change tool behavior per project (local), per repository (global), or per user (user settings).

Topics

  • Slash Commands
  • Claude Code Sessions
  • Session Resuming
  • Model Switching
  • Token Usage

Mentioned

  • API
  • HQ
  • MCP
  • JSON
  • HTML
  • LLM