Cheatsheet
Cheatsheet
Section titled “Cheatsheet”I Want To…
Section titled “I Want To…”| I want to… | Do this |
|---|---|
| Start Claude Code | claude |
| Ask about a specific file | claude "explain src/app.py" |
| Fix a bug | Describe the error + paste the traceback |
| Create a new project | Describe what you want in plain English |
| Ask a one-off question without starting a session | claude -p "what does this regex do: ^[a-z]+$" |
| Resume where I left off | claude --continue |
| Commit my changes | /commit |
| Review code before committing | /review |
| Compress the context to save tokens | /compact |
| See how much I’ve spent this session | /cost |
| Clear the conversation and start fresh | /clear |
| Get help with available commands | /help |
| Run Claude without any interactive prompts | claude --print -p "your task" |
| Use a specific model | claude --model claude-opus-4-5 |
| Limit how many steps Claude can take | claude --max-turns 10 |
Claude Code — CLI Flags
Section titled “Claude Code — CLI Flags”claude # Start interactive sessionclaude -p "prompt" # One-shot, non-interactive (alias: --print)claude --continue # Resume last conversationclaude --model <model> # Specify model (haiku/sonnet/opus or full name)claude --max-turns <n> # Limit agentic turnsclaude --output-format json # Machine-readable JSON outputclaude --output-format text # Plain text output (default)claude --verbose # Show full tool call detailclaude --allowedTools "Bash,Read,Write" # Restrict which tools Claude can useclaude --no-tools # Disable all tools (text only)claude --add-dir /path/to/dir # Add a directory to Claude's contextKeyboard Shortcuts (In-Session)
Section titled “Keyboard Shortcuts (In-Session)”| Shortcut | Action |
|---|---|
Ctrl+C | Cancel current generation |
Ctrl+D | Exit session |
Up arrow | Navigate previous messages |
Shift+Enter | New line in your message (without sending) |
Tab | Autocomplete file paths |
Escape | Cancel current input |
Slash Commands (In-Session)
Section titled “Slash Commands (In-Session)”| Command | What It Does |
|---|---|
/help | Show available commands and current settings |
/status | Session status, model in use, token count |
/cost | Token usage and cost for this session |
/compact | Summarize conversation to free up context window |
/clear | Clear conversation history |
/memory | View and edit CLAUDE.md memory files |
/commit | Stage and commit changes with AI-written message |
/review | Review current changes before committing |
/doctor | Check Claude Code setup for common issues |
/model <name> | Switch model mid-session |
Prompt Patterns
Section titled “Prompt Patterns”One-liners for common tasks — copy, fill in the blanks, send.
Summarize the key points from [document/article] in bullet points.
Review this code for bugs, security issues, and readability. List issues by priority.
You are [role]. [Context]. Task: [what you need]. Format: [how you want it].
Explain [concept] like I understand [adjacent thing] but am new to this area.
I have [problem]. Here's what I've already tried: [attempts]. What should I try next?
Look at [file/folder] and tell me how it works before we make any changes.
Before writing any code, tell me your implementation plan. I'll approve before you start.
This is the output I got: [output]. This is what I expected: [expectation]. What's wrong?Model Comparison
Section titled “Model Comparison”| Model | Speed | Cost | Token Limit | When to Use |
|---|---|---|---|---|
| Claude Haiku 4.5 | Fastest | Lowest (~$0.80/$4 per M) | 200K | Classification, routing, high-volume simple tasks |
| Claude Sonnet 4.6 | Fast | Mid (~$3/$15 per M) | 200K | Most tasks — daily driver |
| Claude Opus 4.6 | Slower | Highest (~$15/$75 per M) | 200K | Complex reasoning, analysis, when quality is worth the cost |
Input/output cost per million tokens. Check anthropic.com/pricing for current rates.
Rule of thumb: Default to Sonnet. Switch to Haiku when running many calls that don’t need high quality. Switch to Opus when you have a hard problem and you can tell Sonnet is struggling.
Token and Pricing Quick Reference
Section titled “Token and Pricing Quick Reference”| Concept | What It Means |
|---|---|
| Token | ~4 characters of text (~0.75 words) |
| 1,000 tokens | ~750 words, or ~1.5 pages |
| Context window | How much text Claude can “see” at once (200K tokens = ~150K words) |
| Input tokens | Everything you send (system prompt + conversation history + your message) |
| Output tokens | Claude’s response — usually billed at a higher rate |
| Prompt caching | Reusing a long system prompt across calls — up to 90% savings on cached input |
Rough cost estimates at Sonnet pricing:
- Short Q&A (500 in / 300 out): ~$0.006
- Summarize a long article (2K in / 500 out): ~$0.013
- Analyze a 50-page document (40K in / 2K out): ~$0.15
- Full codebase review (100K in / 5K out): ~$0.38
MCP Quick Reference
Section titled “MCP Quick Reference”MCP (Model Context Protocol) servers give Claude access to external tools and data sources.
# List installed MCP serversclaude mcp list
# Add an MCP serverclaude mcp add <name> <command>
# Remove an MCP serverclaude mcp remove <name>
# Check MCP server statusclaude mcp get <name>Common MCP servers and what they do:
| Server | What It Adds |
|---|---|
filesystem | Read/write files anywhere on your system |
github | Read PRs, issues, repos; post comments |
notion | Read/write Notion pages and databases |
google-calendar | Read/create calendar events |
gmail | Read emails, create drafts |
firecrawl | Scrape and read web pages as clean text |
sqlite | Query a local SQLite database |
puppeteer | Browser automation |
API Quick Reference (Python)
Section titled “API Quick Reference (Python)”import anthropic
client = anthropic.Anthropic() # Uses ANTHROPIC_API_KEY env var
# Basic callresponse = client.messages.create( model="claude-sonnet-4-5", max_tokens=1024, system="You are a helpful assistant.", # optional messages=[{"role": "user", "content": "Hello"}])print(response.content[0].text)
# Streamingwith client.messages.stream( model="claude-sonnet-4-5", max_tokens=1024, messages=[{"role": "user", "content": "Write a story..."}]) as stream: for text in stream.text_stream: print(text, end="", flush=True)
# Multi-turn conversationmessages = []messages.append({"role": "user", "content": "What is machine learning?"})response = client.messages.create(model="claude-sonnet-4-5", max_tokens=512, messages=messages)messages.append({"role": "assistant", "content": response.content[0].text})messages.append({"role": "user", "content": "Give me a concrete example."})# Continue...API Quick Reference (JavaScript)
Section titled “API Quick Reference (JavaScript)”import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic(); // Uses ANTHROPIC_API_KEY env var
const response = await client.messages.create({ model: "claude-sonnet-4-5", max_tokens: 1024, system: "You are a helpful assistant.", messages: [{ role: "user", content: "Hello" }],});console.log(response.content[0].text);