Built-in Slash Commands
Claude Code includes several built-in slash commands: /help for documentation, /clear for clearing context, /compact for summarizing conversation, /config for managing settings, /cost for viewing token usage, /doctor for diagnosing issues, /init for initializing CLAUDE.md, /review for code review, and /memory for managing CLAUDE.md.
The /compact command is particularly important for long sessions — it summarizes the conversation to reduce context usage while preserving important information.
Custom Slash Commands
Custom slash commands are defined by creating markdown files in the .claude/commands/ directory. Each file becomes a slash command with the filename as the command name. The file content becomes the prompt template, with $ARGUMENTS replaced by user input.
For example, .claude/commands/review-pr.md might contain a prompt template for reviewing pull requests. When a user types /review-pr #123, the $ARGUMENTS placeholder is replaced with '#123' and the template is sent to Claude.
MCP in Claude Code
MCP servers are configured in Claude Code through the .claude/mcp.json file or via the /mcp command. Configured servers provide additional tools that Claude Code can use alongside its built-in tools.
MCP servers can be project-specific (in .claude/mcp.json) or global (in ~/.claude/mcp.json). Project-specific servers are shared with the team through version control. Global servers are personal and available across all projects.
Key Concept
Commands Are Prompt Templates, Not Code
Custom slash commands in Claude Code are markdown prompt templates, not code. They define what to ask Claude, not how to implement it. The $ARGUMENTS placeholder lets users provide input, and the template shapes Claude's behavior for that specific task. This is a prompt engineering pattern, not a programming pattern.
Exam Traps
Confusing slash commands with CLI commands
Slash commands are interactive commands within Claude Code. CLI flags (like --allowedTools) are used when launching Claude Code. The exam may test whether you know the difference.
Not knowing about /compact
The /compact command is critical for managing long sessions. It summarizes the conversation to reduce context usage. The exam may present scenarios where context management is needed.
Forgetting that custom commands are just prompt templates
Custom commands don't execute code — they send prompt templates to Claude. The exam tests whether you understand this distinction.
Check Your Understanding
A team wants all developers to have a standardized code review workflow in Claude Code. The review should check for security issues, performance problems, and adherence to the team style guide. How should this be implemented?
Build Exercise
Create Custom Slash Commands
What you'll learn
- Create custom slash commands with prompt templates
- Use the $ARGUMENTS placeholder
- Configure MCP servers in Claude Code
- Use built-in slash commands effectively
Create a .claude/commands/ directory and add a review.md file with a code review prompt template. Use $ARGUMENTS for the target file or PR.
WHY: Custom commands standardize common workflows across the team.
YOU SHOULD SEE: A /review command available in Claude Code that accepts a file path.
Create a second custom command for generating test cases. The template should instruct Claude to analyze a file and generate comprehensive tests.
WHY: Multiple commands create a library of standardized workflows.
YOU SHOULD SEE: A /generate-tests command that creates test files for specified source files.
Use the /compact command during a long conversation and observe how it affects context usage.
WHY: Understanding /compact is essential for managing long Claude Code sessions.
YOU SHOULD SEE: Reduced context usage with preserved conversation intent after compaction.
Configure an MCP server in .claude/mcp.json and verify its tools are available in Claude Code.
WHY: MCP integration extends Claude Code's capabilities with custom tools.
YOU SHOULD SEE: MCP tools appearing alongside built-in tools in Claude Code.
Sources
- Claude Code Commands— Anthropic Documentation
- Claude Code MCP Integration— Anthropic Documentation