dcg卸载完全指南:一键清除所有钩子、配置与历史数据
【免费下载链接】destructive_command_guardThe Destructive Command Guard (dcg) is for blocking dangerous git and shell commands from being executed by agents.项目地址: https://gitcode.com/GitHub_Trending/de/destructive_command_guard
当你不再需要 dcg(Destructive Command Guard)时,直接删掉二进制文件是不够的——它还往各个 AI 编码助手的配置文件里写入了拦截钩子,并留下了配置目录和历史数据库。本指南教你用官方卸载脚本一键清除 dcg 钩子、配置与历史数据,让系统干净如初。
为什么不能只删二进制文件?
dcg 在 install.sh 安装时会在多个地方留下"痕迹":
- AI 助手钩子:写入 Claude Code、Codex CLI、Gemini CLI、GitHub Copilot、Cursor、Aider 等工具的设置文件
- 配置文件:
~/.config/dcg/config.toml(含自定义规则包与白名单) - 历史数据:
history.db拦截记录数据库、备份目录,以及~/.local/share/dcg日志数据
如果只删dcg可执行文件,AI 助手每次执行命令时仍会去调用一个已不存在的路径,导致报错刷屏。因此必须使用配套的卸载脚本 uninstall.sh。
macOS / Linux:一键卸载步骤
官方提供的卸载脚本与安装脚本一一对应,执行后会先预览将要删除的内容,再请求确认:
curl -fsSL <仓库中的 uninstall.sh> | bash脚本入口说明:uninstall.sh
脚本会自动完成以下清理(见 uninstall.sh 的main流程):
- 移除 Claude Code(
~/.claude/settings.json)中的 PreToolUse 钩子 - 移除 Gemini CLI(
~/.gemini/settings.json)中的 BeforeTool 钩子 - 移除 Copilot、Cursor(含
dcg-pre-shell.py桥接脚本)、Codex CLI(~/.codex/hooks.json)、Hermes、Posit Assistant、OpenCode、Oh My Pi 等扩展 - 删除 Aider 配置中由 dcg 添加的行(删除前自动备份原文件)
- 删除
~/.config/dcg配置目录与~/.local/share/dcg历史数据 - 删除
~/.local/bin/dcg二进制文件
最后提示重启已打开的 AI 编码助手使更改生效。
常用卸载参数一览
| 参数 | 作用 | 适用场景 |
|---|---|---|
--yes | 跳过确认提示 | 无交互环境(CI、远程终端) |
--keep-config | 保留~/.config/dcg/配置 | 以后可能重装,想保留自定义规则 |
--keep-history | 保留 history.db 与备份 | 需要审计历史拦截记录 |
--purge | 彻底清除一切(覆盖保留选项) | 换机、完全告别 |
--quiet | 只输出错误信息 | 批量运维 |
例如想保留配置以便日后重装,只清除钩子和历史:
bash uninstall.sh --keep-configWindows:PowerShell 原生卸载
Windows 用户使用 uninstall.ps1,除上述清理外,它还会额外处理 Windows 特有状态:
- 从用户 PATH 环境变量中移除
~\.local\bin - 清除
%APPDATA%\dcg(Roaming 配置)与%LOCALAPPDATA%\dcg(本地数据) - 同时清理 XDG 风格的遗留路径
~\.config\dcg,兼容旧版本安装
# 标准卸载(带确认提示) & (iwr https://gitcode.com/GitHub_Trending/de/destructive_command_guard/raw/main/uninstall.ps1) -Content # 彻底清除 & (iwr ...) -Purge主要开关:-Yes(跳过确认)、-KeepConfig、-KeepHistory、-KeepPath(保留 PATH 项)、-Purge(全覆盖式清除)、-Quiet(安静模式)。
卸载是否安全?会不会误删别的工具?
这是很多用户担心的问题。卸载脚本在删除任何 JSON/YAML 配置项时,都采用二进制名精确匹配(basename 等于dcg)而非子串匹配——哪怕你的机器上存在/opt/dcgrep/或dcgworkflow这类名字相近的工具,也绝不会被误伤。这一安全设计在 uninstall.sh 的注释中有明确说明,并配套了完整的回归测试:
- Unix 端测试:tests/install/uninstall_test.bats
- Windows 端测试:tests/installer/uninstall_test.ps1
测试验证了"只删 dcg、保留共存钩子"的核心不变量:同一 matcher 组里其他工具配置的钩子会原样保留,只有 dcg 独占的空组才会被移除。
卸载后的验证清单
执行完卸载脚本后,可以逐项确认系统已恢复干净:
| 检查项 | 命令 |
|---|---|
| 二进制已删除 | command -v dcg(应无输出) |
| 配置已清除 | ls ~/.config/dcg(应提示不存在) |
| 历史已清除 | ls ~/.local/share/dcg(应提示不存在) |
| 钩子已移除 | 打开~/.claude/settings.json确认无 dcg 条目 |
| 重启助手 | 重启 Claude Code / Cursor / Codex 等已打开的客户端 |
如果某项残留,可参考官方故障排查文档 docs/troubleshooting.md,或手动删除对应文件。
总结
- 用 uninstall.sh / uninstall.ps1 卸载,不要只删二进制
- 脚本会先预览、再确认,并精确清理所有 AI 助手钩子、
~/.config/dcg配置与history.db历史数据 - 想保留配置用
--keep-config,彻底清除用--purge - 卸载后重启已打开的 AI 编码助手,即可干净完成与 dcg 的告别
【免费下载链接】destructive_command_guardThe Destructive Command Guard (dcg) is for blocking dangerous git and shell commands from being executed by agents.项目地址: https://gitcode.com/GitHub_Trending/de/destructive_command_guard
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考