Skip to main content

Claude Code Commands Reference

Complete reference guide for Claude Code commands, shortcuts, and usage patterns. Master both slash commands and natural language interactions for maximum productivity.

Essential Slash Commands

Context Management Commands

/compact [instructions]

  • Purpose: Summarize conversation to free context window space
  • Usage: /compact keep only function names and error messages
  • When to use: Before context window fills up
  • Pro tip: Give specific instructions about what to preserve

/clear

  • Purpose: Start a completely fresh conversation
  • Usage: /clear
  • When to use: When you want to reset all context
  • Warning: Loses all conversation history

Model and Configuration Commands

/model [model-name]

  • Purpose: Switch between Claude models mid-session
  • Usage:
    • /model claude-sonnet-4-20250514
    • /model claude-opus-4-20250514
    • /model claude-3-5-haiku-20241022
  • When to use: When you need different model capabilities

/config

  • Purpose: View or modify Claude Code configuration
  • Usage: /config
  • Shows: Current model, settings, allowed tools

Help and Information Commands

/help

  • Purpose: Display available slash commands
  • Usage: /help
  • Returns: List of all available commands with descriptions

/version

  • Purpose: Show Claude Code version information
  • Usage: /version
  • Returns: Current version number and build info

VS Code Integration Commands

IDE Connection Commands

/ide

  • Purpose: Connect Claude Code to VS Code extension
  • Usage: /ide
  • Requirement: VS Code extension must be installed
  • When to use: From external terminal to connect to open VS Code

VS Code Keyboard Shortcuts

Open Claude Code Panel:

  • Mac: Cmd+Esc
  • Windows/Linux: Ctrl+Esc

Insert File Reference:

  • Mac: Cmd+Option+K
  • Windows/Linux: Alt+Ctrl+K

Natural Language Commands

File Operations

Read Files:

read src/components/Button.js
show me the contents of package.json
what's in the README file?

Edit Files:

edit the login function in auth.js
update the CSS to use flexbox
fix the typo in line 23 of main.py

Create Files:

create a new React component called UserProfile
write a Python script to process CSV files
make a new test file for the API endpoints

Code Analysis Commands

Understand Code:

explain what this function does
analyze the database schema
show me how authentication works
what are the main components in this app?

Find Code Patterns:

find all React components
show me functions that use async/await
list all the API endpoints
where is error handling implemented?

Code Quality:

review this code for security issues
check for performance problems
suggest improvements to this function
identify potential bugs in this component

Development Task Commands

Feature Development:

add a dark mode toggle to the header
implement user registration functionality
create a dashboard with charts
add search functionality to the product list

Bug Fixing:

fix the memory leak in the data fetcher
resolve the authentication timeout issue
debug why the tests are failing
fix the responsive design on mobile

Refactoring:

convert this JavaScript to TypeScript
refactor this component to use hooks
optimize this database query
modernize this legacy code

Testing:

write unit tests for the User service
create integration tests for the API
add test coverage for edge cases
mock the database in these tests

Advanced Usage Patterns

Project Setup Commands

Initial Project Analysis:

explain what this repo is about
show me the project structure
what technologies does this project use?
how do I run this application?

Dependencies and Configuration:

what dependencies does this project have?
show me the build configuration
explain the deployment process
what environment variables are needed?

Multi-File Operations

Cross-File Analysis:

how do these components interact?
trace the data flow from API to UI
find all files that import this module
show me the complete user registration flow

Batch Operations:

update all components to use the new theme
add error handling to all API calls
convert all class components to functional components
add TypeScript types to all JavaScript files

Debugging Commands

Error Investigation:

debug this error message: [paste error]
why is this test failing?
trace this performance issue
analyze this stack trace

Code Inspection:

check for race conditions in this async code
validate the SQL queries for injection risks
review the authentication flow for security holes
identify bottlenecks in this algorithm

Command Line Arguments

Model Selection

Specify Model at Startup:

claude --model claude-sonnet-4-20250514
claude --model claude-opus-4-20250514
claude --model claude-3-5-haiku-20241022

Directory Management

Multiple Working Directories:

claude --add-dir /path/to/backend
claude --add-dir ../frontend --add-dir ../shared

Permission Management

Skip Permission Prompts:

claude --dangerously-skip-permissions

Note: Use carefully - bypasses security prompts

One-Shot Commands

Quick Queries Without Interactive Session:

claude -p "show me the files in this directory"
claude -p "what kind of project is this?"
claude -p "explain the main.py file"

Context Window Optimization

Efficient Context Usage

Strategic Compacting:

/compact keep only the error messages and function signatures
/compact preserve the main algorithm but remove debug code
/compact focus on the database schema and API endpoints

File Management:

focus on src/components/ directory only
ignore node_modules and build artifacts
work with one feature at a time
break large files into smaller modules

Sub-Agent Commands

Parallel Task Execution:

use sub-agents to research each database table
create separate sub-agents for frontend and backend tasks
delegate the documentation writing to a sub-agent

Best Practices for Commands

Natural Language Tips

Be Specific:

  • ❌ "fix this code"
  • ✅ "fix the memory leak in the WebSocket connection handler"

Provide Context:

  • ❌ "add a button"
  • ✅ "add a logout button to the header navigation component"

Set Scope:

  • ❌ "improve performance"
  • ✅ "optimize the database queries in the user service"

Command Efficiency

Chain Related Tasks:

read the API documentation, then update the client code to match the new endpoint structure
analyze the current authentication system, then implement OAuth integration
review the test coverage, then add missing tests for the payment processing

Use Progressive Disclosure:

1. "show me the project structure"
2. "explain the authentication system"
3. "how does password reset work?"
4. "add two-factor authentication"

Troubleshooting Commands

Diagnostic Commands

System Check:

check my Claude Code configuration
verify my API key is working
test the connection to Anthropic servers
show me my current usage limits

Session Management:

how much context window have I used?
what model am I currently using?
show me the conversation summary
restart with a clean session

Recovery Commands

When Things Go Wrong:

/clear                    # Start completely fresh
/compact # Free up context space
/model claude-sonnet-4 # Switch to different model
exit and restart Claude Code # Nuclear option

Advanced Configuration

Allowed Tools Configuration

Edit ~/.claude.json to configure tool permissions:

{
"allowedTools": [
"bash",
"edit_file",
"read_file",
"create_file"
]
}

Custom Shortcuts

Create aliases for common commands:

# In your shell profile
alias cc="claude"
alias ccs="claude --model claude-sonnet-4-20250514"
alias cco="claude --model claude-opus-4-20250514"

Quick Reference Summary

Most Important Commands

  1. /compact - Manage context window
  2. /clear - Fresh start
  3. /model - Switch models
  4. /help - Show available commands
  5. claude --version - Check version

Essential Natural Language Patterns

  1. "read [file]" - View file contents
  2. "explain [concept]" - Understand code
  3. "fix [problem]" - Debug issues
  4. "add [feature]" - Implement functionality
  5. "test [component]" - Create tests

Key Keyboard Shortcuts

  • VS Code panel: Cmd+Esc (Mac) / Ctrl+Esc (Windows/Linux)
  • File reference: Cmd+Option+K (Mac) / Alt+Ctrl+K (Windows/Linux)

Master these commands to maximize your Claude Code productivity. For more advanced usage, see our Getting Started guide and Configuration documentation.