Master every Claude Code command with this comprehensive reference. Whether you're a beginner or an advanced user, this guide covers all CLI commands, slash commands, keyboard shortcuts, and flags you need for efficient AI-powered development.
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# Start Claude Code in current directory
claude
# Start with a specific task
claude "fix the login bug"
# Start in a specific directory
claude --cwd /path/to/project
| Command | Description |
|---|
claude | Start interactive mode |
claude --help | Show all available options |
claude --version | Check installed version |
claude config | Open configuration settings |
Slash commands are used inside the Claude Code interactive session. Type / to see all available commands.
| Command | Description |
|---|
/help | Display help and available commands |
/clear | Clear the current conversation context |
/compact | Compact conversation history to save tokens |
/exit or /quit | Exit Claude Code |
/status | Show current session status |
| Command | Description |
|---|
/add <file> | Add a file to the conversation context |
/drop <file> | Remove a file from context |
/files | List all files currently in context |
/diff | Show pending changes |
/undo | Undo the last file change |
| Command | Description |
|---|
/commit | Create a git commit with AI-generated message |
/pr | Create a pull request |
/branch <name> | Create and switch to a new branch |
/status | Show git status |
| Command | Description |
|---|
/chat | Switch to chat-only mode (no file edits) |
/code | Switch to code editing mode |
/plan | Enter planning mode for complex tasks |
| Command | Description |
|---|
/config | Open settings configuration |
/model | Switch between Claude models |
/cost | Show token usage and cost estimate |
/history | View conversation history |
/resume | Resume a previous session |
/checkpoint | Create a checkpoint for rollback |
/rollback | Rollback to a previous checkpoint |
# Interactive mode (default)
claude
# Execute a single command and exit
claude -p "explain this function"
# Pipe mode - read from stdin
echo "fix this code" | claude -p
# Continue from last session
claude --resume
# Resume specific session
claude --resume <session-id>
| Flag | Description |
|---|
--cwd <path> | Set working directory |
--model <model> | Specify Claude model (opus, sonnet, haiku) |
--max-tokens <n> | Set maximum response tokens |
--temperature <n> | Set temperature (0-1) |
--no-git | Disable git integration |
--verbose | Enable verbose output |
--quiet | Minimal output mode |
# JSON output format
claude -p "list all functions" --output-format json
# Markdown output
claude -p "explain the architecture" --output-format markdown
# Stream output (default)
claude -p "write a test" --stream
# No streaming
claude -p "write a test" --no-stream
# Auto-approve all file edits (use with caution)
claude --dangerously-skip-permissions
# Dry run - show what would be done without executing
claude --dry-run
# Sandbox mode - restrict file access
claude --sandbox
| Shortcut | Action |
|---|
Ctrl+C | Cancel current operation |
Ctrl+D | Exit Claude Code |
Ctrl+L | Clear screen |
↑ / ↓ | Navigate command history |
Tab | Autocomplete commands/files |
Esc | Cancel current input |
| Shortcut | Action |
|---|
!<cmd> | Execute bash command directly |
@<file> | Quick add file to context |
#<tag> | Add context tag |
Execute shell commands directly without leaving Claude Code:
# Run any bash command
!ls -la
# Run tests
!npm test
# Git operations
!git status
!git diff
# Build commands
!npm run build
| Command | Description |
|---|
/mcp list | List available MCP servers |
/mcp connect <server> | Connect to an MCP server |
/mcp disconnect | Disconnect from MCP server |
/mcp status | Show MCP connection status |
# Open config in editor
claude config
# Set API key
claude config set api_key <key>
# Set default model
claude config set model sonnet
# Enable/disable features
claude config set auto_commit true
claude config set show_cost true
# View current config
claude config list
# List previous sessions
claude sessions list
# Resume last session
claude --resume
# Resume specific session
claude --resume abc123
# Delete session
claude sessions delete <id>
# Export session
claude sessions export <id> > session.json
# Fix all TypeScript errors
claude -p "fix all TypeScript errors in src/"
# Generate tests for a file
claude -p "write comprehensive tests for src/utils.ts"
# Refactor with specific instructions
claude -p "refactor this class to use dependency injection" --add src/service.ts
# Code review
claude -p "review this PR for security issues" --add $(git diff --name-only main)
# Use in scripts
claude -p "generate changelog from recent commits" --output-format markdown > CHANGELOG.md
# Automated code fixes
claude -p "fix linting errors" --dangerously-skip-permissions
# Generate documentation
claude -p "generate API documentation" --output-format markdown > docs/API.md
# Add multiple files
claude --add "src/**/*.ts" -p "analyze the codebase structure"
# Exclude patterns
claude --exclude "node_modules/**" --exclude "dist/**"
# Work with specific files
claude -p "refactor these components" --add src/components/Header.tsx --add src/components/Footer.tsx
| Variable | Description |
|---|
ANTHROPIC_API_KEY | Your Anthropic API key |
CLAUDE_CODE_MODEL | Default model to use |
CLAUDE_CODE_CONFIG | Path to config file |
CLAUDE_CODE_CACHE | Cache directory path |
NO_COLOR | Disable colored output |
# Check installation
claude --version
# Verify API connection
claude --check-api
# Reset configuration
claude config reset
# Clear cache
claude cache clear
# Debug mode
claude --debug
# Show detailed logs
claude --verbose
| Command | What it does |
|---|
claude | Start interactive session |
/clear | Fresh start, clear context |
/add <file> | Include file in conversation |
!git status | Quick git check |
/commit | AI-assisted commit |
/undo | Revert last change |
Ctrl+C | Stop current operation |
- Use
/clear frequently - Start fresh for new tasks to avoid context pollution
- Leverage
! commands - Execute quick shell commands without breaking flow
- Add files selectively - Only add files relevant to your current task
- Use
--model haiku - For quick, simple tasks to save costs
- Create checkpoints - Before major refactoring operations
Last updated: January 2025. Commands are based on Claude Code version 1.x.