Claude Code CLI Cheatsheet
Claude Code is Anthropic's AI coding assistant CLI tool that integrates into terminal workflows, supporting code generation, editing, review, debugging, and more. This cheatsheet covers common commands and configurations from basic startup to advanced extensions.
Overview
Claude Code is Anthropic's official AI coding assistant CLI, deeply integrated into terminal development workflows. It supports interactive sessions, code generation and editing, file operations, Git integration, and extensibility through the MCP protocol.
Quick Start
``bash
# Start an interactive session
claude
# One-shot query claude -p "Explain this codebase"
# Start with a specific model
claude --model claude-sonnet-4-20250514
`
Refer to the command table below for detailed usage.
Basic Commands
Use the claude command to start an interactive session, or -p for one-shot queries. --resume restores the previous session context. --print outputs in plain text (non-interactive).
Session Commands
Manage conversations with / prefixed commands: /help for assistance, /clear to clear the screen, /compact to compress context and save tokens, /cost to view session costs, /doctor to diagnose issues.
Code Operations
Use /bug to analyze code bugs, /review to review code changes, /add and /drop to manage context files, /read and /write for file I/O, /edit for code editing, /diff to view changes, /undo to revert modifications.
Configuration
Project-level configuration is defined in CLAUDE.md. User-level settings go in .claude/settings.json. Hooks provide custom script triggers. MCP tools and Extensions offer extensible integration capabilities.
Advanced
Advanced features include claude update for version updates, claude --verbose for detailed output, claude --version to check version, claude ssh for remote SSH mode, and claude mcp` for MCP tool management.
Basic Usage(5)
| Command | Level | ||
|---|---|---|---|
claudeStart an interactive Claude Code session | Basic | claude | |
claude -pOne-shot prompt without interactive session | Basic | claude -p 'Write a Python function to sort a list' | |
claude --resumeResume context from the last interactive session | Basic | claude --resume | |
claude --printOutput in plain text format, suitable for piping | Basic | claude --print -p 'List all files' | |
claude --modelSpecify which Claude model to use | Intermediate | claude --model claude-opus-4-20250514 |
Chat Commands(5)
| Command | Level | ||
|---|---|---|---|
/helpShow help for all available commands | Basic | /help | |
/clearClear the current session terminal display | Basic | /clear | |
/compactCompact session context to save tokens | Intermediate | /compact | |
/costShow current session token usage and cost estimate | Basic | /cost | |
/doctorDiagnose Claude Code environment issues | Intermediate | /doctor |
Code Operations(9)
| Command | Level | ||
|---|---|---|---|
/bugAnalyze specified files for potential bugs | Intermediate | /bug src/app.py | |
/reviewReview code changes or entire files | Intermediate | /review | |
/addAdd files to the session context | Basic | /add src/main.ts src/utils.ts | |
/dropRemove files from the session context | Basic | /drop src/utils.ts | |
/readRead file contents into the session context | Basic | /read package.json | |
/writeWrite generated content to a file | Basic | /write src/newfile.py | |
/editEdit code or text content | Intermediate | /edit src/app.ts -p 'Add error handling' | |
/diffView diff of changes in current context | Basic | /diff | |
/undoUndo the last code modification | Basic | /undo |
Configuration(7)
| Command | Level | ||
|---|---|---|---|
CLAUDE.mdProject-level instruction file (auto-loaded into context) | Intermediate | echo 'Use TypeScript strict mode' > CLAUDE.md | |
.claude/settings.jsonUser-level configuration file (JSON format) | Intermediate | cat .claude/settings.json | |
claude hooksConfigure custom hook scripts (pre/post actions) | Expert | claude hooks add pre-commit 'npm run lint' | |
MCP toolsIntegrate external tools and data sources via MCP protocol | Expert | claude mcp add weather --url https://api.weather.com/mcp | |
claude extensionsManage Claude Code extensions | Expert | claude extensions list | |
CLAUDE_PROJECT.mdShared project-level instruction file across projects | Intermediate | cat ~/.claude/CLAUDE_PROJECT.md | |
claude configView or modify Claude Code configuration | Intermediate | claude config set theme dark |
Advanced(5)
| Command | Level | ||
|---|---|---|---|
claude updateUpdate Claude Code to the latest version | Basic | claude update | |
claude --verboseEnable verbose logging output | Intermediate | claude --verbose | |
claude --versionShow Claude Code version information | Basic | claude --version | |
claude sshConnect to a remote Claude Code session via SSH | Expert | claude ssh user@remote-host | |
claude mcpManage MCP tools (add/remove/list) | Expert | claude mcp list |