6.4 --disallowedTools - 禁止的工具列表
--disallowedTools 標誌允許您指定應禁止的工具列表,無需提示使用者獲得許可權。這可以防止 Claude Code 執行危險或不需要的操作。
标志语法
bash
claude --disallowedTools <tool1> <tool2> ... [其他选项]
功能描述
--disallowedTools 標誌會:
- 指定禁止的工具列表
- 這些工具在使用時會被拒絕,無需提示使用者
- 其他工具仍可正常使用
使用示例
基本用法
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:*)"
禁止需要提升許可權的操作。