# 📖 Hướng dẫn cài đặt AI Coding CLI Tools Hướng dẫn cài tay đầy đủ cho **tất cả 6 tools** được hỗ trợ trong AI Code Toolkits. > 💡 **Cách nhanh nhất:** Dùng tab **CLI Installer** trong GUI (`http://localhost:3456`) — nhấn Install là xong. > > Trang này dành cho ai muốn **cài tay** hoặc **chạy script tự động**. --- ## 📋 Tổng quan | Tool | Mô tả | Yêu cầu | Website | |------|--------|---------|---------| | **Claude Code** | Anthropic AI coding assistant | Node.js 18+ | [anthropic.com](https://docs.anthropic.com/claude-code) | | **Gemini CLI** | Google AI coding agent | Node.js 18+ | [github.com/google-gemini](https://github.com/google-gemini/gemini-cli) | | **OpenCode** | AI coding agent for terminal | curl / Node.js 18+ | [opencode.ai](https://opencode.ai) | | **Codex CLI** | OpenAI coding assistant | Node.js 22+ | [github.com/openai/codex](https://github.com/openai/codex) | | **Kiro CLI** | AWS AI coding assistant | curl (Linux/macOS) | [kiro.dev](https://kiro.dev) | | **Aider** | AI pair programming | Python 3.9+ | [aider.chat](https://aider.chat) | --- ## ⚡ SCRIPT TỰ ĐỘNG — Copy dán 1 phát ### Windows (PowerShell — chạy với quyền Admin) ```powershell # =============================================== # AI Code Toolkits — Auto Install All CLI Tools # Windows PowerShell (Admin) # =============================================== Write-Host "`n⚡ AI Code Toolkits — Installing CLI Tools...`n" -ForegroundColor Cyan # --- Check Node.js --- $node = Get-Command node -ErrorAction SilentlyContinue if (-not $node) { Write-Host "[SKIP] Node.js chưa cài — bỏ qua npm tools" -ForegroundColor Yellow Write-Host " Cài Node.js: https://nodejs.org/en/download/" -ForegroundColor Gray } else { $v = (node --version) -replace 'v','' -split '\.' | Select-Object -First 1 # Claude Code Write-Host "[1/4] Claude Code..." -ForegroundColor White npm install -g @anthropic-ai/claude-code 2>$null Write-Host " Done" -ForegroundColor Green # Gemini CLI Write-Host "[2/4] Gemini CLI..." -ForegroundColor White npm install -g @google/gemini-cli 2>$null Write-Host " Done" -ForegroundColor Green # OpenCode Write-Host "[3/4] OpenCode..." -ForegroundColor White npm install -g opencode-ai 2>$null Write-Host " Done" -ForegroundColor Green # Codex CLI (cần Node 22+) if ([int]$v -ge 22) { Write-Host "[4/4] Codex CLI..." -ForegroundColor White npm install -g @openai/codex 2>$null Write-Host " Done" -ForegroundColor Green } else { Write-Host "[4/4] Codex CLI — cần Node 22+ (hiện: v$v) — SKIP" -ForegroundColor Yellow } } # --- Aider (Python) --- $pip = Get-Command pip -ErrorAction SilentlyContinue if ($pip) { Write-Host "[5] Aider..." -ForegroundColor White pip install aider-chat 2>$null Write-Host " Done" -ForegroundColor Green } else { Write-Host "[5] Aider — cần Python+pip — SKIP" -ForegroundColor Yellow } # --- Kiro (không hỗ trợ Windows native) --- Write-Host "[6] Kiro CLI — chỉ hỗ trợ Linux/macOS (hoặc dùng WSL)" -ForegroundColor Yellow Write-Host "`n✅ Hoàn tất! Kiểm tra:" -ForegroundColor Green Write-Host " claude --version" Write-Host " gemini --version" Write-Host " opencode --version" Write-Host " codex --version" Write-Host " aider --version" ``` ### macOS / Linux (Bash — copy dán vào terminal) ```bash #!/usr/bin/env bash # =============================================== # AI Code Toolkits — Auto Install All CLI Tools # macOS / Linux (Ubuntu, Debian, Fedora...) # =============================================== set -e echo "" echo "⚡ AI Code Toolkits — Installing CLI Tools..." echo "" # --- System update (Linux only) --- if command -v apt &> /dev/null; then echo "[0] Updating system..." sudo apt update -y && sudo apt install -y curl git fi # --- Node.js tools --- if command -v node &> /dev/null; then NODE_VER=$(node --version | sed 's/v//' | cut -d. -f1) echo "[1/4] Claude Code..." npm install -g @anthropic-ai/claude-code echo " ✅ Done" echo "[2/4] Gemini CLI..." npm install -g @google/gemini-cli echo " ✅ Done" echo "[3/4] OpenCode (official installer)..." curl -fsSL https://opencode.ai/install | bash source ~/.bashrc 2>/dev/null || source ~/.zshrc 2>/dev/null || true echo " ✅ Done" if [ "$NODE_VER" -ge 22 ]; then echo "[4/4] Codex CLI..." npm install -g @openai/codex echo " ✅ Done" else echo "[4/4] Codex CLI — cần Node 22+ (hiện: v$NODE_VER) — SKIP" fi else echo "[SKIP] Node.js chưa cài — bỏ qua npm tools" echo " Cài: curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt install -y nodejs" fi # --- Kiro CLI --- echo "[5] Kiro CLI..." curl -fsSL https://cli.kiro.dev/install | bash source ~/.bashrc 2>/dev/null || source ~/.zshrc 2>/dev/null || true echo " ✅ Done" # --- Aider (Python) --- if command -v pip3 &> /dev/null; then echo "[6] Aider..." pip3 install aider-chat echo " ✅ Done" elif command -v pip &> /dev/null; then echo "[6] Aider..." pip install aider-chat echo " ✅ Done" else echo "[6] Aider — cần Python+pip — SKIP" fi echo "" echo "✅ Hoàn tất! Kiểm tra:" echo " claude --version" echo " gemini --version" echo " opencode --version" echo " codex --version" echo " kiro --version" echo " aider --version" ``` --- ## 🔧 HƯỚNG DẪN CÀI TAY TỪNG TOOL --- ### 1. Claude Code (Anthropic) **Mô tả:** AI coding assistant chính thức của Anthropic. Hỗ trợ đọc/sửa code, chạy terminal, tạo project. | OS | Lệnh | |----|-------| | Windows | `npm install -g @anthropic-ai/claude-code` | | macOS | `npm install -g @anthropic-ai/claude-code` | | Linux | `npm install -g @anthropic-ai/claude-code` | **Sau khi cài:** ```bash claude # Mở interactive mode claude "tạo api nodejs crud" # Chạy prompt trực tiếp claude --version # Kiểm tra version ``` **Login:** Chạy `claude` lần đầu → đăng nhập Anthropic account hoặc nhập API key. --- ### 2. Gemini CLI (Google) **Mô tả:** AI coding agent của Google, dùng model Gemini. Free 60 req/phút với Google account. | OS | Lệnh | |----|-------| | Windows | `npm install -g @google/gemini-cli` | | macOS | `npm install -g @google/gemini-cli` | | Linux | `npm install -g @google/gemini-cli` | **Sau khi cài:** ```bash gemini # Mở interactive mode gemini --version # Kiểm tra version ``` **Login:** Chạy `gemini` lần đầu → đăng nhập Google account → được free tier (60 req/min, 1000 req/day). --- ### 3. OpenCode **Mô tả:** AI coding agent mạnh cho terminal. Hỗ trợ nhiều AI provider (OpenAI, Claude, Gemini, local models). | OS | Cách cài (khuyên dùng) | Cách 2 (npm) | |----|----------------------|-------------| | Windows | `npm install -g opencode-ai` | — | | macOS | `curl -fsSL https://opencode.ai/install \| bash` | `npm install -g opencode-ai` | | Linux | `curl -fsSL https://opencode.ai/install \| bash` | `npm install -g opencode-ai` | **⚠️ Quan trọng (Linux/macOS):** Sau khi cài bằng curl, chạy: ```bash source ~/.bashrc # hoặc source ~/.zshrc ``` **Sau khi cài:** ```bash opencode # Mở TUI (terminal UI) opencode --version # Kiểm tra version ``` **Bước quan trọng — Kết nối AI provider:** ``` # Trong OpenCode, gõ: /connect # → Chọn provider (OpenAI / Claude / Gemini) # → Nhập API key ``` **Chạy nâng cao:** ```bash opencode run "viết api nodejs crud" # Chạy prompt không cần UI opencode --port 4096 # Chạy server mode ``` --- ### 4. Codex CLI (OpenAI) **Mô tả:** AI coding assistant của OpenAI. Yêu cầu **Node.js 22+**. | OS | Lệnh | |----|-------| | Windows | `npm install -g @openai/codex` | | macOS | `npm install -g @openai/codex` | | Linux | `npm install -g @openai/codex` | **⚠️ Yêu cầu:** Node.js **22 trở lên** (không chạy được trên Node 18/20). **Sau khi cài:** ```bash codex # Mở interactive mode codex "fix bug this function" # Chạy prompt trực tiếp codex --version # Kiểm tra version ``` **Login:** Cần set `OPENAI_API_KEY`: ```bash export OPENAI_API_KEY="sk-..." # Linux/macOS $env:OPENAI_API_KEY="sk-..." # Windows PowerShell ``` --- ### 5. Kiro CLI (AWS) **Mô tả:** AI coding assistant của Amazon Web Services. Chỉ hỗ trợ Linux/macOS. | OS | Lệnh | |----|-------| | Windows | ❌ Không hỗ trợ (dùng WSL) | | macOS | `curl -fsSL https://cli.kiro.dev/install \| bash` | | Linux | `curl -fsSL https://cli.kiro.dev/install \| bash` | **Windows (qua WSL):** ```powershell # 1. Cài WSL wsl --install # 2. Mở Ubuntu terminal, chạy: curl -fsSL https://cli.kiro.dev/install | bash source ~/.bashrc ``` **Sau khi cài:** ```bash kiro # Mở interactive mode kiro --version # Kiểm tra version ``` **Login:** Cần AWS account. Chạy `kiro` lần đầu → đăng nhập. --- ### 6. Aider **Mô tả:** AI pair programming tool. Hỗ trợ nhiều model, tự commit git, chỉnh sửa nhiều file cùng lúc. | OS | Cách 1 (khuyên dùng) | Cách 2 | |----|---------------------|--------| | Windows | `pip install aider-chat` | `python -m pip install aider-chat` | | macOS | `pip3 install aider-chat` | `brew install aider` | | Linux | `pip3 install aider-chat` | `curl -fsSL https://aider.chat/install.sh \| bash` | **⚠️ Yêu cầu:** Python 3.9+ **Sau khi cài:** ```bash aider # Mở interactive mode (trong git repo) aider --model claude-3.5-sonnet # Chọn model aider --version # Kiểm tra version ``` **Login:** Cần set API key cho model bạn muốn dùng: ```bash export ANTHROPIC_API_KEY="sk-..." # Dùng Claude export OPENAI_API_KEY="sk-..." # Dùng OpenAI ``` --- ## ❗ Lỗi thường gặp | Lỗi | Nguyên nhân | Cách fix | |-----|-------------|----------| | `command not found` | Chưa thêm PATH | `source ~/.bashrc` hoặc restart terminal | | `EACCES permission denied` | Thiếu quyền npm global | Dùng `sudo npm install -g ...` hoặc fix npm permissions | | `Node.js version not supported` | Node quá cũ | Cập nhật Node.js: `nvm install 22` | | `pip: command not found` | Chưa cài Python | Cài Python: `sudo apt install python3 python3-pip` | | `OPENAI_API_KEY not set` | Chưa đăng nhập | Set API key theo hướng dẫn mỗi tool | --- ## 🔑 Tổng hợp API Keys | Tool | Cần gì | Cách lấy | |------|--------|---------| | **Claude Code** | Anthropic account/key | [console.anthropic.com](https://console.anthropic.com) | | **Gemini CLI** | Google account (free) | Đăng nhập lần đầu chạy | | **OpenCode** | Tùy provider | `/connect` trong app | | **Codex CLI** | OpenAI API key | [platform.openai.com](https://platform.openai.com/api-keys) | | **Kiro CLI** | AWS account | Đăng nhập lần đầu chạy | | **Aider** | Tùy model (Claude/OpenAI/Gemini) | Set `ANTHROPIC_API_KEY` hoặc `OPENAI_API_KEY` |