agent:~/.claude$ cat claude-code-cheatsheet.md

Claude Code速查表:命令、設定與快捷鍵

# 為v2.1.150更新的Claude Code快速查閱速查表,涵蓋CLI flags、slash commands、鍵盤快捷鍵、hooks、plugins、Agent View、/goal、Workflow與環境變數。

words: 1574 read_time: 10m updated: 2026-05-25 05:38
$ less claude-code-cheatsheet.md

一站掌握所有CLI旗標、斜線指令、鍵盤快速鍵、設定鍵、hook 事件與環境變數。如需深入說明,請參閱完整的Claude Code指南。若是首次設定,請參閱快速入門


1. 安裝

3種安裝方法,依建議優先順序排列。

# Native binary (recommended)
curl -fsSL https://claude.ai/install.sh | bash

# Homebrew (macOS)
brew install --cask claude-code

# NPM (deprecated — migrate with `claude install`)
npm install -g @anthropic-ai/claude-code

安裝特定版本:

curl -fsSL https://claude.ai/install.sh | bash -s 1.0.58

驗證安裝:

claude doctor
claude --version

驗證身分:

claude auth login       # Log in or switch accounts
claude auth status      # Check current auth state
claude auth logout      # Clear stored credentials

2. CLI Flags

Flag 說明 範例
-p 列印模式——單次查詢後結束 claude -p "list TODOs"
-c 繼續最近一次 session claude -c
-r, --resume 繼續指定名稱或編號的 session claude -r "auth-refactor"
-n, --name 啟動時設定 session 顯示名稱 claude -n "feature-x"
--model 覆寫此 session 使用的模型 claude --model opus
--max-turns 限制自主回合數 claude -p "fix lint" --max-turns 10
--output-format textjsonstream-json 輸出 claude -p "count files" --output-format json
--allowedTools 限制可用工具 claude -p "fix" --allowedTools "Edit,Bash(npm:*)"
--permission-mode 設定權限模式 claude --permission-mode auto
--enable-auto-mode 啟動時啟用 Auto Mode claude --enable-auto-mode
--dangerously-skip-permissions YOLO 模式——略過所有提示 claude --dangerously-skip-permissions
--from-pr 啟動連結至 PR 的 session(v2.1.27+);接受 GitHub、GHE、GitLab MR、Bitbucket PR URL(v2.1.119+) claude --from-pr 123
--fork-session 從已恢復的 session 分岔 claude -r base --fork-session
-w 在隔離的 git worktree 中啟動 claude -w
--bare 腳本模式——略過 hooks、LSP、plugins claude -p "count files" --bare
--plugin-url <url> 為目前 session 擷取 plugin .zip 封存檔(v2.1.129+) claude --plugin-url https://example.com/plugin.zip
--plugin-dir <path> 為目前 session 載入 plugin 目錄或 .zip 封存檔(.zip 支援 v2.1.128+) claude --plugin-dir ./my-plugin.zip
--channels 將核准提示轉送至 Telegram/Discord claude --channels
--debug 啟用偵錯記錄 claude --debug
--init 使用 CLAUDE.md 初始化專案 claude --init

3. Slash Commands

