Claude Code
不只是程式碼補全 — 一個能理解整個專案、自主規劃與執行的 AI 開發夥伴
Claude Code 是什麼?
Claude Code 是 Anthropic 推出的agentic AI 程式開發工具,能直接在你的終端機、IDE 或瀏覽器中運作。它不只是回答問題,而是能讀懂你的整個 codebase、主動搜尋檔案、編輯程式碼、執行終端指令、管理 Git 操作。
6 種使用介面
Terminal CLI、VS Code、JetBrains、Desktop App、Web、Slack
Agentic 工作流
自主規劃、搜尋、編輯、測試、commit,不只是補全
MCP 生態系
連接 GitHub、Figma、Notion、Jira 等 100+ 外部工具
跨 Session 記憶
Auto Memory + CLAUDE.md,團隊知識持久化
多檔案編輯
一次理解並修改多個檔案,處理複雜重構
安全可控
5 種權限模式、沙箱隔離、企業級管控
核心能力
- 程式碼理解:讀取整個專案結構,理解架構與相依關係
- 智慧編輯:跨多個檔案同時修改,自動處理 import、type 更新
- 終端操作:執行 build、test、lint、deploy 等指令
- Git 整合:commit、branch、merge、建立 PR,附帶有意義的 commit message
- Web 搜尋:即時查詢最新文件、API 變更、Bug 修復方案
- 瀏覽器自動化:
--chrome模式可操控瀏覽器測試 Web 應用 - 排程任務:在雲端定時執行程式碼檢查、測試等自動化流程
安裝指南
原生安裝(推薦)
macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash
Windows PowerShell
irm https://claude.ai/install.ps1 | iex
Windows CMD
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
套件管理器安裝
Homebrew(macOS / Linux)
brew install --cask claude-code
# 更新:brew upgrade claude-codeWinGet(Windows)
winget install Anthropic.ClaudeCode
# 更新:winget upgrade Anthropic.ClaudeCodeIDE 擴充套件
VS Code
在 Extensions 搜尋 Claude Code(Anthropic 官方)安裝即可。
JetBrains
在 Settings > Plugins > Marketplace 搜尋 Claude Code 安裝。支援 IntelliJ、PyCharm、WebStorm 等。
其他方式
- Desktop App:從 claude.com/download 下載(macOS / Windows)
- Web 版:直接前往 claude.ai/code,免安裝
驗證安裝
claude --version
claude update # 更新到最新版快速開始
第一步:登入
claude auth login # Claude Pro/Max/Team 訂閱 claude auth login --console # Anthropic Console(API 計費) claude auth status # 檢查登入狀態
第二步:啟動 Claude Code
cd /your/project # 進入專案目錄 claude # 啟動互動模式
第三步:探索你的專案
# 在 Claude Code 互動模式中輸入:
這個專案做什麼?
資料夾結構是什麼?
主要進入點在哪裡?第四步:讓 Claude 幫你改程式
在 main.py 加一個 hello world 的 API endpoint
Claude 會:找到檔案 → 顯示修改方案 → 等你確認 → 執行修改
第五步:生成專案指令
/init # 自動分析 codebase 生成 CLAUDE.md常用啟動方式
| 指令 | 說明 |
|---|---|
claude | 啟動互動模式 |
claude "修正登入 bug" | 執行單次任務 |
claude -p "解釋這個函數" | 執行查詢後退出(適合腳本) |
claude -c | 繼續上一次對話 |
claude -r "session-name" | 恢復指定 session |
cat log.txt | claude -p "分析錯誤" | Pipe 輸入 |
指令參考
CLI 核心指令
| 指令 | 說明 |
|---|---|
claude | 啟動互動模式 |
claude "task" | 執行單次任務 |
claude -p "query" | 執行後立即退出(適合 pipe) |
claude -c | 繼續上一次對話 |
claude -r "name" | 恢復指定 session |
claude --resume | 互動式選擇 session |
claude update | 更新到最新版 |
claude auth login | 登入 |
claude auth status | 查看登入狀態 |
claude mcp add | 新增 MCP 伺服器 |
claude mcp list | 列出 MCP 伺服器 |
claude -v | 顯示版本 |
重要 CLI Flags
| Flag | 說明 | 範例 |
|---|---|---|
--model | 選擇模型 | --model opus、--model sonnet |
--effort | 回應深度 | low(快速)/ high(深入)/ max |
--permission-mode | 權限模式 | default、acceptEdits、plan、auto |
--name, -n | 命名 session | -n "feature-auth" |
--worktree, -w | 獨立 git worktree | -w feature-branch |
--chrome | 啟用瀏覽器自動化 | |
--remote | 雲端執行 | |
--add-dir | 增加工作目錄 | --add-dir ../shared-lib |
--system-prompt | 替換系統 prompt | |
--append-system-prompt | 附加到系統 prompt | |
--debug | 除錯模式 | |
--bare | 最小模式(跳過自動探索) |
互動模式 Slash Commands
| 指令 | 說明 |
|---|---|
/help | 顯示幫助 |
/clear | 清除對話歷史 |
/compact | 壓縮對話歷史(釋放 context) |
/init | 自動生成 CLAUDE.md |
/config | 互動式設定 UI |
/cost | 查看目前 session 費用 |
/memory | 查看 / 編輯自動記憶 |
/mcp | 檢查 MCP 伺服器狀態 |
/checkpoint | 建立進度檢查點 |
/rewind | 回到上一個 checkpoint |
/commit | 提交變更(Skill) |
/review-pr | 審查 PR(Skill) |
/ | 列出所有可用指令與 skills |
使用環境
Claude Code 提供 6 種使用介面,同一帳號可在不同介面間無縫切換。
| 環境 | 適合場景 | 特色 |
|---|---|---|
| Terminal CLI | Power user、腳本、CI/CD | 完整功能、Git 整合、Pipe 支援 |
| VS Code | 前端/全端開發者 | Inline diff、@-mention、選取程式碼直接發問 |
| JetBrains | Java/Python/Go 開發者 | 互動式 diff、IDE 選取分享 |
| Desktop App | 視覺化 diff 審查 | Side-by-side diff、排程任務、多 session |
| Web(claude.ai/code) | 遠端/免安裝 | 雲端執行、長時間任務、免本機設定 |
| Slack | 團隊協作 | @Claude 發問、PR 回饋、非同步工作 |
各環境安裝方式
💻 Terminal CLI
參見安裝指南
🛠 VS Code
Extensions > 搜尋 Claude Code > Install
⚙️ JetBrains
Settings > Plugins > Marketplace > Claude Code
🖥 Desktop
🌐 Web
claude.ai/code(免安裝)
💬 Slack
Slack Workspace 管理員新增 Claude Code App
MCP 整合
什麼是 MCP?
Model Context Protocol(MCP)是一個開放標準,讓 Claude 連接外部工具和資料來源。透過 MCP,Claude 可以直接存取你的資料庫、Issue Tracker、設計工具、監控系統等。
安裝 MCP 伺服器
HTTP 伺服器(推薦)
claude mcp add --transport http notion https://mcp.notion.com/mcp
SSE 伺服器
claude mcp add --transport sse asana https://mcp.asana.com/sse
本地 Stdio 伺服器
claude mcp add --transport stdio airtable \ -- npx -y airtable-mcp-server \ --env AIRTABLE_API_KEY=YOUR_KEY
管理指令
| 指令 | 說明 |
|---|---|
claude mcp list | 列出所有已設定的 MCP 伺服器 |
claude mcp get github | 查看特定伺服器詳情 |
claude mcp remove github | 移除伺服器 |
/mcp | 在 session 中檢查所有 MCP 狀態 |
常用 MCP 伺服器
🐙 開發
GitHub、GitLab、Jira、Linear、Sentry
🎨 設計
Figma、Canva
📄 文件
Notion、Google Docs、Confluence
🗃 資料庫
PostgreSQL、Supabase、Airtable、MongoDB
💬 溝通
Slack、Gmail、Google Calendar
💰 商務
Stripe、Twilio、Statsig
設定範圍
| 範圍 | 檔案 | 共用 |
|---|---|---|
| Local(預設) | ~/.claude.json | 個人 |
| Project | .mcp.json | 可 commit 到 git |
| User | ~/.claude.json | 所有專案 |
Hooks 自動化
什麼是 Hooks?
Hooks 是在 Claude 執行特定動作前後自動觸發的 Shell 指令。不需要 Claude 主動呼叫,完全由事件驅動。
事件類型
| 事件 | 觸發時機 | 用途範例 |
|---|---|---|
SessionStart | Session 開始 | 載入環境變數、初始化 |
UserPromptSubmit | 使用者送出訊息 | 驗證輸入、注入 context |
PreToolUse | 工具執行前 | 攔截危險操作、阻擋修改 |
PostToolUse | 工具執行後 | 自動格式化、記錄變更 |
PermissionRequest | 需要權限確認 | 自動授權特定操作 |
Notification | 需要通知 | 播放音效、推送通知 |
設定範例
自動格式化(每次編輯後執行 Prettier)
{
"hooks": {
"PostToolUse": [
{
"if": { "tool": "Edit" },
"command": "prettier --write {filePath}"
}
]
}
}阻擋修改特定檔案
{
"hooks": {
"PreToolUse": [
{
"if": { "tool": "Edit" },
"command": "if echo {filePath} | grep -q '.env'; then echo 'BLOCKED: Cannot edit .env files' >&2; exit 1; fi"
}
]
}
}完成時發送通知
{
"hooks": {
"Notification": [
{
"command": "osascript -e 'display notification \"{message}\" with title \"Claude Code\"'"
}
]
}
}Hooks 設定在 settings.json(User 或 Project 層級)中配置。
設定與配置
設定檔位置
| 範圍 | 檔案路徑 | 共用 | 說明 |
|---|---|---|---|
| User | ~/.claude/settings.json | 否 | 個人偏好(所有專案) |
| Project | .claude/settings.json | 可 commit | 團隊共用設定 |
| Local | .claude/settings.local.json | 否(gitignore) | 個人專案覆寫 |
| Managed | 系統層級 | IT 部署 | 企業強制政策 |
常用設定
{
"model": "claude-opus-4-6",
"effortLevel": "medium",
"defaultMode": "acceptEdits",
"permissions": {
"allow": ["Bash(git *)", "Read", "Edit"]
},
"autoMemoryEnabled": true
}權限模式
| 模式 | 行為 | 適合 |
|---|---|---|
default | 每個動作都詢問 | 初學者、敏感專案 |
acceptEdits | 自動接受檔案編輯,危險操作仍詢問 | 日常開發(推薦) |
plan | 先展示計畫再執行 | 大型重構 |
auto | 智慧判斷(Team/Enterprise) | 信任環境 |
dontAsk | 預設全部通過 | CI/CD 腳本 |
bypassPermissions | 跳過所有權限檢查 | ⚠️ 高風險,僅測試用 |
CLAUDE.md 專案指令
CLAUDE.md 是 Claude 每次開啟專案時自動讀取的指令檔,用來告訴 Claude 專案的架構、規範和常用操作。
# 專案概述 這是一個 Express.js + PostgreSQL 的電商 API。 # 開發指令 - 安裝:`npm install` - 啟動:`npm run dev` - 測試:`npm test` # 程式規範 - 使用 TypeScript - 2 空格縮排 - 所有新功能必須寫測試 - API handlers 放在 `src/api/handlers/` # 架構 - 資料庫:PostgreSQL + Prisma ORM - 測試:Jest - 部署:Vercel
/init 讓 Claude 自動分析你的 codebase 生成初始 CLAUDE.md。建議控制在 200 行內。
記憶系統
Claude Code 有多層記憶機制,確保跨 session 的連續性,讓你不需要每次都重複解釋。
記憶架構
1. Session 延續(短期 → 中期)
| 指令 | 說明 |
|---|---|
claude -c | 繼續上一次對話(完整上下文) |
claude -r "name" | 恢復指定 session(用 -n 命名) |
claude --resume | 互動式選擇歷史 session |
Session 歷史儲存在本地,關閉 terminal 後仍可恢復。
2. Auto Memory(跨 Session 長期記憶)
Claude 自動將學到的重要資訊存入 ~/.claude/projects/<project>/memory/。
- user:使用者偏好、角色、技術背景
- feedback:使用者的糾正與確認(「不要這樣做」「對,就是這樣」)
- project:專案進度、決策、截止日期
- reference:外部資源位置(Jira、Slack 頻道等)
/memory # 查看與編輯記憶3. CLAUDE.md(專案級指令)
| 位置 | 範圍 | 共用 |
|---|---|---|
./CLAUDE.md | 專案 | ✔ commit 到 git |
./.claude/CLAUDE.md | 專案 | ✔ commit 到 git |
./CLAUDE.local.md | 個人 | ✘ gitignore |
~/.claude/CLAUDE.md | 全域 | ✘ 個人所有專案 |
4. 對話壓縮
/compact:手動壓縮對話歷史,釋放 context window- 系統在接近 context 上限時會自動壓縮
- 壓縮後保留摘要,不會完全遺忘
5. Checkpoint / Rewind
/checkpoint:標記當前進度/rewind:回到上一個 checkpoint- 適合嘗試不同方案時使用
- 為重要 session 命名:
claude -n "feature-auth" - 每個專案都建立
CLAUDE.md(用/init自動生成) - 偶爾檢查
/memory確認記憶正確 - 對話太長時用
/compact而非開新 session
Skills 自訂指令
什麼是 Skills?
Skills 是可重複使用的自訂 slash commands,讓你把常用工作流程打包成一個指令。輸入 /skill-name 即可觸發。
建立 Skill
Skills 以 Markdown 檔案形式存放在 .claude/skills/ 目錄中:
.claude/skills/ ├── commit.md # /commit ├── review-pr.md # /review-pr ├── deploy.md # /deploy └── healthcheck.md # /healthcheck
Skill 檔案格式
--- name: deploy description: Build, test, and deploy to production --- Please perform the following deployment steps: 1. Run all tests: `npm test` 2. Build the project: `npm run build` 3. Check for TypeScript errors: `npx tsc --noEmit` 4. If all checks pass, deploy with: `vercel --prod` 5. Report the deployment URL If any step fails, stop and report the error.
使用 Skill
/deploy # 執行 deploy skill /review-pr 123 # 帶參數 / # 列出所有可用 skills
作用範圍
| 位置 | 範圍 | 共用 |
|---|---|---|
.claude/skills/ | 專案 | ✔ commit 到 git,團隊共用 |
~/.claude/skills/ | 全域 | ✘ 個人使用 |
實用 Skill 範例
📦 自訂 Commit
--- name: commit description: Smart commit with conventional format --- 1. Run `git diff --stat` to see changes 2. Stage relevant files (exclude .env, credentials) 3. Generate a conventional commit message 4. Create the commit 5. Show result with `git log --oneline -1`
🔎 PR 審查
--- name: review-pr description: Review PR for issues and improvements --- Review the current branch changes against main: 1. Run `git diff main...HEAD` 2. Check for: security issues, performance, missing tests 3. Summarize with severity levels (critical/warning/info)
🩹 專案健檢
--- name: healthcheck description: Check project health - deps, tests, lint --- 1. Check for outdated dependencies 2. Run linter and report issues 3. Run tests and report coverage 4. Check for security vulnerabilities 5. Generate a health report summary
- CLAUDE.md:被動載入的背景知識,每次對話自動讀取
- Skills:主動觸發的工作流程,像是自訂 macro
Sub-agents 與 Agent SDK
什麼是 Sub-agents?
Claude Code 可以產生子 agent(sub-agent)來平行處理子任務。每個 sub-agent 有獨立的 context,執行完畢後將結果回報給主 agent。
內建 Sub-agent 類型
| 類型 | 用途 | 可用工具 |
|---|---|---|
Explore | 快速搜尋 codebase | Glob、Grep、Read(唯讀) |
Plan | 設計實作方案 | 唯讀工具(不修改) |
general-purpose | 通用任務 | 所有工具 |
Claude 會自動判斷何時啟動 sub-agents,例如需要搜尋多個目錄時會平行啟動多個 Explore agent。
Agent SDK
如果你想建立自己的 AI agent 應用,Anthropic 提供了 Agent SDK。
Python SDK
import anthropic client = anthropic.Anthropic() message = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=1024, messages=[{"role": "user", "content": "分析這段程式碼的安全性"}] )
TypeScript SDK
import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const message = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, messages: [{ role: "user", content: "寫一個測試" }] });
SDK 核心功能
- Agent Loop:agent 自主使用工具並迭代
- Tool Use:Web 搜尋、程式執行、檔案操作
- Structured Output:取得結構化 JSON 回應
- Streaming:即時串流輸出
- Computer Use:GUI 自動化操作
安全性與權限
權限模式詳解
Claude Code 透過多層權限系統確保安全,預設不會未經同意執行危險操作。
| 模式 | 檔案編輯 | Shell 指令 | MCP 工具 | 適合場景 |
|---|---|---|---|---|
default | 詢問 | 詢問 | 詢問 | 敏感專案 |
acceptEdits | 自動 | 詢問 | 詢問 | 日常開發 |
plan | 先展示計畫 | 先展示計畫 | 先展示計畫 | 大型重構 |
auto | 智慧判斷 | 智慧判斷 | 智慧判斷 | Team/Enterprise |
bypassPermissions | 全部跳過 | 全部跳過 | 全部跳過 | ⚠️ 僅測試 |
沙箱機制
- Claude Code 在本地沙箱中執行 Shell 指令,預設限制網路存取和檔案系統
- macOS 使用 Apple Seatbelt,Linux 使用命名空間隔離
- 可自訂允許/拒絕的指令:
"permissions": { "allow": ["Bash(git *)"], "deny": ["Bash(rm -rf *)"] }
敏感檔案保護
- Claude 預設不會 commit
.env、credentials.json、私鑰等敏感檔案 - 可透過 Hooks 的
PreToolUse事件攔截對特定檔案的修改 - CLAUDE.md 中可明確列出「不要修改」的檔案清單
企業安全管控
- Managed Policies:IT 管理員可部署全組織的強制設定
- SSO 整合:支援 SAML/OIDC 單一登入
- Audit Log:記錄所有 Claude 操作
- 資料不訓練:Claude Code 不會用你的程式碼訓練模型
- 不要使用
bypassPermissions在生產環境 - 定期檢查
permissions.allow清單 - 團隊專案使用
.claude/settings.json統一安全政策
CI/CD 整合
在 GitHub Actions 中使用 Claude Code
name: Claude Code Review on: pull_request: types: [opened, synchronize] jobs: review: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Claude Code run: curl -fsSL https://claude.ai/install.sh | bash - name: Review PR run: | claude -p "Review this PR's changes. Check for bugs, security issues, and suggest improvements." \ --permission-mode dontAsk env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
自動修復 CI 失敗
- name: Auto-fix lint errors
run: |
claude -p "Run linter, fix all errors, and commit the fixes" \
--permission-mode dontAsk自動生成 PR 描述
- name: Generate PR description
run: |
claude -p "Analyze the diff and generate a detailed PR description in markdown" \
--permission-mode dontAsk > pr-body.mdGitLab CI
claude-review: stage: review script: - curl -fsSL https://claude.ai/install.sh | bash - claude -p "Review the MR changes" --permission-mode dontAsk only: - merge_requests
- CI 環境建議用
--permission-mode dontAsk避免互動式提示 - 用
--effort low或--model sonnet加速 CI 流程 - 設定
ANTHROPIC_API_KEY為 repository secret
團隊與企業功能
方案比較
| 功能 | Pro | Max | Team | Enterprise |
|---|---|---|---|---|
| Claude Code 存取 | ✔ | ✔ | ✔ | ✔ |
| 用量額度 | 標準 | 20x | 每人獨立 | 自訂 |
| auto 權限模式 | ✘ | ✘ | ✔ | ✔ |
| SSO 單一登入 | ✘ | ✘ | ✔ | ✔ |
| Managed Policies | ✘ | ✘ | ✘ | ✔ |
| Audit Log | ✘ | ✘ | ✘ | ✔ |
| Usage Analytics | ✘ | ✘ | ✔ | ✔ |
| SCIM 使用者管理 | ✘ | ✘ | ✘ | ✔ |
| 優先支援 | ✘ | ✘ | ✔ | ✔ |
團隊共用設定
團隊專案應該將以下檔案 commit 到 git:
CLAUDE.md— 團隊程式規範、架構說明.claude/settings.json— 共用權限與 hook 設定.claude/skills/— 團隊自訂 skills.mcp.json— 共用 MCP 伺服器設定
Usage Analytics
Team 和 Enterprise 管理員可查看:
- 團隊成員的使用頻率和模式
- PR 貢獻分析(Claude 輔助 vs 手動)
- 模型用量和成本分佈
- Power user 識別
Managed Policies(Enterprise)
IT 管理員可全組織部署的強制設定:
- 強制權限模式(例如禁止
bypassPermissions) - 限制可用模型
- 必須使用的 MCP 伺服器
- 檔案存取限制
與其他 AI 工具比較
綜合比較表
| 特性 | Claude Code | GitHub Copilot | Cursor | Windsurf | Aider |
|---|---|---|---|---|---|
| 類型 | CLI+IDE+Web | IDE 外掛 | IDE | IDE | CLI |
| 模型 | Claude 4.6 | GPT-4o/Claude | 多模型 | 多模型 | 多模型 |
| Agentic | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| 終端操作 | ✔ 原生 | ✘ | 有限 | 有限 | ✔ 原生 |
| 多檔案編輯 | ✔ 自動 | 需手動 | ✔ Composer | ✔ Cascade | ✔ |
| Git 深度整合 | ✔ commit/PR/branch | 基本 | ✔ | ✔ | ✔ 深度 |
| MCP 外掛 | ✔ 100+ | ✘ | ✘ | ✘ | ✘ |
| 自訂指令 | CLAUDE.md | .github/copilot | .cursorrules | .windsurfrules | ✔ |
| 記憶系統 | ✔ Auto Memory | ✘ | ✘ | 基本 | ✘ |
| 雲端執行 | ✔ Web/Remote | ✘ | ✘ | ✘ | ✘ |
| 瀏覽器自動化 | ✔ --chrome | ✘ | ✘ | ✘ | ✘ |
| 開源 | ✘ | ✘ | ✘ | ✘ | ✔ |
| 價格/月 | $20-200 | $10-39 | $20-40 | $15-50 | 免費(API費) |
Claude Code 的獨特優勢
- 真正的 Agentic:不只補全,能自主規劃、搜尋、編輯、測試、commit
- 6 種介面:CLI + VS Code + JetBrains + Desktop + Web + Slack
- MCP 生態系:連接 100+ 外部工具(GitHub、Figma、Notion 等)
- 跨 Session 記憶:Auto Memory 持久化團隊知識
- 雲端 + 本地:長時間任務可雲端執行
- Hooks 自動化:事件驅動的自訂工作流程
各工具最適合的場景
Claude Code
全端開發、複雜重構、跨多檔案、CLI 愛好者、深度 Git 操作、MCP 整合
GitHub Copilot
即時補全、輕量輔助、已在 GitHub 生態系的團隊
Cursor
偏好 VS Code、多模型切換、Composer 多步驟
Windsurf
圖形化 IDE 偏好者、Cascade 自動化
Aider
開源偏好、自選 LLM、預算敏感
實戰工作流程
① 接手新專案
cd /path/to/project claude # 在互動模式中: > 這個專案做什麼?用了哪些技術? > 說明資料夾結構 > 哪裡是主要進入點? > /init # 自動生成 CLAUDE.md
② 修 Bug
claude
> 我遇到這個錯誤:[貼上完整錯誤訊息]
# Claude 會自動:搜尋相關程式碼 → 定位問題 → 修改 → 執行測試③ 開發新功能
claude --permission-mode plan > 我要在使用者設定頁面加上深色模式切換 # Claude 先列出計畫 → 你確認 → 逐步實作 > /commit # 自動生成 commit message > 建立 PR
④ 程式碼審查
claude -p "review the changes in this PR and suggest improvements"
# 或在 GitHub PR 中 @claude 留言⑤ 重構
claude > 將 authentication module 從 callback 改為 async/await > 順便補上 unit tests > 確認所有 tests 都通過
⑥ 平行處理多個任務
# Terminal 1 — 獨立 worktree claude -w feature-auth -n "auth" > 實作 OAuth 登入 # Terminal 2 — 另一個 worktree claude -w fix-ui -n "ui-fix" > 修正首頁 RWD 問題
⑦ 連接外部工具(MCP)
claude mcp add --transport http notion https://mcp.notion.com/mcp claude > 從 Notion 的 API 文件頁面讀取規格,然後實作對應的 endpoint
⑧ CI/CD 自動化
# 在 GitHub Actions 中
claude -p "run all tests and fix any failures" \
--permission-mode dontAsk技巧與最佳實踐
有效提問
❌ 模糊
fix the bug
make it better
✔ 具體
修正登入頁面在輸入錯誤密碼後顯示空白畫面的 bug
將 API response time 從 2 秒優化到 500ms
拆分複雜任務
將大任務拆成 3-5 個小步驟,每步完成後確認再繼續:
1. 建立資料庫 schema 2. 寫 API endpoint 3. 做前端頁面 4. 補測試
先探索再動手
- 新專案先問「這個專案做什麼?用了什麼架構?」
- 修改前先「show me how authentication currently works」
- 避免盲目修改造成 regression
快捷鍵
| 快捷鍵 | 功能 |
|---|---|
? | 顯示所有快捷鍵 |
Tab | 自動補全 |
↑/↓ | 瀏覽歷史指令 |
Shift+Enter | 多行輸入 |
Ctrl+C | 中斷 Claude |
Ctrl+D | 退出 |
Shift+Tab | 切換權限模式 |
Ctrl+R | 反向搜尋歷史 |
/ | 列出所有指令與 skills |
疑難排解
| 問題 | 解決方法 |
|---|---|
| 安裝失敗 | 確認 Node.js 18+ / Git 已安裝 |
| 認證問題 | claude auth logout → claude auth login |
| 權限提示太多 | --permission-mode acceptEdits |
| 回應太慢 | --effort low 或 --model sonnet |
| Context 超出 | /compact 壓縮或 /clear 重開 |
| MCP 連不上 | /mcp 檢查狀態,重啟 session |
方案與費用
訂閱方案
| 方案 | 價格 | 用量 | 適合 |
|---|---|---|---|
| Pro | $20/月 | 標準額度 | 個人開發者 |
| Max | $100-200/月 | 20x 額度 | 重度使用者 |
| Team | 每人計費 | 獨立額度 | 團隊協作 |
| Enterprise | 自訂 | 自訂 | 大型組織 |
API 計費(Console)
透過 claude auth login --console 登入,按 token 用量計費:
| 模型 | Input / MTok | Output / MTok |
|---|---|---|
| Claude Opus 4.6 | $15 | $75 |
| Claude Sonnet 4.6 | $3 | $15 |
| Claude Haiku 4.5 | $0.80 | $4 |
查詢用量
/cost # 查看目前 session 費用- 日常任務用
--model sonnet(便宜 5 倍) - 簡單查詢用
--effort low減少 token /compact減少重複 context 的 token 消耗- Batch 處理享有 50% input token 折扣
常見問題 FAQ
Q: Claude Code 會用我的程式碼訓練模型嗎?
不會。Anthropic 明確承諾不會用 Claude Code 使用者的程式碼和對話來訓練模型。
Q: Claude Code 可以離線使用嗎?
不行,Claude Code 需要網路連線才能運作,因為推論在 Anthropic 的伺服器上執行。
Q: 我可以同時開多個 Claude Code session 嗎?
可以!使用 -w(worktree)在不同 git branch 上平行工作,或直接開多個 terminal。
Q: Claude Code 支援哪些程式語言?
所有語言。Claude Code 不限定語言,它能讀取和修改任何文字檔案。特別擅長 Python、JavaScript/TypeScript、Java、Go、Rust、C/C++。
Q: 如何避免 Claude 修改不該改的檔案?
三種方式:(1) 在 CLAUDE.md 列出禁止修改的檔案 (2) 用 Hooks 的 PreToolUse 攔截 (3) 使用 permissions.deny 設定。
Q: 免費試用?
Claude Code 包含在 Claude Pro ($20/月) 訂閱中。目前沒有獨立免費方案,但新註冊可能有試用額度。也可用 API Console 按量計費。
Q: Claude Code 和 Claude.ai 聊天有什麼不同?
Claude Code 有完整的工具存取權限:可讀寫檔案、執行終端指令、管理 Git、連接 MCP 工具。普通 Claude 聊天只能文字對話。
Q: 如何繼續之前的對話?
claude -c 繼續上一次,claude -r "name" 恢復指定 session,claude --resume 互動式選擇。詳見記憶系統。
Q: Context window 滿了怎麼辦?
用 /compact 壓縮對話歷史。Claude 會自動在接近上限時壓縮,保留摘要。
Q: 可以用自己的 API key 嗎?
可以。用 claude auth login --console 登入 Anthropic Console,按 token 用量計費。也支援 AWS Bedrock 和 Google Vertex AI。
Q: Copilot 和 Claude Code 可以同時用嗎?
完全可以。Copilot 做即時補全,Claude Code 做複雜任務(重構、多檔案修改、PR 建立),兩者互補。
Q: 如何讓 Claude 記住我的偏好?
三種方式:(1) CLAUDE.md 寫專案規範 (2) Auto Memory 自動記錄 (3) 明確說「請記住:我偏好...」,Claude 會存入 memory。