--disallowedTools 参数

指定禁止的工具列表,防止危险操作

概述

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

标志语法

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

功能描述

--disallowedTools 标志会:

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

使用示例

基本用法

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

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

禁止写入操作

claude --disallowedTools "Edit" "Write"

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

禁止危险命令

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

禁止危险的系统命令。

结合其他标志

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

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

使用场景

保护重要文件

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

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

只读分析

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

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

禁止特定操作

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

禁止 git 提交和推送操作。

安全环境

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

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

与 --allowedTools 的对比

标志行为适用场景
--allowedTools白名单,只允许指定的工具严格控制,只允许特定操作
--disallowedTools黑名单,禁止指定的工具灵活控制,禁止危险操作

相关标志

  • --allowedTools:允许的工具列表
  • --dangerously-skip-permissions:跳过所有权限提示
  • --permission-mode:指定权限模式

On this page