Developer Tools

Claude Code
CLI Cheat Sheet

Complete reference for Claude Code CLI: commands, flags, keyboard shortcuts, permission modes, configuration files, MCP servers.

v4.6
Getting Started

Quick Start

1

Install

npm install -g @anthropic-ai/claude-code
2

Login

claude auth login
3

Start

claude

or claude "Fix the login bug"

Reference

CLI Commands

Basic Usage

claudeStart interactive session
claude "query"Start with initial prompt
claude -p "query"Non-interactive (print & exit)
claude -cContinue most recent conversation
claude -r "name"Resume specific session
claude updateUpdate to latest version

Authentication

claude auth loginSign in
claude auth login --ssoForce SSO authentication
claude auth login --consoleUse API billing
claude auth logoutSign out
claude auth statusShow auth status

Model & Session

--model opusUse Opus model
--model sonnetUse Sonnet model
--effort highIncrease thinking effort
--effort maxMaximum thinking (Opus only)
-n "name"Name the session
--fork-sessionNew session ID from resume

Permission & Security

--permission-mode planRead-only, plan proposals
--permission-mode acceptEditsAuto-approve edits
--permission-mode autoAuto-approve all
--allowedTools "Read,Edit"Pre-approve tools
--disallowedTools "Bash(rm *)"Block tools

Output & Format

--output-format textPlain text (default)
--output-format jsonJSON with metadata
--output-format stream-jsonStreaming JSON
--json-schema '...'Structured output
--verboseVerbose logging
--debugDebug mode

Advanced

--bareSkip auto-discovery (fast)
--max-turns 10Limit agentic turns
--max-budget-usd 5Budget limit
-w feature-authIsolated git worktree
--add-dir /pathAdd working directory
--remote "task"Create web session
In-Session

Slash Commands

Session Management

/helpShow all commands
/clearClear conversation context
/compactCompress context window
/costShow API usage & costs
/statusSession status
/renameRename session
/resumeResume past session

Configuration

/configOpen settings
/modelSwitch models
/memoryView/edit memory files
/permissionsManage permissions
/mcpManage MCP servers
/initGenerate CLAUDE.md
/doctorDiagnose issues

Skills

/simplifyReview code changes
/reviewReview pull requests
/loop 5m /cmdRun on interval
/scheduleScheduled remote agents
/skillsView available skills

Special Prefixes

!npm testRun bash command directly
#fix bugEnter plan mode
@file.tsReference a file
@file.ts#5-10Reference line range
@src/components/Reference folder
Shortcuts

Keyboard Shortcuts

Global Actions

Cancel / ExitCtrl+C
Exit Claude CodeCtrl+D
Toggle task listCtrl+T
History searchCtrl+R
Toggle verboseCtrl+O

Chat Input

Submit messageEnter
New lineShift+Enter
Accept autocompleteTab
Cycle permission modesShift+Tab
Clear prompt inputCtrl+L
Stash current promptCtrl+S
Paste imageCtrl+V
Open external editorCtrl+G
Voice dictationHold Space

Model & Mode

Open model pickerCmd+P
Toggle fast modeMeta+O
Toggle thinkingCmd+T
Undo last actionCtrl+_
Kill background agentsCtrl+X Ctrl+K

Permission Prompts

Confirm actionY or Enter
Decline actionN or Escape
Toggle explanationCtrl+E
Toggle debug infoCtrl+D
Security

Permission Modes

defaultSafe

Reads only. Best for getting started and sensitive work.

acceptEditsRecommended

Auto-approve reads + file edits + common FS commands (mkdir, touch, mv, cp, rm).

planRead-only

Reads only, generates plan proposals. Use for exploring before editing.

autoFull access

Auto-approve everything with background safety checks. Best for long tasks.

Switch modes with Shift+Tab or --permission-mode <mode> at startup. Protected paths (.git/, .zshrc, .mcp.json) are never auto-approved.

Setup

Configuration Files

CLAUDE.mdInstructions

