Từ lệnh cơ bản đến điều phối agents, hooks, skills và MCP servers — với hướng dẫn trực quan, template copy-paste và bài tập thực hành.
Click vào module để xem nội dung chi tiết, bài tập thực hành và quiz kiểm tra.
Slash commands là các phím tắt điều khiển hành vi của Claude trong phiên làm việc. Có 60+ lệnh tích hợp sẵn và khoảng 20 bundled skills. Gõ / trong Claude Code để xem toàn bộ danh sách.
/help, /clear, /model — do Claude Code cung cấpSKILL.md (/optimize, /pr)/frontend-design:frontend-design)/mcp__github__list_prs)Lưu ý: Custom slash commands đã được merge vào skills. File trong.claude/commands/vẫn hoạt động, nhưng skills (.claude/skills/) là cách tiếp cận được khuyến nghị.
/help
Hiển thị trợ giúp
/clear
Xóa cuộc hội thoại (alias: /reset, /new)
/model [model]
Chọn model AI — lựa chọn được lưu làm mặc định
/compact
Nén cuộc hội thoại để tiết kiệm context
/memory
Chỉnh sửa CLAUDE.md, bật/tắt auto-memory
/plan [mô tả]
Vào chế độ lập kế hoạch
/code-review [level]
Review code hiện tại hoặc PR
/rewind
Quay lại checkpoint (alias: /undo)
/mcp
Quản lý MCP servers
/skills
Liệt kê các skills khả dụng
/context
Xem mức sử dụng context dạng lưới màu
/effort [level]
Đặt effort level: low → medium → high → xhigh → max
Mục tiêu: Tạo một custom slash command để tối ưu hóa code.
# Tạo thư mục commands trong project
mkdir -p .claude/commands
# Tạo file optimize.md
cat > .claude/commands/optimize.md << 'EOF'
---
name: optimize
description: Phân tích và tối ưu hóa code
---
Phân tích code được chọn và đề xuất cải tiến về:
1. Hiệu suất (Performance)
2. Khả năng đọc (Readability)
3. Khả năng bảo trì (Maintainability)
4. Bảo mật (Security)
EOF
# Thử nghiệm trong Claude Code — gõ:
# /optimize
Mục tiêu: Làm quen với các lệnh cơ bản nhất.
# Trong Claude Code, thử các lệnh sau:
/help # Xem danh sách lệnh
/model # Chọn model
/status # Xem trạng thái phiên
/context # Xem mức sử dụng context
/effort high # Đặt effort level cao
Mục tiêu: Tạo command nhận tham số đầu vào bằng $ARGUMENTS.
cat > .claude/commands/fix-issue.md << 'EOF'
---
name: fix-issue
description: Sửa một GitHub issue theo chuẩn code của project
argument-hint: "[issue-number]"
---
Sửa GitHub issue $ARGUMENTS:
1. Đọc mô tả issue bằng `gh issue view $ARGUMENTS`
2. Tìm code liên quan
3. Implement fix theo coding standards của project
4. Viết test cho fix
EOF
# Sử dụng: /fix-issue 123
1. Lệnh nào dùng để xóa cuộc hội thoại hiện tại?
2. Custom slash commands được lưu ở đâu?
Memory cho phép Claude lưu trữ context qua nhiều phiên làm việc. Có 2 hệ thống: CLAUDE.md files (bạn viết) và Auto Memory (Claude tự ghi chú).
/Library/Application Support/ClaudeCode/CLAUDE.md
Toàn tổ chức
~/.claude/CLAUDE.md
Sở thích cá nhân
./CLAUDE.md hoặc ./.claude/CLAUDE.md
Chuẩn team (commit vào git)
./CLAUDE.local.md
Cá nhân cho project (gitignore)
Các file được nối vào context chứ không ghi đè — file nào load sau sẽ xuất hiện sau trong context.
/init
Khởi tạo CLAUDE.md cho project
/memory
Mở memory files trong editor
@path/to/file
Import nội dung file vào CLAUDE.md
Mục tiêu: Viết project memory chứa chuẩn code và quy ước của team.
# CLAUDE.md
## Dự Án
- Tên: My Project
- Tech Stack: Node.js, React, PostgreSQL
## Quy Tắc Code
- Dùng TypeScript strict mode
- Viết unit test cho mọi function
- Commit message theo conventional commits
## Cấu Trúc Thư Mục
- src/ — mã nguồn chính
- tests/ — unit tests
- docs/ — tài liệu
## Lệnh Quan Trọng
- npm run dev — chạy dev server
- npm run test — chạy tests
- npm run build — build production
# Khởi tạo CLAUDE.md tự động trong Claude Code
/init
# Chế độ interactive (chi tiết hơn)
CLAUDE_CODE_NEW_INIT=1 claude
/init
# Chỉnh sửa memory
/memory
# Import file khác vào CLAUDE.md — thêm vào nội dung:
# @README.md
# @docs/architecture.md
1. File CLAUDE.md nào có phạm vi rộng nhất (tổ chức)?
2. Lệnh nào dùng để khởi tạo CLAUDE.md?
Checkpoints tự động lưu snapshot trạng thái cuộc hội thoại với mỗi prompt. Bạn có thể quay lại (rewind) để thử cách tiếp cận khác mà không mất dữ liệu.
Esc + Esc
Mở menu rewind nhanh
/rewind
Quay lại checkpoint (alias: /undo, /checkpoint)
/branch [name]
Tạo nhánh hội thoại mới từ điểm hiện tại
Kịch bản: Thử 2 cách implement khác nhau và so sánh.
# 1. Yêu cầu Claude implement tính năng
"Implement user authentication"
# 2. Nhận thấy có thể làm theo cách khác
# Nhấn Esc + Esc để mở menu rewind
# 3. Chọn "Restore code and conversation"
# để quay lại trước khi implement
# 4. Thử cách khác
"Implement user authentication using JWT + refresh tokens"
# 5. So sánh 2 cách tiếp cận
# Tạo nhánh mới từ điểm hiện tại, giữ nguyên hội thoại gốc
/branch approach-with-redis
# Quay lại hội thoại gốc sau
/resume
1. Phím tắt nào mở menu rewind nhanh?
Claude Code chạy từ command line với nhiều chế độ: interactive, print mode (non-interactive), và piping — nền tảng cho scripting và CI/CD.
claude "prompt"
Chế độ tương tác
claude -p "prompt"
Print mode — không tương tác, dùng cho scripts
cat file | claude -p "prompt"
Pipe nội dung file vào Claude
claude -r "session" "prompt"
Tiếp tục phiên trước
claude -p --output-format json
Output JSON cho automation
# Interactive mode
claude "explain this project"
# Print mode (cho scripts)
claude -p "summarize README.md"
# Piping nội dung file
cat error.log | claude -p "explain this error"
# JSON output
claude -p --output-format json "list functions"
# Resume session
claude -r "feature-auth" "continue implementation"
# Tóm tắt tất cả file .md trong thư mục
for file in *.md; do
claude -p "summarize this: $(cat $file)" > "${file%.md}.summary.txt"
done
1. Flag nào dùng cho print mode (không tương tác)?
Skills là các khả năng tái sử dụng lưu trên filesystem, đóng gói chuyên môn và workflow thành component mà Claude tự động kích hoạt khi phù hợp.
name + descriptionNhờ vậy bạn có thể cài nhiều skills mà không tốn context.
my-skill/
├── SKILL.md # Hướng dẫn chính (bắt buộc)
├── template.md # Template cho Claude điền
├── examples/
│ └── sample.md # Ví dụ output
└── scripts/
└── validate.sh # Script Claude có thể chạy
---
name: your-skill-name
description: Mô tả skill và khi nào sử dụng
effort: high
context: fork # chạy trong subagent riêng
agent: Explore # loại agent
---
# Tên Skill
## Hướng Dẫn
Cung cấp hướng dẫn rõ ràng, từng bước cho Claude.
## Ví Dụ
Ví dụ cụ thể về cách dùng skill.
~/.claude/skills/<name>/
Personal — mọi project của bạn
.claude/skills/<name>/
Project — chia sẻ qua git với team
<plugin>/skills/<name>/
Plugin — đi kèm plugin
# Tạo thư mục skill
mkdir -p ~/.claude/skills/code-review
# Tạo SKILL.md
cat > ~/.claude/skills/code-review/SKILL.md << 'EOF'
---
name: code-review
description: Review code toàn diện về bảo mật, hiệu suất, chất lượng
effort: high
---
# Code Review Skill
## Kiểm Tra
1. **Bảo Mật** — injection, auth issues, data exposure
2. **Hiệu Suất** — algorithm efficiency, memory, DB queries
3. **Chất Lượng** — SOLID, naming, test coverage
## Output Format
- Đánh giá tổng thể (1-5)
- Các vấn đề tìm thấy + mức độ nghiêm trọng
- Đề xuất cải thiện kèm code mẫu
EOF
Dùng cú pháp !`command` để inject output shell vào skill:
---
name: pr-summary
description: Tóm tắt pull request
context: fork
agent: Explore
---
## PR Context
- PR diff: !`gh pr diff`
- PR comments: !`gh pr view --comments`
- Changed files: !`gh pr diff --name-only`
## Task
Tóm tắt pull request này...
1. File nào là bắt buộc trong một skill?
2. Field nào để skill chạy trong subagent riêng?
Hooks là lệnh shell tự động chạy khi có sự kiện trong Claude Code. Có 33 hook events trong 4 nhóm và 5 loại hook.
PreToolUse
Trước khi tool chạy (chặn/validate)
PostToolUse
Sau khi tool chạy (format, scan)
SessionStart
Khi bắt đầu phiên
UserPromptSubmit
Khi user gửi prompt
# Tạo script hook
mkdir -p ~/.claude/hooks
cat > ~/.claude/hooks/format-code.sh << 'EOF'
#!/bin/bash
# Format code sau khi ghi file
FILE="$1"
EXT="${FILE##*.}"
case "$EXT" in
js|ts|jsx|tsx) npx prettier --write "$FILE" 2>/dev/null ;;
py) black "$FILE" 2>/dev/null ;;
esac
EOF
chmod +x ~/.claude/hooks/format-code.sh
// Thêm vào ~/.claude/settings.json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/format-code.sh"
}
]
}
]
}
}
cat > ~/.claude/hooks/pre-bash-check.sh << 'EOF'
#!/bin/bash
# Chặn các lệnh nguy hiểm trước khi chạy
COMMAND=$(cat | jq -r '.tool_input.command')
if echo "$COMMAND" | grep -qE 'rm -rf /|DROP TABLE'; then
echo "Blocked dangerous command" >&2
exit 2 # exit code 2 = block tool
fi
exit 0
EOF
chmod +x ~/.claude/hooks/pre-bash-check.sh
# Cấu hình trong settings.json với event PreToolUse, matcher "Bash"
1. Có bao nhiêu loại hook trong Claude Code?
Model Context Protocol (MCP) cho phép Claude truy cập tools và API bên ngoài: GitHub, database, Slack, filesystem... Một khi cấu hình, tools của MCP server tự động khả dụng cho Claude.
Prompts từ MCP server xuất hiện dạng /mcp__<server>__<prompt>, ví dụ: /mcp__github__list_prs.
# Đặt environment variable
export GITHUB_TOKEN="your_github_token"
# Thêm MCP server
claude mcp add github -- npx -y @modelcontextprotocol/server-github
# Kiểm tra trong Claude Code
/mcp
# Sử dụng — Claude tự động dùng GitHub MCP khi cần
# hoặc gọi trực tiếp: /mcp__github__list_prs
Mục tiêu: Dùng MCP trong workflow thực tế.
1. Fetch một PR từ GitHub qua MCP
2. Nhờ Claude phân tích các file thay đổi
3. Tổng hợp thành review comment
# Ví dụ prompt:
"Fetch PR #42 từ repo hiện tại, phân tích
các thay đổi và đề xuất review comments"
1. MCP là viết tắt của gì?
Subagents là các AI assistant chuyên biệt với context riêng. Claude tự động ủy quyền công việc cho subagent phù hợp — giữ main conversation gọn gàng và tận dụng chuyên môn hóa.
Lưu trong .claude/agents/*.md — mỗi file định nghĩa một agent với prompt và tools riêng.
# Tạo thư mục agents
mkdir -p .claude/agents
# Tạo code-reviewer agent
cat > .claude/agents/code-reviewer.md << 'EOF'
---
name: code-reviewer
description: Review code chuyên sâu về bảo mật và hiệu suất
tools:
- Read
- Grep
- Glob
---
# Code Reviewer Agent
## Nhiệm Vụ
Review code được cung cấp và báo cáo:
1. **Vấn Đề Bảo Mật** — injection, auth, data exposure
2. **Vấn Đề Hiệu Suất** — complexity, memory leaks
3. **Đề Xuất Cải Thiện** — refactoring, best practices
## Output
Trả về báo cáo chi tiết kèm mức độ nghiêm trọng.
EOF
Workflow tích hợp hoàn chỉnh:
1. Dùng MCP fetch PR từ GitHub
2. Claude ủy quyền review cho code-reviewer subagent
3. Hook PostToolUse chạy tests tự động
4. Claude tổng hợp kết quả
# Prompt thử:
"Review PR #42 — dùng subagent phân tích
bảo mật và hiệu suất, rồi tổng hợp kết quả"
1. Subagent Explore có đặc điểm gì?
Các tính năng nâng cao cho power users: Planning Mode, Extended Thinking, Permission Modes, Background Tasks, Headless Mode...
/plan Implement user authentication system
Claude lập kế hoạch chi tiết trước khi viết code — bạn phê duyệt rồi mới thực hiện.
manual
Hỏi trước mỗi thao tác (mặc định)
acceptEdits
Tự động chấp nhận edit file
plan
Chỉ lập kế hoạch, không thay đổi
auto
Tự động thực hiện (có safety classifier)
dontAsk
Không hỏi permission
bypassPermissions
Bỏ qua mọi permission check
Nhấn Alt+T (hoặc Option+T trên macOS) để bật/tắt chế độ suy nghĩ sâu cho bài toán phức tạp.
low
Nhanh, ít chi tiết
medium
Cân bằng (mặc định trên model mới)
high
Chi tiết hơn
xhigh
Rất chi tiết
max
Tối đa
# Vào planning mode
/plan Implement REST API for user management
# Claude sẽ:
# 1. Phân tích yêu cầu
# 2. Lập kế hoạch chi tiết
# 3. Chờ bạn phê duyệt
# 4. Thực hiện theo kế hoạch
# Plan mode — chỉ lập kế hoạch
claude --permission-mode plan "analyze codebase"
# Accept edits — tự động chấp nhận sửa file
claude --permission-mode acceptEdits "refactor auth"
# Auto mode — tự động thực hiện
claude --permission-mode auto "implement feature"
# Chạy trong CI pipeline
claude -p "Run tests and generate report"
# Giới hạn số turns + JSON output
claude -p --max-turns 3 --output-format json "review code"
1. Phím tắt nào bật/tắt Extended Thinking?
Plugins đóng gói commands, skills, agents, MCP servers và hooks thành một giải pháp hoàn chỉnh — cài bằng một lệnh duy nhất. Lý tưởng để chuẩn hóa workflow cho cả team.
my-plugin/
├── plugin.json # Metadata
├── commands/ # Slash commands
├── skills/ # Skills
├── agents/ # Subagents
├── hooks/ # Hook scripts
└── mcp/ # MCP configs
# Xem danh sách plugins trong Claude Code
/plugin
# Cài đặt plugin
/plugin install pr-review
# Sử dụng command của plugin (namespace plugin:command)
/pr-review:review
# Tạo cấu trúc plugin
mkdir -p my-team-plugin/{commands,skills,agents}
# plugin.json
cat > my-team-plugin/plugin.json << 'EOF'
{
"name": "my-team-plugin",
"version": "1.0.0",
"description": "Chuẩn workflow của team: review + docs + tests"
}
EOF
# Thêm commands/skills/agents vào các thư mục tương ứng
# rồi chia sẻ qua git cho team
1. File nào chứa metadata của plugin?
/help — Trợ giúp/clear — Xóa hội thoại/model — Chọn model/compact — Nén context
/init — Tạo CLAUDE.md/memory — Chỉnh sửa memory@file — Import file
Esc+Esc — RewindAlt+T — Extended ThinkingCtrl+C — Dừng Claude
claude -p — Print modeclaude -r — Resume session--output-format json