Giao diện
8. Cheat sheet
Lệnh và file hay dùng, đối chiếu với Claude Code 2.1.310 (claude --help, claude plugin --help) và docs chính thức ngày 24/10/2026. Giải thích chi tiết nằm ở các chương trước.
Khởi động và mode
| Việc | Lệnh |
|---|---|
| Mở phiên tương tác | claude |
| Xem phiên bản | claude --version |
| Khởi động với mode cụ thể | claude --permission-mode manual|acceptEdits|plan|auto|dontAsk|bypassPermissions |
| Đổi mode trong phiên | Shift+Tab (xoay vòng) |
| Tiếp tục phiên gần nhất / chọn phiên | claude -c / claude -r |
| Phiên mới trong worktree riêng | claude -w <tên> |
| Chạy nền | claude --bg "task" |
| Xem mọi phiên (agent view) | claude agents |
| Phiên trên cloud | claude --cloud "task" |
| Chọn model / effort | --model <model> / --effort low|medium|high|xhigh|max |
Mặc định lâu dài: permissions.defaultMode trong settings. Thứ tự ưu tiên: flag > defaultMode > mặc định có sẵn. "auto" trong .claude/settings.json của dự án bị bỏ qua.
Plugin
| Việc | Trong phiên | Từ terminal |
|---|---|---|
| Thêm marketplace | /plugin marketplace add owner/repo | claude plugin marketplace add owner/repo |
| Cài plugin | /plugin install <plugin>@<marketplace> (mở panel chọn scope) | claude plugin install <plugin>@<marketplace> (mặc định scope user) |
| Bật / tắt | /plugin enable <plugin>@<marketplace> | claude plugin enable|disable <plugin> |
| Liệt kê / cập nhật | claude plugin list / claude plugin update <plugin> | |
| Xem thành phần, chi phí token | claude plugin details <plugin> | |
| Bật You Should Know | /plugin enable cc-plugin-you-should-know@builtin |
Marketplace chính thức claude-plugins-official tự có ở phiên tương tác đầu tiên. Trong CI: claude plugin marketplace add anthropics/claude-plugins-official.
Plugin dùng trong khóa học:
text
/plugin install superpowers@claude-plugins-official
/plugin install ralph-loop@claude-plugins-official
/plugin enable cc-plugin-you-should-know@builtinMCP
| Việc | Lệnh |
|---|---|
| Thêm server chạy bằng lệnh (stdio) | claude mcp add <name> -- <cmd> [args] |
| Thêm server HTTP | claude mcp add --transport http <name> <url> |
| Chọn scope | --scope local|project|user (mặc định local; project ghi vào .mcp.json) |
| Liệt kê | claude mcp list |
--transport sse đã deprecated.
Headless
| Việc | Lệnh / cờ |
|---|---|
| Chạy một lệnh rồi thoát | claude -p "..." |
| Định dạng output | --output-format text|json|stream-json |
| Cho phép tool cụ thể | --allowedTools "Read,Edit,Bash(bun test*)" |
| Chọn mode (mặc định Manual) | --permission-mode auto |
| Giới hạn số lượt | --max-turns N |
| Giới hạn tiền | --max-budget-usd <số> (chỉ với -p) |
| Không ai trả lời hỏi quyền | --permission-prompts none (chỉ với -p; tự từ chối mọi thứ cần hỏi) |
| Tiếp tục phiên | --continue / --resume <id> |
| Chế độ tối giản cho CI | --bare |
--bare bỏ qua hook
Theo claude --help, --bare bỏ qua hook (trong settings và plugin), plugin sync, auto-memory và tự tìm CLAUDE.md. Chạy starter bằng --bare thì mất hai hook rào chắn. Chỉ dùng khi bạn tự truyền đủ ngữ cảnh và chấp nhận điều đó.
GitHub Actions: anthropics/claude-code-action@v1; cài nhanh trong phiên bằng /install-github-app.
Vòng lặp và lịch
| Việc | Lệnh |
|---|---|
| Bắt đầu Ralph loop | /ralph-loop "<prompt>" --max-iterations N --completion-promise "TEXT" |
| Agent báo xong | in <promise>TEXT</promise> |
| Xem vòng hiện tại | head -10 .claude/ralph-loop.local.md |
| Hủy Ralph loop | /cancel-ralph |
| Tạo / quản lý scheduled task | /schedule, /schedule list|update|run (alias /routines) |
| Codex: vòng tới khi xong | /goal <mục tiêu>, /goal pause|resume|clear |
Biến môi trường
| Biến | Tác dụng |
|---|---|
CLAUDE_CODE_STOP_HOOK_BLOCK_CAP | Nâng giới hạn 8 lần tiếp tục liên tiếp của Stop hook |
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 | Bật agent teams (experimental) |
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 | Tắt subagent chạy nền |
CLAUDE_CODE_FORK_SUBAGENT=0 | Tắt fork mode |
CLAUDE_PROJECT_DIR | (trong hook) gốc dự án |
File cấu hình
| File | Dùng cho |
|---|---|
CLAUDE.md | Hướng dẫn dự án cho Claude Code; @AGENTS.md để nạp file dùng chung |
AGENTS.md | Hướng dẫn dùng chung cho mọi agent (Codex đọc trực tiếp) |
.claude/settings.json | Quyền (permissions.allow), hook (hooks), plugin (enabledPlugins) của dự án |
.claude/skills/<name>/SKILL.md | Skill của dự án |
.claude/agents/ | Subagent của dự án (bắt buộc name, description) |
.mcp.json | MCP server scope project |
~/.claude/settings.json | Settings cá nhân |
~/.codex/config.toml | Config Codex (MCP, approval, sandbox) |
.agents/skills/ | Skill của dự án cho Codex |
Khung .claude/settings.json (rút từ starter):
json
{
"permissions": { "allow": ["Bash(bun test*)", "Bash(git diff*)"] },
"hooks": {
"PreToolUse": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "bun", "args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/block-secrets.ts"] }] }]
},
"enabledPlugins": { "superpowers@claude-plugins-official": true }
}Hook: exit 0 cho qua, exit 2 chặn (stderr đưa lại cho Claude), mã khác kể cả 1 không chặn.
Dự án lab
| Việc | Lệnh |
|---|---|
| Cài dependency | bun install |
| Chạy app (web 3001, server 3000) | bun run dev |
| Kiểm tra kiểu | bun run check-types |
| Chạy test | bun test |
| Đẩy schema DB | bun run db:push |
Codex nhanh
| Việc | Lệnh |
|---|---|
| Headless | codex exec |
| Thêm MCP | codex mcp add <name> -- <cmd> |
| Plugin | /plugins |
| Gọi skill | $skill-name hoặc /skills |
| Sandbox + approval | --sandbox workspace-write --ask-for-approval on-request |
| Để agent duyệt thay | --approve-for-me (từ codex 0.147.0; bản cũ: -c approvals_reviewer=auto_review) |
Nguồn
- CLI reference: https://code.claude.com/docs/en/cli-reference
- Permission modes: https://code.claude.com/docs/en/permission-modes
- Headless: https://code.claude.com/docs/en/headless
- Plugins: https://code.claude.com/docs/en/discover-plugins
- MCP: https://code.claude.com/docs/en/mcp
- Hooks: https://code.claude.com/docs/en/hooks
- Scheduled tasks: https://code.claude.com/docs/en/routines
- GitHub Actions: https://code.claude.com/docs/en/github-actions
- Ralph loop plugin: https://github.com/anthropics/claude-plugins-official/tree/main/plugins/ralph-loop
- Codex sandbox: https://learn.chatgpt.com/docs/sandboxing.md
- Codex auto-review: https://learn.chatgpt.com/docs/sandboxing/auto-review.md
- Codex MCP: https://learn.chatgpt.com/docs/extend/mcp.md
- Lệnh
claude --help,claude plugin --help(Claude Code 2.1.310, chạy ngày 24/10/2026)