Claude Code Cheatsheet (2026)

Tài liệu tổng hợp nhanh các lệnh, workflow và mẹo dùng [Claude Code Docs](https://code.claude.com/docs/en/commands) và CLI thực chiến.

1. Cài đặt

Install

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

Update

claude update

Kiểm tra cài đặt

claude doctor

2. Chạy Claude Code

Interactive mode

claude

Mở phiên làm việc tương tác trong terminal.


Start với prompt ban đầu


One-shot mode

Chạy 1 lần rồi thoát.

Rất hữu ích cho:

  • scripting

  • CI/CD

  • automation

  • shell pipeline


Pipe dữ liệu vào Claude


3. Session Management

Continue phiên gần nhất

Continue + prompt mới

Resume bằng session ID

Export conversation

Hoặc:


4. Slash Commands Quan Trọng

/help

Hiển thị toàn bộ commands.


/clear

Xoá toàn bộ conversation context.

Alias:

  • /reset

  • /new


/compact

Compress context hiện tại.

Tác dụng:

  • giảm token usage

  • giữ summary quan trọng

  • tránh full context window

Có thể thêm hướng dẫn:


/btw

Hỏi câu phụ mà không pollute main context.

Ví dụ:


/init

Cho Claude scan repo và tạo:

Rất nên chạy khi vào project mới.


/memory

Quản lý project memory.

Thường dùng để refine:

  • coding conventions

  • architecture

  • workflow

  • commands


/permissions

Cấu hình permission behavior.

Useful khi:

  • cho phép auto edit

  • auto run commands

  • sandbox setup


/agents

Quản lý subagents / agent configs.


/mcp

Quản lý MCP servers.


/diff

Mở interactive diff viewer.

Cho phép:

  • xem file changes

  • xem per-turn diffs

  • inspect generated edits


/doctor

Diagnose installation và environment.


/sandbox

Toggle sandbox mode.


/security-review

Review security vulnerabilities trong diff hiện tại.

Useful trước khi merge PR.


6. Shell Mode

Chạy shell command trực tiếp

Dùng ! để execute shell command mà không cần thoát Claude.


7. MCP (Model Context Protocol)

Kiểm tra danh sách MCP hiện có

Thêm MCP server qua HTTP

Xoá MCP server

Xác thực bằng API Key

Xác thực bằng username/password


8. CLAUDE.md Best Practices

CLAUDE.md là gì?

Persistent project memory.

Claude sẽ load file này khi vào repo.


Nên chứa gì?

Project structure


Coding conventions


Useful commands


Workflow


9. Workflow Khuyên Dùng

Khi vào repo mới

Sau đó:


Khi context dài


Khi Claude bắt đầu “ngu”

Rồi restate task ngắn gọn.


Với task lớn

Chia phase:


Với refactor nguy hiểm

Yêu cầu:


10. Tips Thực Chiến

1. Prompt tốt hơn

Bad:

Good:


2. Luôn yêu cầu plan trước


3. Hạn chế hallucination


4. Force search trước khi edit


5. Với monorepo

Add extra dirs:


11. Automation Examples

Git diff review


Generate commit message


Analyze logs


Generate release notes


12. Context Window Tips

Context gồm:

  • prompts

  • responses

  • opened files

  • command outputs

  • tool calls

Khi đầy:

  • Claude sẽ compact

  • hoặc quên context cũ

Dùng:

  • /compact

  • /clear

  • task decomposition


Small fix


Feature lớn


Safe refactor


14. Tài liệu chính thức

Cập nhật lần cuối