Claude Code Command Cheat Sheet: Master All CLI Operations
This comprehensive guide walks you through Claude Code’s installation, core design principles, full command reference—including basic CLI commands, slash commands, shortcuts, work modes, and advanced features—plus practical pros, cons, use‑case scenarios and a step‑by‑step workflow for real‑world development.
Core Value and Design Philosophy
Claude Code is a terminal AI programming assistant released by Anthropic in 2025. It works directly in the command line, can read project files, execute shell commands, and operate Git. Its advantage over competitors stems from three design pillars:
Multi‑Agent Parallel Architecture – approximately 40 built‑in tools and a 46 000‑line query engine enable sub‑agents to collaborate on complex tasks.
Progressive Context Management – layered memory with intelligent compression reduces token usage while preserving context quality.
Deep Repository Operations – native support for cross‑file edits, Git workflow integration, and fine‑grained permission control.
Installation & Environment Setup
Prerequisites
Node.js 18+ is required. Verify with node --version. Install from nodejs.org if missing.
Installation Commands
macOS/Linux/WSL (official script):
# Install stable version
curl -fsSL https://claude.ai/install.sh | bash
# Install latest version
curl -fsSL https://claude.ai/install.sh | bash -s latest
# Homebrew (macOS)
brew install --cask claude-codeWindows (requires Git for Windows or WSL):
# CMD / PowerShell
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmdNPM (all platforms): npm install -g @anthropic-ai/claude-code Verify installation: claude --version First launch guides authentication and workspace configuration.
For Alibaba Cloud Bailei Coding Plan, set environment variables in ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_Key",
"ANTHROPIC_BASE_URL": "https://coding.dashscope.aliyuncs.com/apps/anthropic",
"ANTHROPIC_MODEL": "qwen3.6-plus"
}
}CLI Startup Commands
Basic entry points: claude – start interactive REPL in current directory (daily multi‑turn development). claude "task description" – launch with a question and begin analysis immediately (quick query). claude -p "query" – execute once and exit, printing result (scripting / automation). claude -c – continue the most recent conversation in the current directory (morning start‑up).
Examples:
# Interactive mode
claude
> Please analyze the project’s code structure
# Question mode
claude "Explain the authentication flow"
# One‑off execution for CI/CD
claude -p "Check code style issues" >> review.log
# Resume previous session
claude -c
# AI remembers the unfinished bug fixAdvanced Startup Parameters
--add-dir– add extra work directories (essential for monorepos). Example:
claude --add-dir ../lib ../apps --model sonnet|opus|haiku– select model for the session. Example:
claude --model opus --verbose– enable detailed logs. --dangerously-skip-permissions – skip all permission confirmations (use only in sandbox). --system-prompt "text" – replace the default system prompt. --append-system-prompt "text" – append custom content to the default prompt.
Monorepo example:
claude --add-dir ../shared-lib ../api-gateway
# Claude can now understand cross‑package call logicPipe log file into Claude:
cat logs/error.log | claude -p "Analyze these errors and identify the most likely root cause"Slash Commands (Core Operations)
Session & Context Management
/help– show all commands and shortcuts. /clear – hard reset, erase all history. /compact – compress history while keeping core summary. /context – visualize current token usage. /resume – resume a previous session. /rewind (ESC ×2) – undo the last AI modification.
Difference between /compact and /clear: /compact compresses and retains core context (e.g., key decisions) – used to continue the same task with long dialogue. /clear erases all history – used to start a brand‑new task.
Git & Code Operations
/commit– analyze staged changes and auto‑generate a commit message. /review – review current changes, find bugs and style issues. /diff – show current git diff. /branch – create or switch git branch. /pr_comments – fetch and display open PR review comments.
Example workflow:
# Auto‑generate commit message
git add .
/commit
# PR‑time review
/review
# Suggested fixes: variable naming, missing exception handling, potential null pointerMemory & Configuration
/init– generate initial CLAUDE.md knowledge base (project description, tech stack, code style, common patterns). /memory – edit persistent CLAUDE.md file. /model – switch model within a session (Sonnet/Opus/Haiku). /config – view and edit runtime configuration. /cost – show token usage and cost for the current session. /stats – display session statistics.
Sample CLAUDE.md content (eliminates ~80 % of repetitive context setup):
## Tech Stack
- Java 17 + Spring Boot 3.x
- JWT Token stored in httpOnly cookies
- JUnit 5 + Mockito
## Code Style
- Use async/await instead of promises
- All API endpoints must have tests
- Structured error responses: { error: string, code: number }
## Project Structure
- Controllers: src/main/java/com/example/controller
- Services: src/main/java/com/example/service
- Repositories: src/main/java/com/example/repositoryDiagnosis & Authentication
/doctor– check environment, authentication, network. /version – show installed version. /login – log in to Anthropic account. /logout – log out current account. /upgrade – upgrade to latest version.
Integration & Extension
/mcp– manage Model Context Protocol server connections (connect external tools such as GitHub, databases). /skills – list and manage reusable skill packages. /hooks – configure automation hooks (e.g., auto‑format files with Prettier after write).
Keyboard Shortcuts
Session Control
Ctrl+C– interrupt current generation or command. Ctrl+D – safely exit Claude Code. Ctrl+L – clear screen (visual only, keep context). Ctrl+T – toggle task list, view background tasks. Ctrl+R – reverse search command history.
Operation Acceleration
Shift+Tab– cycle through three work modes (Default, Auto‑Accept, Plan). Esc ×2 – undo/rewind last AI operation. Ctrl+B – send current task to background. Alt+V – paste image (Windows).
Input Box
Shift+Enter– insert newline without sending. Ctrl+W – delete previous word. Ctrl+U – delete entire line. Ctrl+K – clear current input box.
Advanced Bash Prefix
Prefix a command with ! to execute it directly in the shell, bypassing the AI and saving tokens.
! git status
! npm run test
! ls -laWork Modes
Toggle modes with Shift+Tab:
Default – every file edit or command requires confirmation (suitable for production projects).
Auto‑Accept – file modifications are applied automatically; shell commands still need confirmation (fast iteration).
Plan – read‑only; Claude only analyzes and plans without making changes (design phase).
Advanced Features: Skills, Agents, MCP
Skills
Skills are packaged capabilities that can be invoked like plugins. Example: a “Run Tests” skill detects project structure, runs tests, parses output, and summarizes failures. To create a custom skill, add a folder under ~/.claude/skills/ containing a SKILL.md file.
Agents
Agents are autonomous AI entities that can plan, execute, reflect, and iterate toward a goal. Example workflow: “Fix this GitHub issue” → read issue → run tests → locate bug → generate fix → open PR with explanation.
MCP
MCP connects Claude Code to external services via the /mcp command. In many cases, combining CLI commands with Skills can replace MCP, saving context window and reducing token consumption.
Pros, Cons, and Suitable Scenarios
Advantages
Powerful agent capability – 67 % win rate over Cursor in code‑quality and correctness tests.
Cross‑file refactoring – understands tens of thousands of lines and performs consistent multi‑file refactors.
Low memory footprint – hierarchical memory compression keeps token usage low.
Deep Git workflow integration – auto‑generate commit messages, code review, PR management.
Model flexibility – Sonnet for everyday coding, Opus for complex architecture, Haiku for rapid exploration.
Disadvantages
Steep learning curve – many commands and shortcuts to master.
Terminal‑only – no GUI, which may deter developers unfamiliar with CLI.
Token cost – heavy usage can consume many tokens.
Limited Windows support – requires WSL or Git Bash.
Ideal Use Cases
Large‑scale project development – cross‑file refactoring, architecture understanding, complex bug fixing.
Automated workflows – CI/CD integration, code review, PR management.
Parallel multitasking – background task management for simultaneous AI operations.
Monorepo / micro‑service environments – use --add-dir to access multiple packages.
Practical Workflow Example (Spring Boot JWT Auth Module)
Step 1: Start and initialize
# Enter project directory
cd my-spring-boot-project
# Launch Claude
claude
# Initialize project knowledge base
/init
# Add authentication module rules
/memoryStep 2: Switch to Plan mode and design
Shift+Tab # Switch to Plan mode
> Design a JWT authentication module (registration, login, token refresh) and output a design document for review.Step 3: Confirm design, switch to Auto‑Accept, and implement
Shift+Tab # Switch to Auto‑Accept
> Implement according to the design document.Step 4: Review changes and commit
/diff
/review
/commitStep 5: Background compilation
Ctrl+B # Run compilation in background while continuing discussionStep 6: Context cleanup
/context # Check token usage
/compact retain the authentication module design and API specifications
/clear # Start a brand‑new task if neededLearning Path
Must‑Learn (Session Management) : /init, /compact, /clear, claude -c Important (Git Operations) : /commit, /review Intermediate (Model Switching) : /model, /memory Advanced (MCP / Skills) : /mcp, /skills Suggested staged learning: first master session continuation and context compression, then initialize projects and automate commits, followed by code review and mode switching, and finally explore MCP, Skills, and Agents as needed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
