Claude Code Cheat Sheet

Quick reference for claude — the CLI. Run claude to start, claude --help for flags.

How to Never Hit Your Claude Session Limit Again
Most Used Slash Commands
Command Explanation Typical Usage
/context Shows current context window usage — tokens consumed vs. remaining in this session Check before a long task to see if you need to compact or clear first
/clear Wipes the entire conversation history — Claude has no memory of anything said before Starting a brand-new, unrelated task; getting a clean slate
/compact Compresses conversation history into a summary, freeing context while keeping the working thread Conversation is getting long but you want to continue the same task without losing context
/plan Enters plan mode — Claude outlines its approach and waits for approval before taking any action Before a risky or multi-step task; when you want to review the approach before Claude touches any files
↩️ After Every Reply — What You Can Do
Continue
Send "continue" or "keep going" if Claude stopped mid-task. It will pick up exactly where it left off.
Rewind
Edit a previous message in the thread to re-run the conversation from that point — useful to try a different approach without re-typing context.
Clear /clear
Wipe history and start completely fresh. Use when moving to a new, unrelated task.
Compact /compact
Compress the conversation into a summary. Use when context is running low but the task isn't done.
Sub-agent
Ask Claude to spawn a sub-agent for a parallel or isolated subtask — e.g. "use an agent to research X while we continue". Results return as tool output.
💬 Other Slash Commands
/bug Report a bug to Anthropic with session context attached
/btw Add a silent note to Claude's context — no response generated; useful for passing context mid-task
/config View or change model, theme, and other settings
/cost Show token usage and estimated cost for this session
/doctor Run diagnostics — checks API key, config, connectivity
/help Show available commands and shortcuts
/init Generate a CLAUDE.md for the current codebase
/mcp List connected MCP servers and their status
/memory View and manage persistent memory files
/model Switch model mid-session (e.g. opus, sonnet)
/review Review a pull request — opens PR review skill
/simplify Review changed code for reuse, quality, and efficiency — then fix any issues found
/status Show current model, session ID, and working directory
📄 CLAUDE.md
Place a CLAUDE.md at the project root to give Claude persistent context — conventions, stack, commands to know, what to avoid.
/init Auto-generate a CLAUDE.md from the codebase
Claude reads CLAUDE.md at session start. Checked-in files inform all collaborators; .claude/settings.local.json is for personal overrides.
Global instructions: ~/.claude/CLAUDE.md — applies to all projects on this machine.
⚠️ Aim to keep CLAUDE.md under 200 lines. Shorter files load faster and stay focused — link out to docs rather than pasting them in.
⌨️ Keyboard Shortcuts
Enter Submit message
Shift+Enter New line without submitting
Ctrl+C Cancel current response or interrupt running tool
Ctrl+C Ctrl+C Exit Claude Code (double press)
↑ / ↓ Navigate prompt history
Tab Autocomplete file paths and slash commands
Ctrl+L Clear terminal output (doesn't reset conversation)
Esc Cancel pending input / close autocomplete
🚩 CLI Flags
--print / -p Non-interactive: print response and exit (pipe-friendly)
--continue / -c Resume the most recent conversation
--resume <id> Resume a specific session by ID
--model / -m Set model: claude-opus-4-7, claude-sonnet-4-6, etc.
--add-dir <path> Add an extra directory to Claude's context
--allowedTools Comma-separated list of tools to permit
--output-format text (default), json, or stream-json
--max-turns Limit agentic turns in non-interactive mode
--verbose Show full tool call details and timing
--version Print installed version and exit
🔒 Permissions & Trust
--dangerously-skip-permissions Skip all permission prompts — use in trusted, isolated environments only
Permissions are stored in .claude/settings.json (project) or ~/.claude/settings.json (global). Use /update-config skill to manage them.
Trust levels: allow (auto-approve), deny (auto-reject), or prompt (default). Applies per tool, per path prefix, or per command pattern.
🧠 Memory
Claude Code has a file-based memory system at ~/.claude/projects/<project>/memory/. Memories persist across sessions.
/memory View, search, and manage memory files
Types: user (preferences), feedback (corrections + confirmations), project (context, deadlines), reference (where things live).
Say "remember that…" to save something. Say "forget that…" to remove it. Claude saves proactively when it learns something non-obvious.
🪝 Hooks
Hooks are shell commands that run automatically in response to events — configured in settings.json under a hooks key.
PreToolUse Runs before a tool call — can block it by exiting non-zero
PostToolUse Runs after a tool completes — good for linting, logging
Notification Fires when Claude sends a desktop notification
Stop Runs when Claude finishes a response
Use the /update-config skill to add hooks ("run X after every file edit", "whenever Claude stops…").
🔌 MCP Servers
Model Context Protocol — extend Claude with external tools (databases, APIs, services). Configured in settings.json under mcpServers.
/mcp List connected MCP servers and available tools
Scopes: project (.claude/settings.json), user (~/.claude/settings.json), or via --mcp-config <file> flag.
Server types: stdio (local process) or http (remote). Each server exposes tools Claude can call like any built-in tool.
🤖 Agentic / Headless Use
Run one-shot tasks from the shell — useful for CI, scripts, and automation.
-p "prompt" Print mode: run prompt, output result, exit
Example: claude -p "summarise changes in this PR" --output-format json
Pipe input: cat file.py | claude -p "review this" — stdin is included in context.
Sub-agents: Use the SDK's Agent tool to spawn parallel sub-agents. Each starts cold — write self-contained prompts. Results return as tool output.
💡 Tips & Patterns
Run shell commands yourself: prefix with ! in the prompt — e.g. ! git log --oneline -10 — output lands directly in the conversation.
Context management: use /compact when the conversation gets long; use /clear for a clean slate on a new task.
Exploratory questions ("what could we do about X?") get a 2-3 sentence recommendation. Claude won't implement until you say go.
Images & screenshots: drag a file into the prompt or reference a path — Claude can read PNG/JPG/PDF and Jupyter notebooks.
Parallel agents: send multiple Agent tool calls in a single message to run them concurrently and cut wall-clock time on independent tasks.
Worktrees: use isolation: "worktree" on agents to give them an isolated git branch — auto-cleaned if no changes are made.
Models (2025): Opus 4.7 (claude-opus-4-7) · Sonnet 4.6 (claude-sonnet-4-6) · Haiku 4.5 (claude-haiku-4-5-20251001). Default to Sonnet for cost/quality balance; Opus for complex reasoning.