跳轉到主要內容

CLI 命令

您可以使用這些命令來啟動工作階段、管道內容、繼續對話和管理更新:
命令描述範例
claude啟動互動式工作階段claude
claude "query"使用初始提示啟動互動式工作階段claude "explain this project"
claude -p "query"透過 SDK 查詢,然後退出claude -p "explain this function"
cat file | claude -p "query"處理管道內容cat logs.txt | claude -p "explain"
claude -c在目前目錄中繼續最近的對話claude -c
claude -c -p "query"透過 SDK 繼續claude -c -p "Check for type errors"
claude -r "<session>" "query"按 ID 或名稱繼續工作階段claude -r "auth-refactor" "Finish this PR"
claude update更新至最新版本claude update
claude auth login登入您的 Anthropic 帳戶。使用 --email 預先填入您的電子郵件地址,使用 --sso 強制進行 SSO 驗證,使用 --console 以 Anthropic Console 登入以進行 API 使用計費,而不是 Claude 訂閱claude auth login --console
claude auth logout從您的 Anthropic 帳戶登出claude auth logout
claude auth status以 JSON 格式顯示驗證狀態。使用 --text 以人類可讀的格式輸出。如果已登入則以代碼 0 退出,如果未登入則以代碼 1 退出claude auth status
claude agents列出所有已設定的 subagents,按來源分組claude agents
claude auto-mode defaults以 JSON 格式列印內建的 auto mode 分類器規則。使用 claude auto-mode config 查看您的有效設定及套用的設定claude auto-mode defaults > rules.json
claude mcp設定 Model Context Protocol (MCP) 伺服器請參閱 Claude Code MCP 文件
claude plugin管理 Claude Code plugins。別名:claude plugins。請參閱 plugin 參考 以了解子命令claude plugin install code-review@claude-plugins-official
claude remote-control啟動 Remote Control 伺服器以從 Claude.ai 或 Claude 應用程式控制 Claude Code。在伺服器模式下執行(無本機互動式工作階段)。請參閱 伺服器模式旗標claude remote-control --name "My Project"

CLI 旗標

