了解如何為您的組織配置 Claude Code 的使用者驗證、授權和存取控制。
工具類型 | 範例 | 需要核准 | ”是,不要再問” 行為 |
---|---|---|---|
唯讀 | 檔案讀取、LS、Grep | 否 | 不適用 |
Bash 命令 | Shell 執行 | 是 | 每個專案目錄和命令永久生效 |
檔案修改 | 編輯/寫入檔案 | 是 | 直到會話結束 |
/permissions
檢視和管理 Claude Code 的工具權限。此 UI 列出所有權限規則和它們來源的 settings.json 檔案。
Tool
或 Tool(optional-specifier)
僅為工具名稱的規則匹配該工具的任何使用。例如,將 Bash
新增到 allow 規則清單中將允許 Claude Code 使用 Bash 工具而無需使用者核准。
defaultMode
:
模式 | 描述 |
---|---|
default | 標準行為 - 在首次使用每個工具時提示權限 |
acceptEdits | 自動接受會話的檔案編輯權限 |
plan | 計劃模式 - Claude 可以分析但不能修改檔案或執行命令 |
bypassPermissions | 跳過所有權限提示(需要安全環境 - 請參閱下方警告) |
--add-dir <path>
CLI 參數/add-dir
斜線命令additionalDirectories
Bash(npm run build)
匹配確切的 Bash 命令 npm run build
Bash(npm run test:*)
匹配以 npm run test
開頭的 Bash 命令Bash(curl http://site.com/:*)
匹配以確切 curl http://site.com/
開頭的 curl 命令&&
),因此像 Bash(safe-cmd:*)
這樣的前綴匹配規則不會給它執行命令 safe-cmd && other-cmd
的權限:*
只能在模式末尾使用以匹配任何延續Bash(curl http://github.com/:*)
這樣的模式可以透過多種方式繞過:
curl -X GET http://github.com/...
不會匹配curl https://github.com/...
不會匹配curl -L http://bit.ly/xyz
(重新導向到 github)URL=http://github.com && curl $URL
不會匹配curl http://github.com
不會匹配WebFetch(domain:github.com)
權限Edit
規則適用於所有編輯檔案的內建工具。Claude 將盡力將 Read
規則應用於所有讀取檔案的內建工具,如 Grep、Glob 和 LS。
Read 和 Edit 規則都遵循 gitignore 規範,具有四種不同的模式類型:
模式 | 意義 | 範例 | 匹配 |
---|---|---|---|
//path | 從檔案系統根目錄的絕對路徑 | Read(//Users/alice/secrets/**) | /Users/alice/secrets/** |
~/path | 從家目錄的路徑 | Read(~/Documents/*.pdf) | /Users/alice/Documents/*.pdf |
/path | 相對於設定檔案的路徑 | Edit(/src/**/*.ts) | <設定檔案路徑>/src/**/*.ts |
path 或 ./path | 相對於當前目錄的路徑 | Read(*.env) | <cwd>/*.env |
/Users/alice/file
這樣的模式不是絕對路徑 - 它是相對於您的設定檔案的!使用 //Users/alice/file
表示絕對路徑。Edit(/docs/**)
- 在 <project>/docs/
中編輯(不是 /docs/
!)Read(~/.zshrc)
- 讀取您家目錄的 .zshrc
Edit(//tmp/scratch.txt)
- 編輯絕對路徑 /tmp/scratch.txt
Read(src/**)
- 從 <current-directory>/src/
讀取WebFetch(domain:example.com)
匹配對 example.com 的取得請求mcp__puppeteer
匹配由 puppeteer
伺服器提供的任何工具(在 Claude Code 中配置的名稱)mcp__puppeteer__puppeteer_navigate
匹配由 puppeteer
伺服器提供的 puppeteer_navigate
工具*
)。要核准來自 MCP 伺服器的所有工具:mcp__github
(核准所有 GitHub 工具)mcp__github__*
(不支援萬用字元)mcp__github__get_issue
mcp__github__list_issues
/Library/Application Support/ClaudeCode/managed-settings.json
/etc/claude-code/managed-settings.json
C:\ProgramData\ClaudeCode\managed-settings.json
.claude/settings.local.json
).claude/settings.json
)~/.claude/settings.json
)apiKeyHelper
設定可以配置為執行返回 API 金鑰的 shell 腳本。apiKeyHelper
在 5 分鐘後或在 HTTP 401 回應時被呼叫。設定 CLAUDE_CODE_API_KEY_HELPER_TTL_MS
環境變數以自訂重新整理間隔。