Skip to content

6.4 --disallowedTools - 禁止的工具列表

--disallowedTools 标志允许您指定应禁止的工具列表,无需提示用户获得权限。这可以防止 Claude Code 执行危险或不需要的操作。

标志语法

bash


claude --disallowedTools <tool1> <tool2> ... [其他选项]

功能描述

--disallowedTools 标志会:

  1. 指定禁止的工具列表
  2. 这些工具在使用时会被拒绝,无需提示用户
  3. 其他工具仍可正常使用

使用示例

基本用法

bash


claude --disallowedTools "Bash(rm:*)" "Bash(rmdir:*)"

禁止删除文件和目录的命令。

禁止写入操作

bash


claude --disallowedTools "Edit" "Write"

禁止文件写入和编辑操作。

禁止危险命令

bash


claude --disallowedTools "Bash(rm:*)" "Bash(dd:*)" "Bash(mkfs:*)"

禁止危险的系统命令。

结合其他标志

bash


claude --disallowedTools "Bash(git push:*)" --add-dir ./src

禁止 git push 操作,同时添加工作目录。

使用场景

1. 保护重要文件

bash


claude --disallowedTools "Edit" "Write" "Bash(rm:*)"

防止意外修改或删除重要文件。

2. 只读分析

bash


claude --disallowedTools "Edit" "Write" "Bash(*:*)"

只允许读取操作,禁止任何修改。

3. 禁止特定操作

bash


claude --disallowedTools "Bash(git push:*)" "Bash(git commit:*)"

禁止 git 提交和推送操作。

4. 安全环境

bash


claude --disallowedTools "Bash(sudo:*)" "Bash(chown:*)" "Bash(chmod:*)"

禁止需要提升权限的操作。

基于 MIT 许可发布 | 永久导航