使用這些命令列旗標自訂 Claude Code 的行為。claude --help 不會列出每個旗標,因此旗標在 --help 中的缺失並不表示它無法使用。
旗標描述範例
--add-dir新增額外的工作目錄供 Claude 讀取和編輯檔案。授予檔案存取權;大多數 .claude/ 設定 未從這些目錄探索。驗證每個路徑是否存在為目錄claude --add-dir ../apps ../lib
--agent為目前工作階段指定代理程式(覆蓋 agent 設定)claude --agent my-custom-agent
--agents透過 JSON 動態定義自訂 subagents。使用與 subagent frontmatter 相同的欄位名稱,加上代理程式指示的 prompt 欄位claude --agents '{"reviewer":{"description":"Reviews code","prompt":"You are a code reviewer"}}'
--allow-dangerously-skip-permissions新增 bypassPermissionsShift+Tab 模式循環而不立即啟動它。允許您以不同的模式(如 plan)開始,稍後切換到 bypassPermissions。請參閱 permission modesclaude --permission-mode plan --allow-dangerously-skip-permissions
--allowedTools無需提示權限即可執行的工具。請參閱 permission rule syntax 以了解模式匹配。若要限制可用的工具,請改用 --tools"Bash(git log *)" "Bash(git diff *)" "Read"
--append-system-prompt將自訂文字附加到預設系統提示的末尾claude --append-system-prompt "Always use TypeScript"
--append-system-prompt-file從檔案載入額外的系統提示文字並附加到預設提示claude --append-system-prompt-file ./extra-rules.txt
--bare最小模式:跳過 hooks、skills、plugins、MCP 伺服器、自動記憶體和 CLAUDE.md 的自動探索,以便指令碼呼叫啟動更快。Claude 可以存取 Bash、檔案讀取和檔案編輯工具。設定 CLAUDE_CODE_SIMPLE。請參閱 bare modeclaude --bare -p "query"
--betas要包含在 API 請求中的 Beta 標頭(僅限 API 金鑰使用者)claude --betas interleaved-thinking
--channels(研究預覽)MCP 伺服器,其 channel 通知 Claude 應在此工作階段中監聽。以空格分隔的 plugin:<name>@<marketplace> 項目清單。需要 Claude.ai 驗證claude --channels plugin:my-notifier@my-marketplace
--chrome啟用 Chrome 瀏覽器整合 以進行網頁自動化和測試claude --chrome
--continue, -c載入目前目錄中最近的對話claude --continue
--dangerously-load-development-channels啟用不在核准允許清單上的 channels,用於本機開發。接受 plugin:<name>@<marketplace>server:<name> 項目。提示確認claude --dangerously-load-development-channels server:webhook
--dangerously-skip-permissions略過權限提示。等同於 --permission-mode bypassPermissions。請參閱 permission modes 以了解此操作會和不會略過的內容claude --dangerously-skip-permissions
--debug啟用偵錯模式,可選類別篩選(例如,"api,hooks""!statsig,!file"claude --debug "api,mcp"
--debug-file <path>將偵錯日誌寫入特定檔案路徑。隱含啟用偵錯模式。優先於 CLAUDE_CODE_DEBUG_LOGS_DIRclaude --debug-file /tmp/claude-debug.log
--disable-slash-commands為此工作階段停用所有 skills 和命令claude --disable-slash-commands
--disallowedTools從模型的內容中移除且無法使用的工具"Bash(git log *)" "Bash(git diff *)" "Edit"
--effort為目前工作階段設定 effort level。選項:lowmediumhighmax(僅限 Opus 4.6)。工作階段範圍且不會持久化到設定claude --effort high
--fallback-model當預設模型過載時啟用自動回退到指定的模型(僅列印模式)claude -p --fallback-model sonnet "query"
--fork-session繼續時,建立新的工作階段 ID 而不是重複使用原始 ID(與 --resume--continue 搭配使用)claude --resume abc123 --fork-session
--from-pr繼續連結到特定 GitHub PR 的工作階段。接受 PR 編號或 URL。透過 gh pr create 建立時會自動連結工作階段claude --from-pr 123
--ide如果恰好有一個有效的 IDE 可用,在啟動時自動連線到 IDEclaude --ide
--init執行初始化 hooks 並啟動互動模式claude --init
--init-only執行初始化 hooks 並退出(無互動式工作階段)claude --init-only
--include-hook-events在輸出串流中包含所有 hook 生命週期事件。需要 --output-format stream-jsonclaude -p --output-format stream-json --include-hook-events "query"
--include-partial-messages在輸出中包含部分串流事件。需要 --print--output-format stream-jsonclaude -p --output-format stream-json --include-partial-messages "query"
--input-format為列印模式指定輸入格式(選項:textstream-jsonclaude -p --output-format json --input-format stream-json
--json-schema在代理程式完成其工作流程後取得符合 JSON Schema 的驗證 JSON 輸出(僅列印模式,請參閱 structured outputsclaude -p --json-schema '{"type":"object","properties":{...}}' "query"
--maintenance執行維護 hooks 並啟動互動模式claude --maintenance
--max-budget-usd在停止前在 API 呼叫上花費的最大美元金額(僅列印模式)claude -p --max-budget-usd 5.00 "query"
--max-turns限制代理程式轉數(僅列印模式)。達到限制時以錯誤退出。預設無限制claude -p --max-turns 3 "query"
--mcp-config從 JSON 檔案或字串載入 MCP 伺服器(以空格分隔)claude --mcp-config ./mcp.json
--model使用最新模型的別名(sonnetopus)或模型的完整名稱為目前工作階段設定模型claude --model claude-sonnet-4-6
--name, -n為工作階段設定顯示名稱,顯示在 /resume 和終端標題中。您可以使用 claude --resume <name> 繼續已命名的工作階段。

/rename 在工作階段中途變更名稱,也會在提示列中顯示
claude -n "my-feature-work"
--no-chrome為此工作階段停用 Chrome 瀏覽器整合claude --no-chrome
--no-session-persistence停用工作階段持久性,使工作階段不會儲存到磁碟且無法繼續(僅列印模式)claude -p --no-session-persistence "query"
--output-format為列印模式指定輸出格式(選項:textjsonstream-jsonclaude -p "query" --output-format json
--enable-auto-modeShift+Tab 循環中解鎖 auto mode。需要 Team、Enterprise 或 API 方案以及 Claude Sonnet 4.6 或 Opus 4.6claude --enable-auto-mode
--permission-mode以指定的 permission mode 開始。接受 defaultacceptEditsplanautodontAskbypassPermissions。覆蓋設定檔案中的 defaultModeclaude --permission-mode plan
--permission-prompt-tool指定 MCP 工具以在非互動模式下處理權限提示claude -p --permission-prompt-tool mcp_auth_tool "query"
--plugin-dir為此工作階段僅從目錄載入 plugins。每個旗標採用一個路徑。重複旗標以使用多個目錄:--plugin-dir A --plugin-dir Bclaude --plugin-dir ./my-plugins
--print, -p列印回應而不進入互動模式(請參閱 Agent SDK 文件 以了解程式化使用詳細資訊)claude -p "query"
--remote在 claude.ai 上建立新的 web session,並提供工作描述claude --remote "Fix the login bug"
--remote-control, --rc啟動互動式工作階段,並啟用 Remote Control,以便您也可以從 claude.ai 或 Claude 應用程式控制它。可選擇傳遞工作階段的名稱claude --remote-control "My Project"
--replay-user-messages從 stdin 重新發出使用者訊息回到 stdout 以進行確認。需要 --input-format stream-json--output-format stream-jsonclaude -p --input-format stream-json --output-format stream-json --replay-user-messages
--resume, -r按 ID 或名稱繼續特定工作階段,或顯示互動式選擇器以選擇工作階段claude --resume auth-refactor
--session-id為對話使用特定的工作階段 ID(必須是有效的 UUID)claude --session-id "550e8400-e29b-41d4-a716-446655440000"
--setting-sources要載入的設定來源的逗號分隔清單(userprojectlocalclaude --setting-sources user,project
--settings設定 JSON 檔案的路徑或要載入其他設定的 JSON 字串claude --settings ./settings.json
--strict-mcp-config僅使用 --mcp-config 中的 MCP 伺服器,忽略所有其他 MCP 設定claude --strict-mcp-config --mcp-config ./mcp.json
--system-prompt用自訂文字取代整個系統提示claude --system-prompt "You are a Python expert"
--system-prompt-file從檔案載入系統提示,取代預設提示claude --system-prompt-file ./custom-prompt.txt
--teleport在本機終端中繼續 web sessionclaude --teleport
--teammate-mode設定 agent team 隊友的顯示方式:auto(預設)、in-processtmux。請參閱 Choose a display modeclaude --teammate-mode in-process
--tmux為 worktree 建立 tmux 工作階段。需要 --worktree。在可用時使用 iTerm2 原生窗格;傳遞 --tmux=classic 以使用傳統 tmuxclaude -w feature-auth --tmux
--tools限制 Claude 可以使用的內建工具。使用 "" 停用全部,"default" 為全部,或工具名稱如 "Bash,Edit,Read"claude --tools "Bash,Edit,Read"
--verbose啟用詳細記錄,顯示完整的逐轉輸出claude --verbose
--version, -v輸出版本號claude -v
--worktree, -w在隔離的 git worktree 中啟動 Claude,位於 <repo>/.claude/worktrees/<name>。如果未提供名稱,則會自動產生一個claude -w feature-auth

系統提示旗標

Claude Code 提供四個旗標用於自訂系統提示。所有四個都在互動和非互動模式中運作。
旗標行為範例
--system-prompt取代整個預設提示claude --system-prompt "You are a Python expert"
--system-prompt-file用檔案內容取代claude --system-prompt-file ./prompts/review.txt
--append-system-prompt附加到預設提示claude --append-system-prompt "Always use TypeScript"
--append-system-prompt-file將檔案內容附加到預設提示claude --append-system-prompt-file ./style-rules.txt
--system-prompt--system-prompt-file 互斥。附加旗標可以與任一取代旗標組合。 對於大多數使用案例,請使用附加旗標。附加會保留 Claude Code 的內建功能,同時新增您的需求。僅當您需要對系統提示進行完全控制時,才使用取代旗標。

另請參閱