Command 功能
/init 使用 CLAUDE.md 初始化專案
/compact 壓縮對話歷史。可加入焦點:/compact focus on tests
/context 檢視 context window 使用情況,並取得可執行的建議
/usage token 使用量、成本、方案用量;整合對話框(v2.1.118+:/cost/stats 是輸入捷徑,會開啟 /usage 分頁);v2.1.149+ 新增 skills、subagents、plugins 的分類限制用量,以及每個 MCP 伺服器成本
/cost 輸入捷徑 → 開啟 /usage 成本分頁(v2.1.118+)
/model 變更模型。/model opus/model sonnet
/fast 切換快速輸出模式
/effort 設定 effort 等級:lowmediumhigh
/status 檢視 session 狀態、模型與設定
/permissions 以互動方式管理權限設定
/config 開啟完整設定介面
/mcp 設定 MCP 伺服器。/mcp enable/mcp disable
/hooks 檢視 hook 設定
/memory 檢視並管理 auto-memory 檔案
/copy 複製 code blocks。/copy N 表示複製第 N 個最近回應
/resume 繼續指定名稱的 session。/resume 1/resume name
/rename 命名目前 session。/rename feature-auth
/branch 分岔對話以平行探索
/clear 清除對話歷史
/plan 進入 plan mode。/plan refactor the auth module
/powerup 透過動畫示範進行互動式功能教學(v2.1.90+)
/voice 切換按住說話語音模式
/loop 週期性工作。/loop 5m /foo 每 5 分鐘執行一次
/rewind 返回 checkpoint(或按兩次 Esc
/export 匯出對話逐字稿
/add-dir 新增工作目錄以擴展檔案存取範圍
/agents 管理 subagents
/goal 設定完成條件;Claude 會持續執行直到達成目標(v2.1.139+)
/skills 列出已安裝的 skills;提供輸入篩選搜尋框(v2.1.121+)
/bashes 列出背景 bash 工作
/tasks 列出背景 agents
/theme 管理具名 themes(v2.1.118+);plugins 會提供 themes/ 目錄
/color 設定提示列顏色。使用 /color default 重設
/code-review [effort] 依選擇性的 effort 等級找出正確性錯誤;--comment 會張貼行內 GitHub PR comments(v2.1.147 從 /simplify 重新命名)
/batch 批次操作
/security-review 檢查程式碼是否有弱點
/claude-api 使用 Claude API/Anthropic SDK 建構 apps
/doctor 檢查安裝健康狀態
/bug 向 Anthropic 回報 bug
/release-notes 具 changelogs 的互動式版本選擇器(v2.1.92+)
/buddy 終端機陪伴寵物——18 種物種、5 個稀有度階層,依 account ID 決定且具確定性
/login / /logout 在 session 中驗證身分或登出

自訂命令:建立 .claude/commands/my-command.md(專案)或 ~/.claude/commands/my-command.md(個人),並用 /my-command 呼叫。命令支援 YAML frontmatter,可設定說明、允許的工具、模型覆寫,以及透過 $ARGUMENTS 或位置參數 $1$2 進行引數插值。

---
description: Fix a GitHub issue
allowed-tools: Read, Edit, Bash(git:*)
model: opus
argument-hint: [issue-number]
---

Fix GitHub issue #$ARGUMENTS following our coding standards.

用法:/fix-issue 123


4. 鍵盤快速鍵

一般控制

快速鍵 動作
Ctrl+C 取消目前操作
Ctrl+D 結束 session(EOF)
Ctrl+L 清除畫面(保留歷史)
Ctrl+O 切換詳細輸出
Ctrl+R 搜尋命令歷史
Ctrl+V 從剪貼簿貼上圖片
Ctrl+B 將目前操作移至背景
Ctrl+X Ctrl+K 停止所有 agents(v2.1.83 從 Ctrl+F 變更)
Ctrl+S 暫存 prompt 草稿
Ctrl+G 開啟外部編輯器
Esc Esc 回復上一個變更
Tab 接受 prompt 建議
! Tab Bash 歷史自動完成
Shift+Tab 循環切換權限模式
Alt+P / Option+P 輸入時切換模型
Alt+T 切換 thinking mode
Ctrl+T 切換語法醒目提示
Shift+Down 循環切換 agent team 隊友
Up/Down 瀏覽命令歷史
v Vim visual mode——字元選取(v2.1.118+;僅 vim mode)
V Vim visual-line mode(v2.1.118+;僅 vim mode)
? 顯示快速鍵

快速前綴

前綴 動作 範例
# 新增至持久記憶 # Always use TypeScript
/ Slash command /review
! 直接執行 bash ! git status
@ 參照檔案 @src/index.ts
& 將工作傳送到雲端 & Build the API

多行輸入

方法 按鍵
跳脫換行 \ 然後按 Enter
macOS Option+Enter
iTerm2/WezTerm/Ghostty/Kitty Shift+Enter
其他終端機 Shift+Enter(先執行 /terminal-setup
控制字元 Ctrl+J

Keybindings 可透過 /keybindings 自訂(儲存在 ~/.claude/keybindings.json)。


5. 設定檔案

優先順序階層(由高到低)

層級 位置 範圍
Enterprise(鎖定) /Library/Application Support/ClaudeCode/managed-settings.json(macOS) 所有使用者,無法覆寫
CLI flags 命令列引數 目前 session
本機專案 .claude/settings.local.json 個人、目前專案(gitignored)
共享專案 .claude/settings.json 團隊,提交至 git
使用者全域 ~/.claude/settings.json 您的所有專案
執行階段狀態 ~/.claude.json OAuth tokens、MCP config

第一個符合項目生效。Enterprise 設定無法繞過。


6. Settings.json 參考

主要設定、型別與範例。請放在上述階層中的任一 settings 檔案。

{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "model": "claude-sonnet-4-6",
  "permissions": {
    "allow": ["Read", "Glob", "Grep", "Bash(npm run:*)", "Bash(git:*)", "Edit(src/**)"],
    "deny": ["Read(.env*)", "Bash(rm -rf:*)", "Bash(sudo:*)"],
    "ask": ["WebFetch", "Bash(docker:*)"],
    "defaultMode": "acceptEdits",
    "additionalDirectories": ["../shared-lib"]
  },
  "env": {
    "NODE_ENV": "development"
  },
  "hooks": {},
  "sandbox": {
    "enabled": false,
    "autoAllowBashIfSandboxed": true
  },
  "includeCoAuthoredBy": true,
  "cleanupPeriodDays": 30,
  "respectGitignore": true,
  "showTurnDuration": true,
  "language": "en",
  "autoMemoryDirectory": ".claude/memory",
  "plansDirectory": ".claude/plans"
}

權限規則語法:Tool(pattern:*)提供前綴比對。Bash(npm run test:*)允許npm run testnpm run test:unit等。檔案模式使用 glob 語法:Edit(src/**)

新鍵(v2.1.118+):

Key 行為
autoMode.allow $defaults Sentinel,會在內建清單旁加入自訂規則(也適用於soft_denyenvironment)— v2.1.118+
prUrlTemplate 頁尾 PR badge URL 範本 — v2.1.119+
wslInheritsWindowsSettings WSL 繼承 Windows 端受管理設定 — v2.1.118+
skillOverrides 隱藏或收合 skills:offuser-invocable-onlyname-only— v2.1.129+
allowAllClaudeAiMcps 企業受管理設定,可在managed-mcp.json之外載入 claude.ai 雲端 MCP connectors — v2.1.149+

如需完整 settings schema,請參閱完整指南中的Configuration Deep Dive


7. CLAUDE.md 快速參考

CLAUDE.md 是專案的指令檔案。Claude 會在每個 session 開始時讀取它。

存放位置:

位置 範圍
CLAUDE.md(專案根目錄) 此專案中的所有使用者、所有 session
.claude/CLAUDE.md 相同範圍,替代位置
~/.claude/CLAUDE.md 個人設定,所有專案

應包含的內容:

# Project Name

## Stack
- Backend: FastAPI, Python 3.11+
- Frontend: HTMX + Alpine.js + Bootstrap 5

## Commands
- Dev: `uvicorn app.main:app --reload --port 8000`
- Test: `python -m pytest -v`
- Lint: `ruff check .`

## Conventions
- Conventional commits: feat:, fix:, docs:, refactor:
- Never force push to main
- Always activate venv before Python commands

## Key Files
- app/main.py — FastAPI app and routes
- app/models.py — SQLAlchemy models

保持易於掃描。密集的長篇文字會在每個 session 浪費 context tokens。請使用項目符號、表格與短程式碼區塊。避免長段落,因為 Claude 會在每個 session 開始時讀取 CLAUDE.md,所以每個字都會消耗 context。

專業技巧: - 在 REPL 中使用#前綴,即可將內容加入 auto-memory,而不必編輯 CLAUDE.md:# Always use TypeScript strict mode - 當 Claude 讀取子目錄中的檔案時,也會載入該子目錄內的 CLAUDE.md - 團隊共用規則可放在.claude/rules/*.md,方便模組化整理


8. 權限模式

模式 行為 使用情境
default 每個工具首次使用時提示 一般開發
acceptEdits 自動核准檔案編輯,bash 仍會提示 受信任專案
auto Classifier(Sonnet 4.6)會檢查每個動作是否安全 具備防護的自主執行
plan 唯讀,不允許編輯或執行 僅供分析與規劃
bypassPermissions 略過所有提示 CI/CD 自動化

Auto Mode(v2.1.85+)是取代--dangerously-skip-permissions的建議方案。唯讀與檔案編輯會自動核准。自訂 allow/deny 規則會優先解析,其餘動作則交由安全 classifier 判斷。預設會自動封鎖:curl | bash、force-push 到 main、生產環境部署、大量雲端刪除、IAM 變更、將敏感資料傳送到外部。1

Circuit breaker:同一 session 中連續封鎖 3 次或總計封鎖 20 次,會暫停並回到手動提示。

# Enable at startup
claude --enable-auto-mode

# Cycle during session
Shift+Tab    # default -> acceptEdits -> auto -> plan

PowerShell 自動核准(v2.1.119+):PowerShell 工具命令會和 Bash 命令一樣,依權限模式自動核准。像PowerShell(Get-*:*)這類 allow 規則,可讓唯讀操作略過提示。若工作流程大量使用 PowerShell,建議使用 v2.1.149+;它修正了內建cd權限繞過、前綴/萬用字元 allow 規則比對,以及過期目錄變數追蹤。


9. Hook 事件

事件 觸發時機 可封鎖?
PreToolUse 工具執行前
PostToolUse 工具完成後
PostToolUseFailure 工具失敗後
UserPromptSubmit 使用者送出 prompt
Stop Claude 完成回覆
SubagentStart Subagent 產生
SubagentStop Subagent 完成
SessionStart Session 開始
SessionEnd Session 關閉
Notification 觸發警示

| InstructionsLoaded | CLAUDE.md 已載入 | 否 | | ConfigChange | Config 檔案在 session 中途變更 | 是 | | WorktreeCreate | 正在建立 worktree | 是 | | WorktreeRemove | 正在移除 worktree | 否 | | PreCompact | Context compaction 前 | 否 | | PostCompact | Context compaction 後 | 否 | | Elicitation | MCP 要求結構化輸入 | 是 | | ElicitationResult | 使用者回應 MCP 對話框 | 是 | | StopFailure | Turn 因 API 錯誤而結束 | 否 | | PermissionRequest | 顯示權限對話框 | 是 | | PermissionDenied | Auto mode 拒絕某項動作(v2.1.88+) | 否 | | CwdChanged | 工作目錄變更(v2.1.83+) | 否 | | FileChanged | 受監看檔案由外部修改(v2.1.83+) | 否 | | TaskCreated | 建立新 task(v2.1.84+) | 否 | | TeammateIdle | Agent 團隊成員閒置 | 是 | | TaskCompleted | Task 標記為完成 | 是 |

如需完整 hook protocol(輸入/輸出 JSON、matchers、exit codes),請參閱完整指南中的Hooks Deep Dive


10. Hook 設定

Hooks 位於settings.json或專用的hooks.json。最小範例如下:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "npx prettier --write \"$FILE_PATH\""
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/validate-bash.sh"
          }
        ]
      }
    ]
  }
}

Matcher 語法:

Pattern 比對
* 所有工具
Bash 僅 Bash
Edit\|Write Edit 或 Write
mcp__github MCP 伺服器工具
""(空字串) 沒有工具的事件(例如UserPromptSubmit

Exit codes:

Code 意義
0 成功,操作繼續
2 封鎖,操作停止,stderr 會傳給 Claude
13+ 非封鎖警告

Async hooks 會在背景執行而不封鎖:請在 hook 物件中加入"async": true2

Hook 輸出/輸入欄位:

  • duration_ms位於PostToolUse/PostToolUseFailure hook input(v2.1.119+)— 工具執行時間,不包含權限提示與 PreToolUse hooks。
  • hookSpecificOutput.updatedToolOutput(v2.1.121+)— 取代任何工具的輸出(v2.1.118 最初僅為 MCP 引入;v2.1.121 擴展到所有工具)。
  • hookSpecificOutput.sessionTitle(v2.1.96+)— 從UserPromptSubmit hook 設定 session 標題。
  • args: string[]位於 command hooks(v2.1.139+)— 不需 shell quoting,即可傳遞結構化 argv。
  • continueOnBlock位於PostToolUse hooks(v2.1.139+)— 將封鎖原因回傳給 Claude,並繼續該 turn。
  • subagent_type位於 agent hook input(v2.1.140+)— 識別正在執行的 agent 類型。
  • terminalSequence位於 hook JSON output(v2.1.141+)— 發出用於通知、視窗標題與鈴聲的終端機控制序列。

11. MCP 快速設定

用一個指令新增MCP伺服器:

# Remote HTTP server (recommended)
claude mcp add --transport http github https://api.githubcopilot.com/mcp/

# Remote with auth header
claude mcp add --transport http api https://api.example.com/mcp \
  --header "Authorization: Bearer $TOKEN"

# Local stdio server
claude mcp add --transport stdio postgres \
  --env "DATABASE_URL=postgresql://user:pass@localhost/db" \
  -- npx -y @anthropic-ai/mcp-server-postgres

範圍控制:

claude mcp add --scope project ...   # Team-shared (.mcp.json)
claude mcp add --scope user ...      # Personal (~/.claude.json)

專案.mcp.json範例:

{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/"
    },
    "database": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@anthropic-ai/mcp-server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost/db"
      }
    }
  }
}

MCP目前每月下載量已達1億次,並索引3,000多個伺服器。3如需傳輸類型、elicitation與工具搜尋設定,請參閱完整指南中的MCP章節

alwaysLoad(v2.1.121+):讓受信任的伺服器不受 Tool Search 延後載入影響。其所有工具會在工作階段開始時載入,不需要ToolSearch往返:

{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "alwaysLoad": true
    }
  }
}

自動重試(v2.1.121+):啟動期間發生錯誤的MCP伺服器,最多會重試3次,之後才標記為已中斷連線。

SDK mcp_authenticate redirectUri(v2.1.121+):在自訂 URI scheme 上完成OAuth時必填,適用於桌面應用程式與 claude.ai connector 流程。


11.5. Plugin CLI 指令

Command 行為
claude --plugin-url <url> 擷取目前工作階段使用的 plugin .zip封存檔(v2.1.129+)
claude --plugin-dir <path> 載入目前工作階段使用的 plugin 目錄或.zip封存檔(.zip支援 v2.1.128+)
claude plugin prune 移除其父項已不存在的自動安裝 plugins(v2.1.121+)
claude plugin uninstall <name> --prune 解除安裝並連帶移除成為孤兒的自動安裝相依項(v2.1.121+)
claude plugin tag 建立 release git tags,並進行版本驗證(v2.1.118+)

12. Subagent 類型

類型 預設模型 模式 適用情境
Explore Haiku(快速) 唯讀 程式碼庫搜尋、尋找檔案、理解結構
General-purpose 繼承主要模型 完整讀寫 複雜研究與修改任務
Plan 繼承主要模型 唯讀 執行前規劃實作
Custom 可設定 可設定 領域特定工作(安全性審查、測試等)

Claude會自動委派給 subagents。也可以明確要求使用:

> Use the explore agent to find all auth-related files
> Have a subagent analyze the database schema

自訂 subagents 會以帶有YAML frontmatter 的 markdown 檔案定義於.claude/agents/(專案)或~/.claude/agents/(個人)。最多可平行執行10個 subagents。4

claude agents會在目前版本中開啟 Agent View:這是一個研究預覽版的作業畫面,用於檢視執行中、受阻與已完成的Claude Code工作階段。claude agents --cwd <path>會將檢視範圍限制在單一目錄(v2.1.141+);v2.1.142 為背景工作階段加入 dispatch flags;v2.1.143 則將這些 flags 一致套用到儀表板與背景工作階段:--add-dir--settings--mcp-config--plugin-dir--permission-mode--model--effort--dangerously-skip-permissions。v2.1.144 為背景工作階段加入/resume支援,並以bg標記;v2.1.145 加入claude agents --json、等待輸入分頁計數,以及 Agent View 回覆窗格修正;v2.1.147 加入釘選背景工作階段,使其閒置時仍保持存活,並可就地重新啟動以套用更新。Agent View 適合用於監控,不應作為工作已通過品質關卡的證明。6

自訂 agent frontmatter 欄位:

欄位 用途
name 唯一識別碼(小寫、連字號)
description 何時叫用(若要自動委派,請包含「PROACTIVELY」)
tools 逗號分隔的工具清單。支援Agent(Explore)以限制可產生的類型
disallowedTools 從繼承集合中拒絕使用的工具
model opussonnethaikuinherit(預設)
permissionMode defaultacceptEditsplanbypassPermissions
maxTurns 最大 agentic 回合數
background 設為true時一律以背景任務執行
isolation worktree代表使用隔離的 git worktree 副本

自訂 agent 範例.claude/agents/security-reviewer.md):

---
name: security-reviewer
description: Expert security code reviewer. Use PROACTIVELY after code changes to auth or data handling.
tools: Read, Grep, Glob, Bash
model: opus
permissionMode: plan
---

You are a senior security engineer. Analyze for OWASP Top 10 vulnerabilities,
secrets, hardcoded credentials, and SQL injection. Report findings with severity
levels and remediation steps.

13. 環境變數

驗證與API

變數 用途
ANTHROPIC_API_KEY 直接API驗證
ANTHROPIC_AUTH_TOKEN 自訂 authorization header
ANTHROPIC_CUSTOM_HEADERS 額外 request headers

模型設定

變數 用途
ANTHROPIC_MODEL 覆寫預設模型
CLAUDE_CODE_SUBAGENT_MODEL subagents 使用的模型;v2.1.147 修正其傳遞至 agent-team 隊友程序的問題
CLAUDE_CODE_WORKFLOWS 設為1即可啟用預設關閉的 Workflow 工具,用於確定性的多 agent 編排(v2.1.147+)
MAX_THINKING_TOKENS 啟用延伸思考
CLAUDE_CODE_MAX_OUTPUT_TOKENS 限制輸出長度

雲端供應商

變數 用途
CLAUDE_CODE_USE_BEDROCK=1 使用 AWS Bedrock
CLAUDE_CODE_USE_VERTEX=1 使用 Google Vertex AI
CLAUDE_CODE_USE_FOUNDRY=1 使用 Microsoft Foundry
ANTHROPIC_BEDROCK_SERVICE_TIER=priority Bedrock 服務層級 — default/flex/priority(v2.1.122+);會以X-Amzn-Bedrock-Service-Tier送出
ENABLE_TOOL_SEARCH=true 在 Vertex AI 上選擇啟用 Tool Search(v2.1.119+;預設關閉,以避免不支援的 beta header)
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 /model選擇器選擇啟用 gateway /v1/models探索(v2.1.129+)

行為控制

變數 用途
DISABLE_AUTOUPDATER=1 防止自動更新
DISABLE_UPDATES=1 封鎖所有更新路徑,包含手動claude update(v2.1.118+,比DISABLE_AUTOUPDATER更嚴格)
CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE=1 Homebrew/WinGet 安裝會在背景執行套件管理器升級,並提示重新啟動(v2.1.129+)
CLAUDE_CODE_PLUGIN_PREFER_HTTPS=1 當SSH金鑰不可用時,改用HTTPS而非SSH複製GitHub plugin 來源(v2.1.141+)
CLAUDE_CODE_OPUS_4_6_FAST_MODE_OVERRIDE=1 在 Opus 4.6 保持 Fast 模式,而不是使用 v2.1.142+ 的 Opus 4.7 預設值
CLAUDE_CODE_STOP_HOOK_BLOCK_CAP 覆寫 v2.1.143+ 的上限;該上限會在 stop hooks 反覆阻擋後,以警告結束一個回合
CLAUDE_CODE_POWERSHELL_RESPECT_EXECUTION_POLICY=1 選擇退出 v2.1.143+ 的 PowerShell -ExecutionPolicy Bypass行為
CLAUDE_CODE_USE_POWERSHELL_TOOL=0 在 v2.1.143 為 Bedrock、Vertex 與 Foundry 使用者預設啟用 PowerShell 工具的情況下,停用該工具
DISABLE_TELEMETRY=1 選擇退出使用情況 telemetry
DISABLE_COST_WARNINGS=1 隱藏成本警告
DISABLE_PROMPT_CACHING=1 全域停用 prompt caching
CLAUDE_CODE_DISABLE_1M_CONTEXT=1 使用標準 200K,而非 1M
CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 移除內建 commit/PR 指示
CLAUDE_CODE_HIDE_CWD=1 在啟動畫面 logo 中隱藏工作目錄(v2.1.119+)
CLAUDE_CODE_FORK_SUBAGENT=1 在外部 builds 上 fork subagents(v2.1.117+;v2.1.121+ 可在非互動式-p模式運作)
CLAUDE_CODE_FORCE_SYNC_OUTPUT=1 當自動偵測遺漏時,強制同步終端機輸出(v2.1.129+)

工具設定

變數 用途
BASH_DEFAULT_TIMEOUT_MS Bash 指令逾時(預設 30000)
BASH_MAX_TIMEOUT_MS bash 最大逾時(預設 600000)
MCP_TIMEOUT MCP伺服器啟動逾時(預設 5000)
MCP_TOOL_TIMEOUT MCP工具執行逾時(預設 30000);v2.1.142 修正遠端 HTTP/SSE 呼叫忽略較高值的問題

網路與 Proxy

變數 用途
HTTP_PROXY / HTTPS_PROXY Proxy 設定
NO_PROXY 對特定網域略過 proxy
CLAUDE_CODE_CLIENT_CERT mTLS 憑證路徑
ANTHROPIC_WORKSPACE_ID 當規則橫跨多個 workspaces 時,限定 workload-identity-federated tokens 的範圍(v2.1.141+)

完整清單請參閱完整指南中的環境變數


14. 成本參考

每 100 萬 token 定價(截至 2026年4月)。5

Model Input Output Notes
Opus 4.7 $5.00 $25.00 目前旗艦模型。1M context 採標準定價,無長 context 加價。
Opus 4.6(舊版) $5.00 $25.00 1M context 目前也採標準定價
Sonnet 4.6 $3.00 $15.00 均衡型模型。1M context 採標準定價,無長 context 加價。
Haiku 4.5 $1.00 $5.00 探索、簡單工作

典型 session 會消耗 50K-200K input tokens 與 10K-50K output tokens。Haiku session:約 $0.10-$0.45。Opus session:約 $0.50-$2.25。

各方案預設模型(Claude Code 截至 2026年4月16日):

  • Max、Team Premium → Opus 4.7
  • Pro、Team Standard、Enterprise、Anthropic API → Sonnet 4.6(Enterprise + API 會在 2026年4月23日切換至 Opus 4.7)
  • Bedrock、Vertex、Foundry → Sonnet 4.5(可透過 ANTHROPIC_DEFAULT_OPUS_MODEL 固定使用較新模型)

Opus 4.7 需要 Claude Code v2.1.111 或更新版本。它只使用自適應推理(沒有固定 thinking budgets)。新的 xhigh effort level 是 Opus 4.7 在程式開發/agentic 工作負載上的預設值。

在 session 期間切換模型:

/model opus       # Switch to Opus (resolves to 4.7 on API, 4.6 on Bedrock/Vertex/Foundry)
/model sonnet     # Switch to Sonnet 4.6
/model haiku      # Switch to Haiku 4.5
/effort xhigh     # Opus 4.7 only  recommended for coding/agentic

決策規則:簡單探索交給 Haiku。重視成本的日常程式開發交給 Sonnet。困難推理、架構、agentic loops 與安全分析交給 Opus。複雜重構使用 opusplan(Opus 規劃,Sonnet 執行)。


15. 重要檔案位置

Path Purpose
~/.claude/settings.json 使用者全域設定
~/.claude/keybindings.json 自訂鍵盤快捷鍵
~/.claude/CLAUDE.md 個人指示(所有專案)
~/.claude/commands/ 個人 slash commands
~/.claude/skills/ 個人 skills
~/.claude/agents/ 個人 subagent 定義
~/.claude.json 執行階段狀態、OAuth tokens、MCP config
.claude/settings.json 專案設定(透過 git 共享)
.claude/settings.local.json 專案設定(個人使用,gitignored)
.claude/CLAUDE.md 專案指示
.claude/commands/ 專案 slash commands
.claude/agents/ 專案 subagent 定義
.claude/skills/ 專案 skills
.claude/plans/ Plan mode 輸出檔案
.claude/memory/ Auto-memory 檔案
.mcp.json 專案 MCP server config
CLAUDE.md 專案指示(根目錄替代位置)

16. 變更記錄

Date Change
2026-05-24 將最新版本證據同步至 Claude Code v2.1.150。新增 /usage 分類限制用量、透過 changelog 補上 /diff 鍵盤捲動備註、透過 changelog 補上 GFM task-list checkbox rendering 備註、Enterprise allowAllClaudeAiMcps、PowerShell 權限修正指引,以及 Bash/git-worktree/managed-settings/OTEL/Remote Control 可靠性備註。v2.1.150 本身沒有公布面向使用者的變更。本機驗證:本機 claude --version 回傳 2.1.144 (Claude Code),而 npm latest 為 2.1.1506
2026-05-21 將最新版本證據同步至 Claude Code v2.1.147。新增預設關閉的 Workflow tool(CLAUDE_CODE_WORKFLOWS=1)、釘選 Agent View 背景 sessions、以 /code-review [effort] --comment 取代 /simplify、強化 REPL/Workflow sandboxes、auto-updater 與 large-diff 改進、重複 prompt-history 抑制,以及 enterprise-login、PowerShell、MCP pagination、Agent View、plugin、hook-condition 與 pasted-text 修正。本機驗證:本機 claude --version 回傳 2.1.144 (Claude Code),而 npm latest 為 2.1.1476
2026-05-19 將最新版本證據同步至 Claude Code v2.1.145。新增 claude agents --json、Agent View awaiting-input tab counts、status-line GitHub repo/PR JSON 欄位、更完整的 pre-install plugin discovery、Stop/SubagentStop background_taskssession_crons hook input、OTEL agent_id/parent_agent_id,以及 permission、MCP、spinner、Windows、Agent View、task-list、plugin validation、skill recursion 與 Read tool 修正。本機驗證:本機 claude --version 回傳 2.1.144 (Claude Code),而 npm latest 為 2.1.1456
2026-05-19 將最新版本證據同步至 Claude Code v2.1.144。新增 /resume 對背景 sessions 的支援、/model 目前 session/預設行為、/usage-credits、plugin last-updated 顯示、background-subagent duration notifications,以及 terminal/background-session 可靠性修正。本機驗證:claude --version 回傳 2.1.144 (Claude Code),npm latest 為 2.1.1446
2026-05-18 將最新版本證據同步至 Claude Code v2.1.143。新增 Agent View dispatch consistency、stop-hook block cap、PowerShell policy env vars,並註記 plugin dependency enforcement、projected plugin context cost、worktree.bgIsolation: "none"、background-session model/effort preservation 與 /goal evaluator timing 修正。本機驗證:claude --version 回傳 2.1.142 (Claude Code),而 npm latest 為 2.1.1436
2026-05-15 將最新版本證據同步至 Claude Code v2.1.142。新增 terminalSequenceclaude agents --cwd、v2.1.142 background-session dispatch flags、Fast-mode Opus 4.7 default override、HTTPS plugin clone env var、workload-identity workspace env var,以及 MCP_TOOL_TIMEOUT remote HTTP/SSE 修正備註。本機驗證:claude --version 回傳 2.1.141 (Claude Code),而 npm latest 為 2.1.1426
2026-05-13 將最新版本證據同步至 Claude Code v2.1.140。新增 /goal、Agent View 備註、command-hook argsPostToolUse continueOnBlock,以及 agent hook input 上的 subagent_type。註記 v2.1.140 修正 ConfigChangedisableAllHooksallowManagedHooksOnly 行為。本機驗證:claude --version 回傳 2.1.140 (Claude Code)6
2026-05-06 將最新版本證據同步至 Claude Code v2.1.131。無需變更 command、config、shortcut、hook、plugin 或 env-var 表格,因為 v2.1.131 是針對 VS Code Windows 啟用與 Mantle endpoint authentication 的修正版。6
2026-05-05 同步至 CC guide v2.36(CLI v2.1.126–v2.1.129)。新增:用於 plugin zip 載入的 --plugin-url--plugin-dir.zip 支援、skillOverridesCLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYCLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATECLAUDE_CODE_FORCE_SYNC_OUTPUT,以及 v2.1.129 plugin manifest 對實驗性 themes/monitors 的指引。涵蓋至 v2.1.129。6
2026-04-29 同步至 CC guide v2.35(CLI v2.1.117–v2.1.123)。新增:alwaysLoad MCP 選項 + 啟動時自動重試;claude plugin prune--prune 級聯;claude plugin tag/skills 輸入篩選;/theme 命名 themes;/usage 合併對話框;vim visual modes(v/V);PowerShell 自動核准;hook input 上的 duration_ms + 所有 tools 的 updatedToolOutputprUrlTemplatewslInheritsWindowsSettingsautoMode.allow $defaults;env vars ANTHROPIC_BEDROCK_SERVICE_TIERENABLE_TOOL_SEARCHCLAUDE_CODE_HIDE_CWDDISABLE_UPDATESCLAUDE_CODE_FORK_SUBAGENT--from-pr 接受 GitLab/Bitbucket/GHE PR URLs。涵蓋至 v2.1.123。
2026-04-19 更新:Sonnet 4.6 1M context 目前顯示為標準 $3/$15(無長 context 加價);將定價註腳改為 platform.claude.com/docs/en/about-claude/pricing。涵蓋至 v2.1.116。
2026-04-04 重新依據 CC guide v2.26 推導。新增 /powerup、更新 /release-notes、移除 /vim。更新 Ctrl+X Ctrl+K 快捷鍵。新增 4 個 hook events(CwdChanged、FileChanged、TaskCreated、PermissionDenied)。更新 /cost,加入依模型區分的明細。涵蓋至 v2.1.92。
2026-03-28 cheat sheet 首次發布,涵蓋 Claude Code CLI 至 v2.1.85

17. 參考資料


這份 cheat sheet 是完整 Claude Code CLI指南的快速查閱搭配資料。如需設定逐步說明,請參閱Claude Code quickstart。若是 iOS 與 macOS 專案,請參閱iOS Agent Development指南XcodeBuildMCP整合模式,以及Apple Ecosystem Series。最後更新日期:2026年5月24日。

NORMAL claude-code-cheatsheet.md EOF