▸ Official Reference · v2.1.71

Claude Code Cheatsheet

Every command you need — sourced directly from the official docs

Install & Authentication
curl -fsSL https://claude.ai/install.sh | bash Install Claude Code (native binary, recommended)
source ~/.bashrc Reload shell after install
claude --version Verify installation
claude auth login Sign in to your Anthropic account
claude auth logout Log out from your account
claude auth status Show authentication status
claude update Update to latest version
CLI Commands
claude Start interactive session in current directory
claude "explain this project" Start session with an initial prompt
claude -p "your task" Run one-off query then exit (non-interactive)
cat file.txt | claude -p "explain" Process piped content
claude -c Continue most recent conversation
claude --model sonnet Start with a specific model
claude --debug Start with debug logging enabled
Slash Commands (Inside Session)
/help Show help and all available commands
/clear Clear conversation history and free context. Aliases: /reset, /new
/compact [instructions] Compress conversation with optional focus instructions
/cost Show token usage statistics for current session
/context Visualize context window usage as a colored grid
/model [model] Select or switch AI model mid-session
/status Show version, model, account and connectivity
/init Initialize project with CLAUDE.md guide
/doctor Diagnose and verify installation and settings
/memory Edit CLAUDE.md memory files and auto-memory
/permissions View or update tool permissions
/feedback Submit feedback or report a bug. Alias: /bug
/exit Exit Claude Code. Alias: /quit
🧠
Model Selection
/model Open interactive model picker
/model haiku Claude Haiku — fastest & cheapest, simple tasks
/model sonnet recommended Claude Sonnet — best balance of speed and quality
/model opus Claude Opus — most powerful, complex reasoning
Alt+P (Option+P on macOS) Switch model without clearing your current prompt
Keyboard Shortcuts
Ctrl+C Cancel current input or generation
Ctrl+D Exit Claude Code session
Ctrl+L Clear terminal screen (keeps conversation)
Ctrl+R Reverse search through command history
Ctrl+G Open current prompt in your default text editor
Shift+Tab Toggle between Auto-Accept, Plan, and Normal mode
Esc + Esc Rewind conversation to a previous point
\ + Enter Multiline input — works in all terminals
🔤
Quick Input Prefixes
! npm test Bash mode — run shell command directly, output added to conversation
@ filename File path mention — triggers file path autocomplete
/ command Slash command or skill invocation
cat logs.txt | claude -p "explain errors" Pipe any file content directly into Claude
git diff main | claude -p "review for security" Pipe git diff for an instant code review
💻
Working with Code (Natural Language)
Explain what main.py does
Add error handling to main.py
Write unit tests for the get_users function
Find and fix the bug in main.py
Refactor this function to use async/await
Create a new file called auth.py with JWT login
Review all files and summarize the project
🔌
MCP Servers
claude mcp list Show all configured MCP servers
claude mcp add <name> Add a new MCP server
claude mcp remove <name> Remove an MCP server
claude mcp get <name> Show details of a specific server
/mcp Manage MCP connections and OAuth inside session
.mcp.json Project-level MCP config file — place in project root
💡
Pro Tips & Best Practices
/clear Use between unrelated tasks — free reset, zero token cost
/compact Use at logical breakpoints — after research or completing a milestone
/cost Check token spend regularly during long sessions
/init Run this first in any new project to auto-generate CLAUDE.md
Always run claude from inside your project directory Claude reads your files automatically for full context
Use Sonnet by default, Opus only when needed Sonnet handles 80% of tasks at significantly lower cost
Keep active MCP servers under 10 per project Too many MCPs reduce your usable context window
Use CLAUDE.md to give Claude persistent project context Add your stack, conventions, and common commands — loaded every session