The Claude Code CLI is the primary interface for interacting with Claude. Understanding commands and options helps you work more efficiently.
Claude Code CLI là giao diện chính để tương tác với Claude. Hiểu rõ các lệnh và tùy chọn giúp bạn làm việc hiệu quả hơn.
1# Start interactive session in current directory2claude34# Start with an initial prompt5claude "explain this codebase"67# Start in a specific directory8claude --cwd /path/to/project910# Resume last session11claude --resume1213# Start with a specific model14claude --model opusClaude Code supports multiple models with different characteristics. Choose the appropriate model for your task to optimize cost and quality.
Claude Code hỗ trợ nhiều model với các đặc điểm khác nhau. Chọn model phù hợp với tác vụ để tối ưu chi phí và chất lượng.
1# Use Opus (most capable, best for complex tasks)2claude --model opus34# Use Sonnet (balanced, good for most tasks)5claude --model sonnet67# Use Haiku (fastest, cheapest, good for simple tasks)8claude --model haiku910# Short aliases11claude -m opus12claude -m sonnet13claude -m haikuControl what Claude is allowed to do automatically. Different modes provide different levels of automation.
Kiểm soát những gì Claude được phép làm tự động. Các mode khác nhau cung cấp mức độ tự động hóa khác nhau.
1# Default mode - asks for permission on risky actions2claude34# Auto mode - automatically approve safe actions5claude --mode auto67# Plan mode - requires approval before execution8claude --mode plan910# Bypass mode - skip all permission prompts (use carefully!)11claude --dangerously-skip-permissionsMode bypass rất nguy hiểm vì Claude có thể thực hiện bất kỳ tác vụ nào mà không cần xác nhận. Chỉ sử dụng khi bạn hoàn toàn tin tưởng vào những gì Claude sẽ làm.
1# Print output in JSON format (for scripting)2claude --print "list all files" --output-format json34# Stream output (see responses as they generate)5claude --stream67# Quiet mode (minimal output)8claude -q "fix the bug"910# Verbose mode (detailed logging)11claude -v "explain this"In an interactive session, you can use slash commands to perform special tasks.
Trong session tương tác, bạn có thể sử dụng slash commands để thực hiện các tác vụ đặc biệt.
1# Get help2/help34# Clear conversation history5/clear67# Exit the session8/exit910# Change model mid-session11/model opus12Claude Code can be integrated into shell scripts and pipelines to automate tasks.
Claude Code có thể được tích hợp vào shell scripts và pipelines để tự động hóa các tác vụ.
1# Pipe file content to Claude2cat error.log | claude "explain this error"34# Use in scripts5OUTPUT=$(claude --print "generate a random UUID")6echo $OUTPUT78# Process multiple files9for file in src/*.ts; do10 claude --print "review $file for bugs"11done1213# Combine with other tools14git diff | claude "write a commit message for these changes"1516# CI/CD integration17claude --print --mode auto "run all tests and fix failures"Claude Code reads configuration from multiple sources with a defined priority order.
Claude Code đọc cấu hình từ nhiều nguồn với thứ tự ưu tiên xác định.
1# Configuration priority (highest to lowest):2# 1. Command line flags3# 2. Environment variables4# 3. Project .claude/settings.json5# 4. User ~/.claude/settings.json67# Example user settings8# ~/.claude/settings.json9{10 "model": "sonnet",11 "theme": "dark",12 "autoApprove": ["read", "glob", "grep"],1# API key (required if not logged in)2export ANTHROPIC_API_KEY="sk-ant-..."34# Default model5export CLAUDE_MODEL="opus"67# Disable telemetry8export CLAUDE_DISABLE_TELEMETRY="1"910# Custom config directory11export CLAUDE_CONFIG_DIR="/path/to/config"1213# Debug mode14export CLAUDE_DEBUG="1"- Use Ctrl+R to search through command history.
Sử dụng Ctrl+R để tìm kiếm trong lịch sử lệnh đã chạy.
- Add alias to shell profile: alias c='claude' for faster typing.
Thêm alias vào shell profile: alias c='claude' để gõ nhanh hơn.
- Use --resume to continue previous session, keeping context.
Sử dụng --resume để tiếp tục session trước, giữ nguyên context.
- Combine with tmux to run multiple Claude sessions in parallel.
Kết hợp với tmux để chạy nhiều Claude session song song.
- Use /fast to toggle between fast and detailed output.
Sử dụng /fast để chuyển đổi giữa output nhanh và chi tiết.
1# Useful aliases for .bashrc/.zshrc2alias c="claude"3alias cr="claude --resume"4alias co="claude --model opus"5alias ch="claude --model haiku"6alias cq="claude -q"78# Quick explain function9explain() {10 cat "$1" | claude "explain this code"11}1213# Quick fix function14fix() {15 claude --mode auto "fix all errors in $1"16}Key Takeaways
Điểm Chính
- Use --model to select opus/sonnet/haiku based on task complexitySử dụng --model để chọn opus/sonnet/haiku tùy theo độ phức tạp
- Permission modes control automation level (auto, plan, default)Permission modes kiểm soát mức độ tự động (auto, plan, default)
- Slash commands provide quick actions in interactive modeSlash commands cung cấp các action nhanh trong chế độ tương tác
- CLI integrates with scripts and pipelines for automationCLI tích hợp với scripts và pipelines để tự động hóa
Practice
Test your understanding of this chapter
Which model is best for complex architectural decisions?
Model nào tốt nhất cho các quyết định kiến trúc phức tạp?
The --resume flag starts a new session with the same model.
Flag --resume bắt đầu session mới với cùng model.
Complete the command to start Claude in auto-approve mode
Hoàn thành lệnh để khởi động Claude với chế độ auto-approve
claude --mode What is the slash command to clear conversation history?
Slash command để xóa lịch sử hội thoại là gì?