Claude Code
CLI Cheat Sheet
Complete reference for Claude Code CLI: commands, flags, keyboard shortcuts, permission modes, configuration files, MCP servers.
Quick Start
Install
npm install -g @anthropic-ai/claude-codeLogin
claude auth loginStart
claudeor claude "Fix the login bug"
Glossary — hiểu nhanh các khái niệm
Những từ hay gặp trong Claude Code. Nắm các khái niệm này trước rồi đọc phần lệnh sẽ dễ hơn nhiều.
Phiên & Agent
SubagentAgent con làm task phụ, trả kết quả vềBackground AgentPhiên chạy ngầm, giải phóng terminalWorktreeGit worktree riêng để làm song songAgent ViewMàn hình quản lý phiên nền & subagentKỹ năng & Lệnh
SkillPrompt đóng gói, gọi bằng slash commandWorkflowQuy trình đa-agent động, chạy nềnSlash CommandLệnh trong phiên, bắt đầu bằng /HookScript tự chạy khi có sự kiện toolModel & Ngữ cảnh
Effort LevelMức suy nghĩ: low → max → ultracodeFast ModeOpus xuất nhanh hơn, không đổi model nhỏExtended ThinkingCho model suy luận sâu trước khi trả lờiContext / CompactCửa sổ ngữ cảnh; /compact nén để giải phóngPrompt CachingCache ngữ cảnh lặp lại, giảm tokenChế độ & Tích hợp
Plan ModeChỉ-đọc, đề xuất kế hoạch trước khi sửaPermission ModeDuyệt tool: plan / acceptEdits / autoSandboxChạy code cách ly an toàn trong phiênCheckpoint / RewindĐiểm lưu để cuộn code/hội thoại vềMCP ServerServer nối thêm tool cho Claude (MCP)ArtifactSản phẩm độc lập chia sẻ được (design/HTML)CLI Commands
Basic Usage
claudeStart interactive sessionclaude "query"Start with initial promptclaude -p "query"Non-interactive (print & exit)claude -cContinue most recent conversationclaude -r "name"Resume specific sessionclaude updateUpdate to latest versionAuthentication
claude auth loginSign inclaude auth login --ssoForce SSO authenticationclaude auth login --consoleUse API billingclaude auth logoutSign outclaude auth statusShow auth statusModel & 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 resumePermission & 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 toolsOutput & Format
--output-format textPlain text (default)--output-format jsonJSON with metadata--output-format stream-jsonStreaming JSON--json-schema '...'Structured output--verboseVerbose logging--debugDebug modeAdvanced
--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 sessionSlash Commands
Gõ / để xem danh sách. Skill (/test, /code-review…) hoạt động như prompt gửi tới Claude; Workflow (/deep-research) toả việc ra nhiều subagent chạy nền. Từ v2.1.199+ có thể nối tối đa 6 skill: /skill-a /skill-b làm XYZ.
Cách đọc cú pháp
<arg>Bắt buộc[arg]Tùy chọn[a|b]Chọn một/a /b taskNối nhiều skill (tối đa 6)Phiên & Điều hướng
/helpDanh sách lệnh khả dụng/clearBắt đầu mới, giữ memory (alias /new)/resume [name]Quay lại phiên trước/rewind [--list]Cuộn code/hội thoại về checkpoint/branch [name]Rẽ nhánh hội thoại thử hướng khác/fork [prompt]Sao chép phiên sang background/compactNén context, có thể kèm chỉ dẫn/export [file]Xuất hội thoại ra textModel & Ngữ cảnh
/model [model]Đổi model, lưu default/effort [level]low → max → ultracode / auto/fast [on|off]Bật/tắt fast mode (mid-turn)/thinking [on|off]Bật/tắt extended thinking/context [all]Xem mức dùng context/usageXem API usage (alias /cost)/statusTrạng thái phiên & modelCấu hình & Chẩn đoán
/config [k=v]Mở settings / đặt trực tiếp/permissionsQuản lý allow/ask/deny tool/mcpQuản lý MCP server & OAuth/memorySửa CLAUDE.md & auto memory/initTạo CLAUDE.md cho dự án/hooksXem cấu hình hook/doctorChẩn đoán cài đặt (alias /checkup)/agentsTạo/quản lý subagentReview & Test (Skills)
/code-review [lvl] [--fix]Soát lỗi diff/PR; ultra = cloud/security-review [--fix]Quét lỗ hổng bảo mật/simplify [--fix]Đơn giản hóa code/test [--fix]Phân tích test fail, đề xuất fix/verifyXác minh code/test chạy đúng/debug [mô tả]Bật debug log, truy vết sự cố/suggestGợi ý cải tiến codeSkills & Workflow khác
/design [brief]Mockup UI/landing trên canvas/dataviz [request]Hướng dẫn thiết kế chart/dashboard/deep-research <q>Toả web search, tổng hợp báo cáo/loop [interval] [prompt]Chạy lặp theo chu kỳ (alias /proactive)/batch <instruction>Tách việc lớn thành 5–30 phần song song/subtask [task]Giao task phụ cho subagentChạy nền & Thiết bị
/tasksLiệt kê việc nền của phiên/background [prompt]Tách phiên chạy ngầm (alias /bg)/teleportKéo web session về terminal/remote-control [on|off]Điều khiển phiên từ thiết bị khác/watch <command>Chạy Bash lặp, đẩy output cho Claude/desktopTiếp tục phiên trong app DesktopKý hiệu đặc biệt
!npm testChạy lệnh Bash trực tiếp#fix bugVào plan mode@file.tsTham chiếu một file@file.ts#5-10Tham chiếu khoảng dòng@src/components/Tham chiếu thư mụcKeyboard Shortcuts
Global Actions
Chat Input
Model & Mode
Permission Prompts
Permission Modes
Reads only. Best for getting started and sensitive work.
Auto-approve reads + file edits + common FS commands (mkdir, touch, mv, cp, rm).
Reads only, generates plan proposals. Use for exploring before editing.
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.
Configuration Files
Persistent project/user instructions loaded at session start.
./CLAUDE.md project-level~/.claude/CLAUDE.md user-level./.claude/rules/*.md path-scopedPermissions, hooks, environment variables, model defaults.
~/.claude/settings.json user.claude/settings.json project.claude/settings.local.json localMCP server configuration for external tools integration.
claude mcp add name transport urlclaude mcp listclaude mcp remove nameProject configuration directory structure.
settings.json shared configcommands/ custom slash commandsagents/ subagent definitionskeybindings.json custom keysHooks
Shell commands that run automatically in response to Claude Code events. Defined in settings.json.
Available Hooks
SessionStartWhen session beginsSessionEndWhen session endsUserPromptSubmitBefore user message processedPreToolUseBefore tool executionPermissionRequestOn permission promptInstructionsLoadedWhen CLAUDE.md loadedEnvironment Variables
ANTHROPIC_API_KEYAPI key for authCLAUDE_CODE_DEBUG_LOGS_DIRDebug log directoryCLAUDE_CODE_DISABLE_AUTO_MEMORYDisable auto memoryCLAUDE_CODE_SIMPLESkip context discoveryGolden Rules
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.
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.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 sessionsTạ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.
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.
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 & 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ả folderCtrl+VPaste ảnh/screenshot vào promptChọn Model
OpusMạnh nhất, tốt cho task phức tạpSonnetCân bằng tốc độ & chất lượngHaikuNhanh 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ớiclaude -cTiếp tục session cũ (đã exit)claude -r "name"Quay lại session theo tênTiế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 agentQuy trình thực tế
Quy trình 5 file — để app không “vỡ” khi sửa
Đây là cách làm việc cùng Claude Code theo hướng documentation-driven: mỗi quyết định được ghi thành một file trong dự án, không trôi vào chat. Bạn đóng vai Product Owner + BA + QA, Claude là cả team kỹ thuật. Rút gọn từ series “Đồng Use Claude”.
Chat với Claude → sinh code → đi tiếp. Lần sửa sau, không ai (kể cả AI) nhớ ràng buộc ban đầu, nên một thay đổi làm vỡ nhiều chỗ. Quyết định nằm trong lịch sử chat, không nằm trong dự án → bảo trì bất khả thi.
intent/INTENT-01.md Vì sao làm? Bài toán kinh doanh thật, kết quả quan sát được, ràng buộc tuyệt đối. “Hợp đồng” đầu tiên trước khi thiết kế.
spec/SPEC-01.md Biến INTENT thành yêu cầu chức năng, business rule, data schema, và các trade-off có ghi rõ lý do chọn.
plan/PLAN-01.md Biến SPEC thành kế hoạch thi công: file nào đổi, thứ tự thực thi, rủi ro & cách giảm, tiêu chí hoàn thành.
CLAUDE.md + code Claude viết code bám theo PLAN. CLAUDE.md giữ convention & chỉ dẫn để mọi phiên làm nhất quán.
test/TEST-01.md Chạy kịch bản test đã viết, có bằng chứng. Thay “cảm giác chắc chạy” bằng “biết chắc chạy”.
phần 7 & 8 Deploy lên Cloudflare (chi phí 0đ) rồi chạy lại toàn bộ kịch bản test trên URL thật; đóng gói tính năng phức tạp thành component tái dùng.
Thứ tự là bất biến
Thiếu INTENTSPEC thành đoán mòThiếu SPECPLAN thiếu business logicThiếu PLANBUILD làm tán loạnThiếu TESTChỉ “cảm thấy” chứ không “biết”Phân vai rõ ràng
BạnProduct Owner + BA + QAClaudeDev + Tester + PM trong mộtFile .md“Hợp đồng” để đối chiếuNguyên tắcAI không tự quyết yêu cầu thay bạnMini-CRM cho chủ shop: khách bị trùng bản ghi giữa Excel & sổ tay, số điện thoại mỗi nơi một định dạng. App chuẩn hoá số điện thoại và phát hiện/gộp bản ghi trùng — business logic thật, không phải demo đồ chơi. Mỗi quyết định neo vào file để “bạn của tương lai” (hoặc bất kỳ AI nào) dựng lại ngữ cảnh sau nhiều tháng.
Học full series “Đồng Use Claude” →Dự án từ A–Z: Landing Page cho khách hàng
Toàn bộ chỉ dùng lệnh Claude Code gốc — không cần plugin. Ngày 1 dựng landing page, ngày 2 thêm form đặt hàng và hoàn thiện.
Ngày 1 — Khởi tạo & dựng trang
Ngày 2 — Thêm form đặt hàng & hoàn thiện
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.
AgentKit — AI Development Team
Supercharge Claude Code với 45 specialized agents, 108+ skills, và production-ready workflows. Ship features in minutes thay vì hours. (AgentKit là tên mới của ClaudeKit.)
/ak:plan → /ak:cook → /ak:test → ship IDE Shortcuts
VS Code
JetBrains
claude /ide