For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

Chỉnh cấu hình settings.json

  • pre-tool hook

  • status line live


2. Chạy Claude Code

Interactive mode

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.

Thêm MCP server

Add server vào workspace hiện tại:

  • **Ví dụ:

    • Thêm slim-tools server:

    • Thêm Atlassian MCP server với HTTP transport và API token:

    • Thêm với username/password:

Xoá MCP server

Remove server khỏi workspace hiện tại:

  • Ví dụ:

Kiểm tra MCP server

Xem danh sách MCP server đã add:

Lưu ý: Nếu hiện Needs authentication khi add Atlassian MCP server, server chính thức (mcp.atlassian.com) chỉ hỗ trợ OAuth, không nhận API token trực tiếp. Cần dùng MCP server thay thế hỗ trợ API token.


/diff

Mở interactive diff viewer trong terminal.

Cho phép:

  • xem file changes — toàn bộ file đã sửa trong session

  • per-turn diffs — xem thay đổi theo từng turn

  • inspect generated edits — kiểm tra diff trước khi apply

  • staged diffs — xem changes đã stage cho commit

Phím tắt trong diff viewer:

  • j/k — điều hướng lên/xuống

  • q — đóng viewer

  • / — search trong diff

Hữu ích để review trước khi commit hoặc kiểm tra Claude đã sửa đúng chưa.


/doctor

Diagnose installation và environment. Tương tự claude doctor CLI.

Kiểm tra:

  • Node.js version — có đúng runtime không

  • CLI installation — claude-code binary có hoạt động không

  • Git config — user.name, user.email đã set chưa

  • MCP servers — kiểm tra kết nối các MCP server đã add

  • Permissions — sandbox mode, file permissions

  • Disk space — đủ cho context cache

  • Proxy/Network — nếu dùng qua corporate network

Dùng khi:

  • Claude không khởi động được

  • MCP server báo lỗi kết nối

  • Cần debug environment trước khi report issue


/sandbox

Toggle sandbox mode.


/security-review

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

Công cụ này chỉ hoạt động với các diff mới được tạo ra (ví dụ: sau git diff hoặc ngay trước khi commit).

Nó sẽ scan code diff để tìm các lỗ hổng tiềm ẩn như:

  • Injection vulnerabilities: SQL injection, Command injection, XSS.

  • Sensitive data exposure: Credentials, API keys bị lộ.

  • Insecure Deserialization.

  • Use of insecure or outdated libraries.

  • Hardcoded secrets.

Dùng trước khi:

  • Commit code mới

  • Tạo Pull Request

  • Push code lên production


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

Atlassian MCP — API Token (HTTP transport)

Cài Atlassian MCP server dùng HTTP transport thay vì SSE:

Thay your-*****@gmail.comyour-api-token bằng thông tin thực. Ví dụ:

Windows PowerShell — base64

Trên PowerShell, lệnh base64 khác:

Kiểm tra

Lưu ý: Nếu hiện Needs authentication, Atlassian MCP server chính thức (mcp.atlassian.com) chỉ hỗ trợ OAuth, không nhận API token trực tiếp. Trong trường hợp đó cần dùng MCP server thay thế hỗ trợ API token.


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