Claude Code is Anthropic's official terminal agentic coding assistant that runs directly in your local command-line environment. It understands repository architectures, edits files, executes test suites, and manages Git workflows autonomously.
This cheat sheet summarizes Claude Code's CLI flags, built-in slash commands, terminal shortcuts, and CLAUDE.md guidelines in compact reference tables.
🔗 Related Cheat Sheets: Core AI Algorithms Cheat Sheet · Python Cheat Sheet · 4 Leading Always-on Agents Comparison Cheat Sheet
1. CLI Commands & Startup Flags
Invoke claude directly from your shell for interactive REPL sessions, non-interactive shell scripting pipelines, and configuration:
| Command / Flag | Description | Example Usage |
|---|---|---|
claude |
Start an interactive REPL session in the current directory | claude |
claude "prompt" |
Start a session immediately with an initial goal | claude "Fix timeout errors in tests/auth.test.ts" |
-p, --print |
Run non-interactively and print the final response to stdout (pipe-friendly) | claude -p "Summarize the latest git commit" > summary.md |
--resume [session_id] |
Resume a previous session; opens a picker if ID is omitted | claude --resume |
--model <name> |
Specify the underlying model (e.g., sonnet, opus) |
claude --model sonnet |
--dangerously-skip-permissions |
Bypass all file edit and shell execution confirmation prompts (containers/sandboxes only) | claude --dangerously-skip-permissions "Run build pipeline" |
claude config [get|set|list] |
Inspect or update global and project configuration | claude config list |
claude mcp [list|add|remove] |
Manage Model Context Protocol (MCP) server connections | claude mcp list |
claude update |
Check and upgrade Claude Code to the latest release | claude update |
claude doctor |
Inspect environment health (Node, Git, network, dependencies) | claude doctor |
2. Interactive Slash Commands
Inside an active Claude Code session, type / to access built-in commands for context, permissions, and task management:
2.1 Initialization & Context Management
| Command | Description | Best Practice & Details |
|---|---|---|
/init |
Analyze project structure and create/update CLAUDE.md |
Recommended first command when adopting Claude Code in a repo |
/context |
Visualize token allocation in the current context window | Breaks down system prompts, tool schemas, and conversation memory |
/compact [instructions] |
Compact conversation history to reclaim context window headroom | Optionally pass compaction guidance: /compact keep only refactoring decisions |
/clear |
Clear conversation history and reset context for a new task | Keeps current directory and process active without exiting |
/memory |
Inspect or edit persistent project guidelines in CLAUDE.md |
Quickly verify rules and project conventions currently in effect |
2.2 Configuration & Security Permissions
| Command | Description | Best Practice & Details |
|---|---|---|
/config |
Interactive settings menu (editor, model, defaults) | Adjust theme preferences, tool policies, and network proxies |
/permissions |
Manage authorized tool execution rules and command whitelists | Review trusted Bash patterns and write-permission scopes |
/terminal-setup |
Configure terminal bindings (Shift+Enter multiline support) | Run once after initial install for smoother multiline input |
/login |
Authenticate with your Anthropic account | Switch active credentials or re-authenticate expired sessions |
/logout |
Clear cached auth tokens from local machine | Safely disconnect credentials on shared workstations |
2.3 Code Review, Debugging & Task Control
| Command | Description | Best Practice & Details |
|---|---|---|
/review [target] |
Review code changes for architecture, performance, and defects | Common invocations: /review (unstaged diff) or /review main |
/diff |
Display a diff of all modifications made by Claude Code | Verify line-by-line changes before committing |
/cost |
Display token consumption and estimated API costs for session | Keep track of token budgets across large-context multi-turn tasks |
/doctor |
In-session environment diagnostics | Troubleshoot failing tool executions and git integration issues |
/bug, /feedback |
Submit telemetry and bug reports directly to Anthropic | Packages version and diagnostics to assist triage |
/help |
Print list of available slash commands | Quick reference during active development |
/exit, /quit |
Save session state and exit Claude Code | Or press Ctrl + D on an empty line |
2.4 Model Switching & Protocol Extensions
| Command | Description | Best Practice & Details |
|---|---|---|
/model [model_name] |
Switch the underlying reasoning model dynamically | Use high-reasoning models for architecture, standard models for syntax edits |
/mcp |
Manage Model Context Protocol (MCP) integrations | Verify status of external databases, docs, and custom tools |
/pr |
Draft commit descriptions and open a GitHub Pull Request | Requires GitHub CLI (gh) or configured GitHub Token |
/resume |
Select and resume historical sessions from within prompt | Seamlessly switch back to previous project contexts |
3. Terminal Keybindings & Interaction Syntax
| Key / Syntax | Action | Context & Behavior |
|---|---|---|
Esc |
Interrupt Task | Immediately stops thinking, file editing, or streaming output |
Ctrl + C |
Cancel Input / Abort | Clears the prompt line; aborts running sub-processes |
Ctrl + D |
Exit Cleanly | Disconnects and exits when the prompt input is empty |
Shift + Enter |
Multiline Input | Inserts a newline without submitting (requires terminal setup) |
@<path> |
Explicit File/Dir Reference | e.g. @src/utils/auth.ts, injects target file into context |
!<shell_command> |
Run Shell Command | e.g. !git status or !npm test, runs command without leaving Claude |
↑ / ↓ |
History Navigation | Cycle through and recall previously executed prompt commands |
4. CLAUDE.md Project Memory Configuration Guide
The CLAUDE.md file in your repository root serves as persistent memory, guiding Claude Code's behavior across every session:
| Section | Recommended Content | Examples |
|---|---|---|
| Build & Run Commands | Core setup, dependencies, dev server start | npm run build, pnpm dev, make all |
| Test & Lint Commands | Unit tests, integration tests, linters | npm test, npm run lint, cargo test |
| Code Style Guidelines | Formatting rules, naming conventions, type safety | Strict TypeScript mode, no any, functional patterns |
| Protected Paths | Files and directories Claude must not modify | .env, secret keys, vendor build directories |
| Git Workflow | Commit conventions and branch strategies | Conventional Commits (feat:, fix:, chore:) |