Claude Code 安裝指南
Claude Code 是 Anthropic 官方推出的 AI 輔助程式開發工具,整合了先進的 Claude 模型和強大的開發功能,讓開發者能夠更高效地編寫程式碼、除錯和學習。
平台特色
Claude Code 是 Anthropic 官方的原生開發工具,提供:
- 🤖 先進的 AI 能力:使用最新的 Claude 5 模型
- 🔌 深度 IDE 整合:VSCode、JetBrains 等主流編輯器
- 🛠️ 完整的開發工具鏈:從編寫到測試到部署
- 📚 豐富的技能系統:Superpowers 技能生態支援
- 🌐 跨平台支援:macOS、Linux、Windows
系統需求
硬體需求
- 處理器:x64_64 或 ARM64 架構
- 記憶體:至少 4 GB RAM(建議 8 GB 以上)
- 硬碟空間:至少 500 MB 可用空間
軟體需求
- 作業系統:
- macOS 11+ (Big Sur 或更高版本)
- Linux(Ubuntu 20.04+、Debian 11+、Fedora 35+)
- Windows 10/11(使用 WSL2)
- 網路:穩定的網際網路連線
- 套件管理員:
- macOS:Homebrew
- Linux:系統套件管理器(apt、yum、dnf 等)
- Windows:WSL2 + apt
安裝步驟
macOS 安裝
# 第 1 步:使用 Homebrew 安裝
brew install claude-ai/tap/claude-code
# 第 2 步:驗證安裝
claude-code --version
# 第 3 步:初始化配置
claude-code init
# 第 4 步:登入 Anthropic 帳號
claude-code login
Linux 安裝
# 第 1 步:下載安裝腳本
curl -fsSL https://install.anthropic.com | sh
# 第 2 步:將 Claude Code 加入 PATH
echo 'export PATH="$HOME/.claude-code/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# 第 3 步:驗證安裝
claude-code --version
# 第 4 步:初始化配置
claude-code init
# 第 5 步:登入 Anthropic 帳號
claude-code login
Windows 安裝(WSL2)
# 第 1 步:確保 WSL2 已安裝
wsl --install
# 第 2 步:在 WSL2 中執行 Linux 安裝步驟
curl -fsSL https://install.anthropic.com | sh
# 第 3 步:配置 PATH
echo 'export PATH="$HOME/.claude-code/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# 第 4 步:驗證安裝
claude-code --version
# 第 5 步:初始化配置
claude-code init
配置設定
基礎配置
初始化後會建立配置檔案:
# 配置檔案位置
~/.claude-code/config.json
預設配置:
{
"model": "claude-fable-5",
"maxTokens": 200000,
"temperature": 0.7,
"editor": "code",
"theme": "dark",
"skillsPath": "~/.claude-code/skills"
}
環境變數配置
# 設定 API 金鑰
export ANTHROPIC_API_KEY="your-api-key"
# 設定預設模型
export CLAUDE_DEFAULT_MODEL="claude-fable-5"
# 設定最大 Token 數
export CLAUDE_MAX_TOKENS="200000"
# 設定輸出格式
export CLAUDE_OUTPUT_FORMAT="markdown"
專案配置
在專案根目錄建立 .claude/ 目錄:
# 建立專案配置目錄
mkdir .claude
touch .claude/config.json
專案配置範例:
{
"model": "claude-fable-5",
"contextFiles": [
"README.md",
"CLAUDE.md",
"package.json"
],
"ignorePatterns": [
"node_modules",
"dist",
"build",
".git"
],
"skills": [
"test-driven-development",
"systematic-debugging",
"verification-before-completion"
]
}
使用方式
CLI 使用
# 啟動 Claude Code
claude-code
# 在對話中使用 Superpowers 技能
claude-code> 使用 brainstorming skill 探索使用者認證的實作方式
# 直接執行特定技能
claude-code --skill test-driven-development 開發購物車功能
# 批次處理檔案
claude-code --batch src/**/*.ts
# 互動式模式
claude-code --interactive
IDE 整合
VSCode 整合
# 安裝 VSCode 擴展
code --install-extension anthropic.claude-code
# 或在 VSCode 中搜尋 "Claude Code" 安裝
VSCode 功能:
- 內建聊天面板
- 程式碼解釋和生成
- 自動完成和建議
- 錯誤診斷和修復
JetBrains 整合
# 在 JetBrains IDE 中
# 1. 開啟 Settings
# 2. 選擇 Plugins
# 3. 搜尋 "Claude Code"
# 4. 安裝並重啟 IDE
Superpowers 技能支援
Claude Code 原生支援 Superpowers 技能系統:
內建技能
# 查看可用技能
claude-code skills list
# 使用技能
claude-code skills run brainstorming "探索微服務架構設計"
# 查看技能詳情
claude-code skills info test-driven-development
# 組合多個技能
claude-code skills chain "writing-plans -> test-driven-development -> verification"
自訂技能
# 建立自訂技能目錄
mkdir -p ~/.claude-code/skills/my-skills
# 建立技能定義檔案
cat > ~/.claude-code/skills/my-skills/my-workflow.md << 'EOF'
---
name: my-workflow
description: 我的專屬工作流程
---
## 使用時機
當需要處理特定類型的任務時
## 執行步驟
1. 分析需求
2. 制定計畫
3. 執行實作
4. 驗證結果
EOF
# 重新載入技能
claude-code skills reload
常見問題
安裝問題
Q1: macOS 安裝時遇到 “Permission denied”
A:
# 解決方案:使用 sudo 安裝
sudo brew install claude-ai/tap/claude-code
# 或手動設定權限
sudo chown -R $(whoami) /usr/local/bin/claude-code
Q2: Linux 安裝後無法執行
A:
# 檢查 PATH 設定
echo $PATH | grep claude-code
# 如果沒有,重新加入 PATH
export PATH="$HOME/.claude-code/bin:$PATH"
echo 'export PATH="$HOME/.claude-code/bin:$PATH"' >> ~/.bashrc
Q3: Windows WSL2 安裝失敗
A:
# 確保 WSL2 版本正確
wsl --list --verbose
# 更新 WSL2
wsl --update
# 重新執行安裝
curl -fsSL https://install.anthropic.com | sh
配置問題
Q4: API 金鑰設定失敗
A:
# 直接設定 API 金鑰
claude-code config set api-key YOUR_API_KEY
# 或透過環境變數
export ANTHROPIC_API_KEY="your-api-key"
# 驗證設定
claude-code config get api-key
Q5: 技能無法載入
A:
# 檢查技能目錄
ls -la ~/.claude-code/skills/
# 重新載入技能
claude-code skills reload
# 檢查技能語法
claude-code skills validate
使用問題
Q6: 回應速度慢
A:
# 調整 maxTokens 設定
claude-code config set maxTokens 100000
# 使用較小的模型
claude-code config set model claude-opus-4-8
# 檢查網路連線
ping api.anthropic.com
Q7: 程式碼生成不符合專案風格
A:
# 在 .claude/config.json 中設定專案風格
{
"codeStyle": {
"indent": "spaces",
"indentSize": 2,
"semicolons": true,
"quotes": "single"
}
}
# 參考 CLAUDE.md 中的專案規範
進階配置
自動化整合
# Git hooks 整合
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
claude-code --skill verification-before-completion
EOF
chmod +x .git/hooks/pre-commit
CI/CD 整合
# GitHub Actions 範例
# .github/workflows/claude-review.yml
name: Claude Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/claude@v1
with:
skill: requesting-code-review
api-key: ${{ secrets.ANTHROPIC_API_KEY }}
效能優化
快取策略
# 啟用結果快取
claude-code config set cache enabled true
# 設定快取大小
claude-code config set cache.size 1000
# 清除快取
claude-code cache clear
並行處理
# 使用多個執行緒
claude-code config set parallel.enabled true
claude-code config set parallel.workers 4
# 批次並行處理
claude-code --parallel --batch src/**/*.ts
資源連結
官方資源
- 官方網站:https://claude.ai/code
- 文件:https://docs.anthropic.com/claude-code
- GitHub:https://github.com/anthropics/claude-code
- 支援論壇:https://community.anthropic.com
學習資源
社群資源
- Discord:https://discord.gg/claude
- Reddit:https://reddit.com/r/ClaudeCode
- Stack Overflow:https://stackoverflow.com/questions/tagged/claude-code
下一步
安裝完成後,建議:
- 熟悉基礎功能:嘗試基本的程式碼生成和解釋
- 學習 Superpowers:探索內建技能系統
- 設定專案:為你的專案建立
.claude/配置 - 整合工作流:將 Claude Code 整合到你的開發流程
開始使用 Claude Code,體驗 AI 輔助程式開發的強大能力!