Persistent project/user instructions loaded at session start.

./CLAUDE.md project-level
~/.claude/CLAUDE.md user-level
./.claude/rules/*.md path-scoped
settings.jsonSettings

Permissions, hooks, environment variables, model defaults.

~/.claude/settings.json user
.claude/settings.json project
.claude/settings.local.json local
.mcp.jsonMCP

MCP server configuration for external tools integration.

claude mcp add name transport url
claude mcp list
claude mcp remove name
.claude/Directory

Project configuration directory structure.

settings.json shared config
commands/ custom slash commands
agents/ subagent definitions
keybindings.json custom keys
Automation

Hooks

Shell commands that run automatically in response to Claude Code events. Defined in settings.json.

Available Hooks

SessionStartWhen session begins
SessionEndWhen session ends
UserPromptSubmitBefore user message processed
PreToolUseBefore tool execution
PermissionRequestOn permission prompt
InstructionsLoadedWhen CLAUDE.md loaded

Environment Variables

ANTHROPIC_API_KEYAPI key for auth
CLAUDE_CODE_DEBUG_LOGS_DIRDebug log directory
CLAUDE_CODE_DISABLE_AUTO_MEMORYDisable auto memory
CLAUDE_CODE_SIMPLESkip context discovery
Best Practices

Golden Rules

1

Review diff trước khi accept

Luôn đọc kỹ thay đổi trước khi nhấn Y. Claude rất mạnh nhưng không hoàn hảo — bạn là người kiểm soát cuối cùng.

2

Prompt có cấu trúc

Theo công thức: WHAT (làm gì) + WHERE (file/folder nào) + HOW (cách làm) + CHECK (kiểm tra thế nào).

Fix the login redirect bug in src/auth/login.ts.
Use NextAuth's signIn callback, not manual redirect.
Verify by running npm test -- auth.
3

Plan Mode cho task phức tạp

Prefix # trước prompt để vào Plan Mode. Claude chỉ đọc, phân tích và đề xuất — không sửa code. Review plan rồi mới thực thi.

# Refactor authentication to use JWT instead of sessions
4

Tạo CLAUDE.md cho mọi project

Chạy /init để tạo file hướng dẫn. Claude đọc file này mỗi session — giúp nó hiểu stack, conventions, và quy tắc của project.

5

Dùng /compact khi context đầy

Context window có giới hạn. Khi thấy Claude quên context cũ hoặc phản hồi chậm, chạy /compact để nén conversation mà vẫn giữ ý chính.

6

Commit thường xuyên

Commit sau mỗi milestone nhỏ. Nếu Claude làm sai, bạn có thể git revert dễ dàng thay vì undo thủ công hàng chục file.

Context

Context & Model

Context Management

/compactNén context, giữ lại ý chính
/compact "focus"Nén + hướng focus cụ thể
/clearXóa sạch context (bắt đầu lại)
/costXem token usage & chi phí
@file.tsĐính kèm file vào context
@folder/Đính kèm cả folder
Ctrl+VPaste ảnh/screenshot vào prompt

Chọn Model

OpusMạnh nhất, tốt cho task phức tạp
SonnetCân bằng tốc độ & chất lượng
HaikuNhanh nhất, task đơn giản
/modelĐổi model giữa session
--effort high|maxTăng thinking depth
/fastToggle fast mode (Opus)

Khi nào /compact vs /clear

/compactCùng task, context quá dài
/clearChuyển sang task hoàn toàn mới
claude -cTiếp tục session cũ (đã exit)
claude -r "name"Quay lại session theo tên

Tiết kiệm Context

--bareBỏ qua CLAUDE.md, git info
@file.ts#5-20Chỉ đính kèm dòng 5–20
#Plan mode: chỉ đọc, không sửa
--max-turns 5Giới hạn số lượt agent
Workflows

Quy trình thực tế

Mở project, code, commit, lặp lại
$ cd my-project && claude
# Mở project + bắt đầu session
> Fix bug login redirect sau khi auth @src/auth/
# Mô tả task + @mention file/folder liên quan
Review diff → Y để accept, N để từ chối
# Luôn đọc diff trước khi accept
> !npm test
# Chạy test trực tiếp trong session
> Commit fix login redirect
# Bảo Claude commit sau mỗi milestone
> /compact
# Nén context → tiếp task tiếp theo
Paste error, Claude trace, fix, test
> Fix this error: "TypeError: Cannot read property 'id' of undefined"
# Paste error message hoặc screenshot (Ctrl+V)
Claude tự grep → đọc file → trace root cause
# Để Claude tự tìm — không cần chỉ file
Review diff → Y hoặc "thử cách khác"
# Không hài lòng? Nói Claude thử approach khác
> !npm test -- auth
# Chạy test liên quan để verify fix
> Có edge case nào khác không? Kiểm tra thêm
# Nhờ Claude rà soát thêm edge cases
Plan trước, code sau, test liên tục
Shift+Tab → Plan
# Plan Mode — KHÔNG sửa code
> Phân tích @src/module/ — dependencies, side effects
# Hiểu impact trước khi động vào
Shift+Tab → Auto
# Thoát Plan → bắt đầu refactor từng bước
> !npm test
# Test pass? Tiếp tục
> Commit refactor module X
# Bảo Claude commit sau mỗi bước thành công
> /compact
# Nén context → tiếp phần tiếp theo
Setup CLAUDE.md từ đầu
$ mkdir my-app && cd my-app && claude
# Tạo thư mục + mở Claude Code
> /init
# Claude phân tích codebase → tự tạo CLAUDE.md
Shift+Tab → Plan
# Plan Mode — thiết kế kiến trúc
> Thiết kế folder structure, key files, conventions cho React + Tailwind
# Claude đề xuất cấu trúc
Shift+Tab → Auto
# Thoát Plan → scaffold dự án
> !git init && git add -A && git commit -m "init"
# Commit baseline
Đúng model, đúng việc
> /model haiku
# Haiku cho fix nhỏ, rename, typo — rẻ nhất
> /fast
# Fast mode — cùng model, output nhanh hơn
> /model sonnet
# Sonnet cho code thực — best value
> /compact
# Compact thường xuyên = ít token = tiết kiệm
> /model opus
# CHỈ dùng Opus cho: race condition, architecture, debug khó
> /cost
# Kiểm tra chi phí — chỉ hiển thị khi dùng API
macOS Terminal

cmux — Terminal cho AI Agents

Chạy nhiều Claude Code sessions cùng lúc trên macOS? Dùng cmux — Ghostty-based terminal với vertical tabs, smart notifications, và built-in browser.

Vertical tabs Git branch, PR status, directory per tab
Notifications Blue ring khi Claude cần attention — ⌘⇧U nhảy ngay
Split panes ⌘D split right, ⌘⇧D split down
Browser pane ⌘⇧L mở browser ngay trong terminal
cmux Cheat Sheet → GitHub ↗
Starter Kit

ClaudeKit — AI Development Team

Supercharge Claude Code với 60+ specialized agents, 90+ skills, và production-ready workflows. Ship features in minutes thay vì hours.

14 Agents Planner, Debugger, Tester, Code Reviewer, UI/UX Designer...
90+ Skills Frontend, backend, DevOps, cloud, AI, media processing
Workflow Commands /ck:plan/ck:cook/ck:test → ship
Thinking Skills Systematic debugging, root cause tracing, problem-solving frameworks
ClaudeKit Cheat Sheet → Get ClaudeKit ↗
Integrations

IDE Shortcuts

VS Code

Toggle focus editor/ClaudeCmd+Esc
New conversationCmd+Shift+Esc
Insert @-mentionOption+K
Model pickerCmd+P

JetBrains

Open Claude CodeCmd+Esc
Insert file referenceCmd+Option+K
Connect terminalclaude /ide