
Every Claude code command you need to know with examples
Complete reference guide to all Claude Code slash commands, CLI flags, keyboard shortcuts, and MCP integration with practical examples for developers.
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands. But if you're just typing natural language prompts, you're missing 90% of its power.
The real magic happens when you master claude code commands – the slash commands, CLI flags, and keyboard shortcuts that transform Claude from a helpful assistant into a coding superpower. After diving deep into the documentation and testing every command, here's your complete reference guide.
What are Claude code commands?
Slash commands provide a way to control Claude Code sessions with special commands that start with /. These commands can be sent through the SDK to perform actions like clearing conversation history, compacting messages, or getting help.
Think of them as keyboard shortcuts for your AI coding workflow. Instead of typing "Please clear the conversation history," you type /clear. Instead of explaining what you want Claude to review, you type /review.
But claude code commands go beyond just slash commands. The complete arsenal includes:
- Built-in slash commands - Over 50 commands like
/help,/clear,/compact - CLI flags - Launch options like
--model,--dangerously-skip-permissions - Keyboard shortcuts - Quick navigation and mode switching
- Custom commands - Your own slash commands for repeated tasks
- MCP integration commands - Connect external tools and services
What built-in slash commands should you master first?
Start with these essential commands that every developer needs:
Session Management Commands
The most commonly used slash commands include /clear, /compact, /init, /model, /help, and /cost. The /help command displays a full list of available commands in your current version.
/help - Shows all available commands
> /help
# Displays complete list of built-in and custom commands
/clear - My favorite command /clear is a real token saver. Almost reached the message limit? This command clears the context and gives you a fresh start.
> /clear
# Starts fresh conversation, preserving no history
/compact - The /compact command compresses Claude Code's working memory of a long conversation, summarizing what's been discussed to free up context space. This is essential for extended working sessions where you've built up significant conversation history but aren't ready to clear everything and start fresh.
> /compact
# Compresses conversation history while preserving key context
> /compact retain the error handling patterns
# Compacts while keeping specific information
/init - Sets up project configuration
> /init
# Creates CLAUDE.md and basic project structure
Development Workflow Commands
/review - Code review
> /review
# Reviews recent changes for quality, security, performance
/plan - Added optional description argument to /plan (e.g., /plan fix the auth bug) that enters plan mode and immediately starts
> /plan
# Enters planning mode for complex tasks
> /plan fix the auth bug
# Plans approach to specific problem
/context - View context usage
> /context
# Shows current context window usage and warnings
/cost - Token usage
> /cost
# Displays token consumption and pricing info
Model and Configuration Commands
/model - Switch between Claude models
> /model
# Opens model selection interface
> /model sonnet
# Switches to Claude Sonnet
/permissions - Manage permissions
> /permissions
# Configure tool access and safety settings
/config - Deprecated /output-style command — use /config instead.
> /config
# Opens configuration editor
What CLI flags give you the most control?
Complete reference for Claude Code command-line interface, including commands and flags. Here are the flags that transform how Claude Code behaves:
Essential Launch Flags
claude -c - claude -c (continue) resumes the most recent session in the current directory.
claude -c
# Continue last session in current directory
claude -r session-id
# Resume specific session by ID
claude -p - claude -p "Analyze this code" # One-time query without session
claude -p "Fix all TypeScript errors"
# Single query, exits after completion
Model Selection Flags
--model - To use a different Claude model, you can specify the model string with a flag
claude --model claude-sonnet-4-20250514
# Use specific model version
claude --model opus
# Use Claude Opus for complex reasoning
Permission Control Flags
--dangerously-skip-permissions - The --dangerously-skip-permissions flag lets Claude Code run end-to-end without approvals. This guide covers what the flag does, the difference between Auto-Accept and YOLO mode, safe setup procedures, proven workflows, observability tools, and critical risk considerations.
# ONLY use in isolated environments!
claude --dangerously-skip-permissions "Refactor auth module"
⚠️ Critical Safety Warning: The flag isn't called "dangerously" skip permissions for nothing. Here are the actual risks I've encountered: File Deletion and Modification: The biggest risk is Claude removing or editing files it shouldn't touch. I was working on a development tool that had a config file, and while I was updating the default config creation process, Claude decided to test by putting blank values directly into my existing config file - without creating a backup first.
--allowedTools - Limit available tools
claude --allowedTools "Read,Edit,Grep,Glob" "Analyze codebase"
# Restrict to safe, read-mostly operations
Advanced Workflow Flags
--system-prompt - Claude Code provides four flags for customizing the system prompt. For most use cases, use an append flag. Appending preserves Claude Code's built-in capabilities while adding your requirements. Use a replacement flag only when you need complete control over the system prompt.
claude --append-system-prompt "You are a senior React developer"
# Add context while keeping Claude Code abilities
claude --system-prompt-file ./prompts/backend-expert.md
# Load custom prompt from file
--effort - --effort (low/medium/high/max)
claude --effort high "Optimize database queries"
# Higher effort level for complex tasks
What keyboard shortcuts speed up your workflow?
Keyboard shortcuts make the difference between productive flow and constant looking things up. Here are all available shortcuts for interactive mode.
Essential Shortcuts
Shift+Tab - Each press of Shift+Tab cycles through normal-mode -> auto-accept on -> plan mode on. The current mode is displayed below the prompt.
Shift+Tab: Cycle permission modes
Normal → Auto-accept → Plan mode
Option+T / Alt+T - Option+T / Alt+T for Extended Thinking
Option+T: Toggle extended thinking mode
Shows Claude's reasoning process
Option+P / Alt+P - Option+P / Alt+P for model picker
Option+P: Quick model selection
Switch between Sonnet/Opus/Haiku
Ctrl+C - Cancel
Ctrl+C: Stop current operation
Interrupt Claude mid-task
Navigation Shortcuts
Ctrl+R - Search history
Ctrl+R: Search command history
Find previous prompts/commands
Tab - Toggle thinking
Tab: Toggle thinking display
Show/hide Claude's reasoning
@ - File autocomplete
@src/auth
# File path completion
How do you create custom slash commands?
Custom slash commands allow you to define frequently-used prompts as Markdown files that Claude Code can execute. Commands are organized by scope (project-specific or personal) and support namespacing through directory structures.
Basic Custom Commands
You can also add custom slash commands pretty easily. To add commands, just create a .claude/commands folder, add the command name as a file with a .md extension. You just write these in natural language and you can use the $ARGUMENTS string to place arguments into the prompt.
# Create command directory
mkdir -p .claude/commands
# Create custom review command
cat > .claude/commands/review-pr.md << 'EOF'
---
description: Review pull request for critical issues
argument-hint: [pr-number]
---
Fetch the PR diff for $ARGUMENTS using gh pr diff.
Review for:
- Logic errors
- Security vulnerabilities
- Missing error handling
Do not comment on style or naming.
Produce structured output: Critical / Important / Minor.
EOF
Usage:
> /review-pr 142
# Reviews PR #142 with your custom criteria
Advanced Command Features
Command files support frontmatter, useful for specifying metadata about the command: allowed-tools, argument-hint, description, model
---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
argument-hint: [message]
description: Create a git commit
model: claude-3-5-haiku-20241022
---
Create a git commit with message: $ARGUMENTS
Check status first, add changes, then commit with descriptive message.
Personal vs Project Commands
# Project-specific (current repo only)
.claude/commands/deploy.md
# Personal (available everywhere)
~/.claude/commands/code-review.md
What are Skills and how do they differ from commands?
Skills are the architectural shift. Unlike commands you invoke manually, skills are model-invoked — Claude autonomously uses them based on context.
Skills vs Commands Comparison
Slash Commands: User-invoked (you type /command), simple prompts, single file · Agent Skills: Model-invoked (automatic), complex capabilities, multiple files + scripts
Commands: You type /review → Claude reviews
Skills: You mention "review my code" → Claude automatically uses review skill
Creating Skills
Location: .claude/skills/ for project scope, or ~/.claude/skills/ for personal scope across all projects. Every skill is a directory with a SKILL.md file.
# Create skill directory
mkdir -p .claude/skills/generate-commit-messages
# Create skill definition
cat > .claude/skills/generate-commit-messages/SKILL.md << 'EOF'
---
name: generate-commit-messages
description: Generates clear commit messages from git diffs.
Use when writing commit messages or reviewing staged changes.
---
## Instructions
1. Run `git diff --staged` to see changes
2. Write a commit message: summary under 50 chars, detailed description below
3. Follow conventional commit format when appropriate
EOF
How do you integrate MCP servers for external tools?
MCP servers can expose prompts as slash commands that become available in Claude Code. These commands are dynamically discovered from connected MCP servers.
Adding MCP Servers
claude mcp add <name> <command> [args...]Add MCP server with command
# Add GitHub MCP server
claude mcp add github npx -y @anthropic-ai/mcp-server-github
# Add database MCP server
claude mcp add postgres npx -y @anthropic-ai/mcp-server-postgres
# Add with environment variables
claude mcp add airtable --env AIRTABLE_API_KEY=your-key -- npx -y airtable-mcp-server
Using MCP Commands
MCP commands appear in the format /mcp__<server>__<prompt>
# GitHub MCP commands
> /mcp__github__list_prs
# Lists pull requests
> /mcp__github__pr_review 456
# Reviews PR #456
# Database MCP commands
> /mcp__postgres__query "SELECT * FROM users LIMIT 5"
# Runs database query
What environment variables control Claude Code behavior?
Beyond CLI flags, there are numerous environment variables that let you control Claude Code's behavior. Set them in your shell or in settings.json under the env key.
Key Environment Variables
# Model and performance
export CLAUDE_CODE_EFFORT_LEVEL=medium
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=8192
# Timeouts and limits
export BASH_DEFAULT_TIMEOUT_MS=30000
export CLAUDE_CODE_DISABLE_CRON=1
# Tool and command limits
export SLASH_COMMAND_TOOL_CHAR_BUDGET=32000
# MCP and debugging
export CLAUDE_CODE_DEBUG="api,mcp"
export ENABLE_TOOL_SEARCH=1
Settings.json Configuration
You can set environment variables permanently in your settings.json instead of exporting them in the shell every time, e.g., {"env": {"CLAUDE_CODE_EFFORT_LEVEL": "medium"}}
{
"model": "claude-sonnet-4-20250514",
"maxTokens": 4096,
"env": {
"CLAUDE_CODE_EFFORT_LEVEL": "high",
"BASH_DEFAULT_TIMEOUT_MS": "45000"
},
"permissions": {
"allowedTools": ["Read", "Write", "Bash(git *)"],
"deny": ["Read(./.env)", "Write(./production.config.*)"]
}
}
Which bundled skills come with Claude Code?
Bundled skills ship with Claude Code and are available in every session. Unlike built-in commands, skills are prompt-based: they give Claude a detailed playbook and let it orchestrate the work using its tools. This means skills can spawn parallel agents, read files, and adapt to your codebase.
Available Bundled Skills
/simplify - reviews your recently changed files for code reuse, quality, and efficiency issues, then fixes them. Run it after implementing a feature or bug fix to clean up your work. It spawns three review agents in parallel (code reuse, code quality, efficiency), aggregates their findings, and applies fixes. Pass optional text to focus on specific concerns: /simplify focus on memory efficiency.
> /simplify
# Reviews and improves recent changes
> /simplify focus on performance
# Targeted optimization review
/batch - orchestrates large-scale changes across a codebase in parallel.
> /batch "Update all API calls to use new authentication"
# Applies changes across multiple files simultaneously
Other bundled skills: /loop, /debug, /claude-api - plus 5 bundled skills (/batch, /simplify, /loop, /debug, /claude-api)
How do you set up safe autonomous workflows?
Before even considering YOLO mode, isolation is mandatory. Run Claude Code in a locked-down container or VM, preferably offline. This mitigates risks of data loss, system corruption, or data exfiltration. Anthropic explicitly warns about these dangers and provides example Docker setups specifically for this use case.
Safe Setup for Autonomous Mode
# 1. Initialize git repository (essential for rollback)
git init && git add -A && git commit -m "Pre-Claude checkpoint"
# 2. Create isolated container
docker run -it --rm -v $(pwd):/workspace \
--network none claude-code:latest \
--dangerously-skip-permissions "Implement feature"
# 3. Use tool restrictions
claude --dangerously-skip-permissions \
--disallowedTools "Bash(rm:*),Bash(sudo:*)" \
"Refactor authentication system"
Permission Mode Progression
Press Shift+Tab to cycle through the first three interactively. Prompts on first use of each tool type. Approve file editing once and subsequent edits proceed automatically for that session. Shell commands still prompt individually. This is what you get out of the box. Auto-approves all file modifications but still prompts for shell commands.
- Normal Mode (default) - Prompts for everything
- Auto-accept Files - Auto-approves file edits
- Auto-accept All - Approves files and safe commands
- Plan Mode - Read-only analysis
- Bypass Mode - No prompts (dangerous)
What configuration files should you create?
Essential Configuration Files
.claude/CLAUDE.md - Use CLAUDE.md files to give context and instructions to Claude. They save time + tokens, and are super helpful for info you'd otherwise include in your prompts. These are loaded hierarchically: Global: ~/.claude/CLAUDE.md (applies to all projects)
# Project: Authentication Service
## Tech Stack
- Node.js with TypeScript
- Express.js framework
- PostgreSQL database
- Jest for testing
## Commands
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`
## Conventions
- Use async/await, not promises
- Write tests for all API endpoints
- Follow REST API conventions
.claude/settings.json - Project configuration
{
"model": "claude-sonnet-4-20250514",
"permissions": {
"allowedTools": ["Read", "Write(src/**)", "Bash(git *)", "Bash(npm *)"],
"deny": ["Read(.env*)", "Write(production.config.*)", "Bash(rm *)"]
},
"hooks": {
"PostToolUse": [
{
"matcher": "Write(*.ts)",
"hooks": [{"type": "command", "command": "npm run type-check"}]
}
]
}
}
What are the most powerful command combinations?
Development Workflow Combo
# 1. Start with project setup
> /init
# Creates CLAUDE.md and configuration
# 2. Set context for session
# Use JWT authentication
# Follow TypeScript strict mode
# Write comprehensive tests
# 3. Begin development
Implement user authentication with password reset
# 4. Review and cleanup
> /review
> /simplify
# 5. Check status
> /cost
> /context
Code Review Workflow
# 1. Create custom review command
mkdir -p .claude/commands
cat > .claude/commands/security-review.md << 'EOF'
---
allowed-tools: Read, Grep, Glob
description: Security-focused code review
---
Review recent changes for:
- SQL injection vulnerabilities
- XSS risks
- Authentication bypass
- Input validation issues
- Credential exposure
Focus on security, not style.
EOF
# 2. Use in workflow
> /security-review
> /compact retain security findings
> /export security-review-$(date +%Y%m%d)
Autonomous Debugging Session
# Safe autonomous debugging setup
git add -A && git commit -m "Pre-debug checkpoint"
claude --effort high \
--allowedTools "Read,Grep,Glob,Edit,Bash(npm test)" \
"Debug failing authentication tests and fix root cause"
The key to mastering claude code commands is building them into systematic workflows. Start with the basics (/help, /clear, /review), add custom commands for your repeated tasks, then gradually explore the advanced features like MCP integration and autonomous modes.
Pro tip: use /clear often. Every time you start something new, clear the chat. You don't need all that history eating your tokens, and you definitely don't need Claude running compaction calls to summarize old conversations. Just clear it and move on.
Remember: Claude Code becomes exponentially more powerful when you stop thinking of it as a chat interface and start using it as a programmable development environment. These commands are your API to that environment.