C Claude Code Internals
| EN | ES

权限系统

Claude Code 有 6 种权限模式,控制如何批准或拒绝工具调用。自动模式使用称为 YOLO 分类器的 2 阶段 AI 分类器来决定,无需询问用户。

6 权限模式 2 分类器阶段 64 第 1 阶段 token 限制 4096 第 2 阶段 token 限制

权限模式

default low risk

敏感操作询问用户。大多数会话的标准模式。

acceptEdits low risk

自动批准所有文件读/写/编辑操作。Shell 和网络仍会提示。

bypassPermissions high risk

自动批准每个工具调用,包括破坏性操作。无安全检查。

dontAsk low risk

不询问,自动拒绝任何通常会提示的工具调用。由 Claude Code Guide 代理使用。

auto medium risk

AI 分类器决定允许/阻止而不询问。使用 2 阶段管道。危险模式始终被阻止。

plan low risk

具有受限工具访问的特殊计划模式。如激活则运行分类器,否则回退到正常模式。

YOLO 分类器(自动模式)

当自动模式激活时,每个工具调用都通过 2 阶段 XML 分类器, 决定允许或阻止,无需用户参与。

1
Stage 1: Fast decision 64 tokens
64 tokens max. Immediate yes/no. If the answer is clearly "allow", it passes instantly. No chain-of-thought.
2
Stage 2: Deep reasoning 4096 tokens
Only runs if Stage 1 blocks. Up to 4096 tokens of chain-of-thought reasoning before reaching a verdict.
3
Output: <block>no</block>
Tool call is allowed. No output shown to user.
4
Output: <block>yes</block><reason>…</reason>
Tool call is blocked. One-sentence reason is shown. Claude receives denial tracking increment.
5
Fallback: interactive mode
If denial threshold is exceeded (too many consecutive blocks), auto mode falls back to asking the user. Resets on any successful tool use.

自动模式下阻止的模式

这些命令模式被分类为高风险,在自动模式下被 YOLO 分类器阻止。 你必须手动批准它们。

解释器
pythonnodedenorubyperlphplua
包运行器
npxbunxnpm runyarn runbun run
Shell
bashshssh
Eval / exec
evalexecsudo
网络
curlwget
云 CLI
kubectlawsgcloudgsutil
Git
git (hooks 风险)
GitHub
ghgh api

工具调用如何决定

1
Tool matched by allow rules?
→ Allow immediately
2
Tool matched by deny rules?
→ Deny immediately
3
Tool's checkPermissions() method
Each tool can return allow / ask / deny directly.
4
Mode handling
bypassPermissions → allow all. dontAsk → convert ask→deny. auto → run classifier. acceptEdits → fast-path for safe ops.
5
Fallback: interactive prompt
Ask the user if no rule matched and mode allows it.
× bypassPermissions 跳过所有检查
在 bypassPermissions 模式下,没有任何安全检查:没有分类器、没有拒绝规则、 没有交互式提示。每个工具调用都会自动批准,包括破坏性操作。 仅在完全受信任的隔离环境中使用此模式。