camjac251/tool-gates

GitHub: camjac251/tool-gates

一个用 Rust 编写的 AI 编程助手智能权限网关,通过 Bash AST 解析实现精确的命令分析和分级审批,支持 300+ 命令的安全策略控制。

Stars: 2 | Forks: 0

# Tool Gates *原名 `bash-gates`* **AI 编程助手的智能工具权限网关** [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/b47e8a0676030805.svg)](https://github.com/camjac251/tool-gates/actions/workflows/ci.yml) [![Release](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/fae4a4bf80030806.svg)](https://github.com/camjac251/tool-gates/actions/workflows/release.yml) [![Rust](https://img.shields.io/badge/rust-1.85+-orange.svg)](https://www.rust-lang.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) 一个 Claude Code [hook](https://code.claude.com/docs/en/hooks),利用 AST 解析对 Bash 命令、文件操作和工具调用进行把关——根据潜在影响决定是允许、询问还是阻止。 [安装](#installation) · [权限网关](#permission-gates) · [安全](#security-features) · [测试](#testing)
## 功能 | 功能 | 描述 | | ------------------------ | ------------------------------------------------------------------------------------------------------ | | **审批学习** | 跟踪已批准的命令,并通过 TUI 或 CLI 将模式保存到 settings.json | | **设置集成** | 遵循您的 `settings.json` 允许/拒绝/询问规则 - 不会绕过您的显式权限 | | **接受编辑模式** | 在 acceptEdits 模式下,自动允许文件编辑命令(`sd`, `prettier --write` 等) | | **现代 CLI 提示** | 通过 `additionalContext` 建议现代替代工具(`bat`, `rg`, `fd` 等),帮助 Claude 学习 | | **AST 解析** | 使用 [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) 进行精确的命令分析 | | **复合命令** | 正确处理 `&&`, `\|\|`, `\|`, `;` 链 | | **安全第一** | 捕获管道到 shell、eval、命令注入模式 | | **未知保护** | 无法识别的命令需要审批 | | **Claude Code 插件** | 作为插件安装,提供 `/tool-gates:review` 技能用于交互式审批管理 | | **300+ 命令** | 13 个专用网关,覆盖全面 | | **文件卫士** | 阻止符号链接的 AI 配置文件(CLAUDE.md, .cursorrules 等),以防止混淆读取/编辑 | | **工具阻断** | 可配置规则以阻断工具(如 Glob, Grep, firecrawl 在 GitHub 上),支持域名过滤 | | **配置** | `~/.config/tool-gates/config.toml` 用于功能开关、自定义阻断规则和文件卫士扩展 | | **快速** | 静态原生二进制文件,无解释器开销 | ## 工作原理 ``` flowchart TD CC[Claude Code] --> CMD[Bash Command] subgraph PTU [PreToolUse Hook] direction TB PTU_CHECK[tool-gates check] --> PTU_DEC{Decision} PTU_DEC -->|dangerous| PTU_DENY[deny] PTU_DEC -->|risky| PTU_ASK[ask + track] PTU_DEC -->|safe| PTU_CTX{Context?} PTU_CTX -->|main session| PTU_ALLOW[allow ✓] PTU_CTX -->|subagent| PTU_IGNORED[ignored by Claude] end CMD --> PTU PTU_IGNORED --> INTERNAL[Claude internal checks] INTERNAL -->|path outside cwd| PR_HOOK subgraph PR_HOOK [PermissionRequest Hook] direction TB PR_CHECK[tool-gates re-check] --> PR_DEC{Decision} PR_DEC -->|safe| PR_ALLOW[allow ✓] PR_DEC -->|dangerous| PR_DENY[deny] PR_DEC -->|risky| PR_PROMPT[show prompt] end PTU_ASK --> EXEC[Command Executes] PR_PROMPT --> USER_APPROVE[User Approves] --> EXEC subgraph POST [PostToolUse Hook] direction TB POST_CHECK[check tracking] --> POST_DEC{Tracked + Success?} POST_DEC -->|yes| PENDING[add to pending queue] POST_DEC -->|no| POST_SKIP[skip] end EXEC --> POST PENDING --> REVIEW[tool-gates review] REVIEW --> SETTINGS[settings.json] ``` **为什么有三个 hook?** - **PreToolUse**: 为主会话把关命令,跟踪“询问”决策 - **PermissionRequest**: 为子智能体把关命令(PreToolUse 的 `allow` 在此会被忽略) - **PostToolUse**: 检测成功执行,排队等待永久审批 **决策优先级:** `阻断 > 询问 > 允许 > 跳过` | 决策 | 效果 | | :-------: | --------------------------- | | **拒绝** | 命令被阻断并附带原因 | | **询问** | 提示用户审批 | | **允许** | 自动批准 | ### settings.json 集成 tool-gates 读取 `~/.claude/settings.json` 和 `.claude/settings.json`(项目)中的 Claude Code 设置,以遵循您的显式权限规则: | settings.json | tool-gates | 结果 | | ------------- | ---------- | -------------------------------------------- | | `deny` 规则 | (任意) | 延迟至 Claude Code(遵循您的拒绝) | | `ask` 规则 | (任意) | 延迟至 Claude Code(遵循您的询问) | | `allow` 规则 | 危险 | **拒绝**(tool-gates 仍会阻断危险操作) | | `allow`/无 | 安全 | **允许** | | 无 | 未知 | **询问** | 这确保了 tool-gates 不会意外绕过您的显式拒绝规则,同时仍能防御危险命令。 **设置文件优先级**(最高者胜出): | 优先级 | 位置 | 描述 | | ----------- | ---------------------------------------- | ----------------------------- | | 1 (最高) | `/etc/claude-code/managed-settings.json` | 企业托管 | | 2 | `.claude/settings.local.json` | 本地项目(未提交) | | 3 | `.claude/settings.json` | 共享项目(已提交) | | 4 (最低) | `~/.claude/settings.json` | 用户设置 | ### 接受编辑模式 当 Claude Code 处于 `acceptEdits` 模式时,tool-gates 自动允许文件编辑命令: ``` # 在 acceptEdits 模式下 - 自动允许 sd 'old' 'new' file.txt # Text replacement prettier --write src/ # Code formatting ast-grep -p 'old' -r 'new' -U . # Code refactoring sed -i 's/foo/bar/g' file.txt # In-place sed black src/ # Python formatting eslint --fix src/ # Linting with fix ``` **仍需审批(即使在 acceptEdits 模式下):** - 包管理器:`npm install`, `cargo add` - Git 操作:`git push`, `git commit` - 删除操作:`rm`, `mv` - 被阻断的命令:`rm -rf /` 仍会被拒绝 ### 现代 CLI 提示 _需要 Claude Code 1.0.20+_ 当 Claude 使用旧版命令时,tool-gates 会通过 `additionalContext` 建议现代替代工具。这有助于 Claude 随着时间推移学习更好的模式,而无需修改命令。 ``` # Claude 运行:cat README.md # tool-gates 返回: { "hookSpecificOutput": { "permissionDecision": "allow", "additionalContext": "Tip: Use 'bat README.md' for syntax highlighting and line numbers (Markdown rendering)" } } ``` | 旧版命令 | 现代替代 | 触发时机 | | ----------------------------- | ------------------ | ------------------------------------ | | `cat`, `head`, `tail`, `less` | `bat` | 总是(`tail -f` 除外) | | `grep` (代码模式) | `sg` | AST 感知的代码搜索 | | `grep` (文本/日志/配置) | `rg` | 任何 grep 用法 | | `find` | `fd` | 总是 | | `ls` | `eza` | 带 `-l` 或 `-a` 标志 | | `sed` | `sd` | 替换模式 (`s/.../.../`) | | `awk` | `choose` | 字段提取 (`print $`) | | `du` | `dust` | 总是 | | `ps` | `procs` | 带 `aux`, `-e`, `-A` 标志 | | `curl`, `wget` | `xh` | JSON API 或详细模式 | | `diff` | `delta` | 双文件比较 | | `xxd`, `hexdump` | `hexyl` | 总是 | | `cloc` | `tokei` | 总是 | | `tree` | `eza -T` | 总是 | | `man` | `tldr` | 总是 | | `wc -l` | `rg -c` | 行计数 | **仅建议已安装的工具。** 提示会被缓存(7天 TTL)以避免重复调用 `which`。 ``` # 刷新 tool detection 缓存 tool-gates --refresh-tools # 检查检测到哪些工具 tool-gates --tools-status ``` ### 审批学习 当您批准命令(通过 Claude Code 的权限提示)时,tool-gates 会跟踪它们,并允许您将模式永久保存到 settings.json。 ``` # 批准部分命令后,查看待批准项 tool-gates pending list # 交互式 TUI 仪表板 tool-gates review # current project only tool-gates review --all # all projects # 或直接通过 CLI 批准 tool-gates approve 'npm install*' -s local tool-gates approve 'cargo*' -s user # 管理现有规则 tool-gates rules list tool-gates rules remove 'pattern' -s local ``` **作用域:** | 作用域 | 文件 | 用例 | |-------|------|----------| | `local` | `.claude/settings.local.json` | 个人项目覆盖(未提交) | | `user` | `~/.claude/settings.json` | 全局个人使用 | | `project` | `.claude/settings.json` | 与团队共享 | **审查 TUI** (`tool-gates review`): 三面板仪表板 —— 项目侧边栏、命令列表和详情面板。 - **侧边栏**:列出项目及其待处理计数,自动选择当前项目。点击或使用方向键切换。 - **命令列表**:带有颜色编码段(绿色=允许,黄色=询问,红色=阻断)的完整命令。使用空格键多选以进行批量操作。 - **详情面板**:显示段细分、模式(用 左/右 循环)、作用域(用 左/右 循环)和操作按钮。 复合命令(`&&`, `||`, `|`)显示每段模式,以便您可以批准各个部分。 | 按键 | 动作 | | --- | ------ | | `Tab` | 切换面板焦点 (侧边栏 -> 命令 -> 详情) | | `Up`/`Down` 或 `j`/`k` | 在聚焦面板内导航 | | `Left`/`Right` 或 `h`/`l` | 循环模式或作用域(在详情面板中) | | `Space` | 切换命令多选 | | `Enter` | 批准选中的命令 | | `d` | 跳过(从待处理中移除) | | `D` | 拒绝(添加到 settings.json 拒绝列表) | | `q` 或 `Esc` | 退出 | ## 安装 ### 下载二进制文件 ``` # Linux x64 curl -Lo ~/.local/bin/tool-gates \ https://github.com/camjac251/tool-gates/releases/latest/download/tool-gates-linux-amd64 chmod +x ~/.local/bin/tool-gates # Linux ARM64 curl -Lo ~/.local/bin/tool-gates \ https://github.com/camjac251/tool-gates/releases/latest/download/tool-gates-linux-arm64 chmod +x ~/.local/bin/tool-gates # macOS Apple Silicon curl -Lo ~/.local/bin/tool-gates \ https://github.com/camjac251/tool-gates/releases/latest/download/tool-gates-darwin-arm64 chmod +x ~/.local/bin/tool-gates # macOS Intel curl -Lo ~/.local/bin/tool-gates \ https://github.com/camjac251/tool-gates/releases/latest/download/tool-gates-darwin-amd64 chmod +x ~/.local/bin/tool-gates ``` ### 从源码构建 ``` # 需要 Rust 1.85+ cargo build --release # Binary: ./target/x86_64-unknown-linux-musl/release/tool-gates ``` ### 配置 Claude Code 使用 `hooks` 子命令来配置 Claude Code: ``` # 安装到用户设置(推荐) tool-gates hooks add -s user # 安装到项目设置(与团队共享) tool-gates hooks add -s project # 安装到本地项目设置(不提交) tool-gates hooks add -s local # 预览更改而不写入 tool-gates hooks add -s user --dry-run # 检查安装状态 tool-gates hooks status # 输出 hooks JSON 用于手动配置 tool-gates hooks json ``` **作用域:** | 作用域 | 文件 | 用例 | |-------|------|----------| | `user` | `~/.claude/settings.json` | 个人使用(推荐) | | `project` | `.claude/settings.json` | 与团队共享 | | `local` | `.claude/settings.local.json` | 个人项目覆盖 | **三个 hook 均已安装:** - `PreToolUse` - 为主会话把关命令,跟踪“询问”决策 - `PermissionRequest` - 为子智能体把关命令(PreToolUse 的 allow 在此会被忽略) - `PostToolUse` - 检测成功执行,排队等待永久审批
手动安装 添加到 `~/.claude/settings.json`: ``` { "hooks": { "PreToolUse": [ { "matcher": "Bash|Read|Write|Edit|MultiEdit|Glob|Grep", "hooks": [ { "type": "command", "command": "~/.local/bin/tool-gates", "timeout": 10 } ] } ], "PermissionRequest": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "~/.local/bin/tool-gates", "timeout": 10 } ] } ], "PostToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "~/.local/bin/tool-gates", "timeout": 10 } ] } ] } } ```
### Claude Code 插件(可选) tool-gates 以 [Claude Code 插件](https://code.claude.com/docs/en/plugins) 形式提供,带有 `/tool-gates:review` 技能,用于交互式审批管理。插件仅提供技能 —— hook 安装由二进制文件处理(参见上方 [配置 Claude Code](#configure-claude-code))。 **前提条件:** 在使用插件之前,必须安装 `tool-gates` 二进制文件并配置好 hook。 **从市场安装:** ``` # 在 Claude Code 中,添加 marketplace /plugin marketplace add camjac251/tool-gates # 安装插件 /plugin install tool-gates@camjac251-tool-gates ``` **从本地克隆安装:** ``` # 加载插件启动 Claude Code claude --plugin-dir /path/to/tool-gates ``` **使用审查技能:** ``` # 查看所有待批准项 /tool-gates:review # 仅查看当前项目 /tool-gates:review --project ``` 该技能列出您手动批准的命令,显示计数和建议的模式,并允许您多选要永久化的内容及其作用域(local、project 或 user)。 | 步骤 | 发生什么 | 权限 | | ---------------------- | ------------------------------------------- | -------------------------- | | 列出待处理审批 | `tool-gates pending list` | 自动批准(只读) | | 显示当前规则 | `tool-gates rules list` | 自动批准(只读) | | 批准一个模式 | `tool-gates approve '' -s ` | 需要您的确认 | ## 权限网关 ### 工具网关(自身) tool-gates 识别其自身的 CLI 命令: | 允许 | 询问 | | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | `pending list`, `pending count`, `rules list`, `hooks status`, `--help`, `--version`, `--tools-status`, `--export-toml` | `approve`, `rules remove`, `pending clear`, `hooks add`, `review`, `--refresh-tools` | ### 基础命令 约 130+ 个安全的只读命令:`echo`, `cat`, `ls`, `grep`, `rg`, `awk`, `sed` (无 -i), `ps`, `whoami`, `date`, `jq`, `yq`, `bat`, `fd`, `tokei`, `hexdump` 等。针对 `xargs`(仅对已知安全目标视为安全)和 `bash -c`/`sh -c`(解析内部脚本)有自定义处理程序。 ### Beads 问题跟踪器 [Beads](https://github.com/steveyegge/beads) - Git 原生问题跟踪 | 允许 | 询问 | | ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `list`, `show`, `ready`, `blocked`, `search`, `stats`, `doctor`, `dep tree`, `prime` | `create`, `update`, `close`, `delete`, `sync`, ``, `dep add`, `comments add` | ### MCP CLI `mcp-cli` - Claude Code 的 [实验性高效 token MCP 接口](https://github.com/anthropics/claude-code/issues/12836#issuecomment-3629052941) Claude 不将完整的 MCP 工具定义加载到系统提示中,而是通过 `mcp-cli` 按需发现工具并通过 Bash 执行。使用 `ENABLE_EXPERIMENTAL_MCP_CLI=true` 启用。 | 允许 | 询问 | | --------------------------------------------------------------- | -------------------------- | | `servers`, `tools`, `info`, `grep`, `resources`, `read`, `help` | `call` (调用 MCP 工具) | 在 settings.json 中预批准受信任的服务器以避免重复提示: ``` { "permissions": { "allow": ["mcp__perplexity", "mcp__context7__*"], "deny": ["mcp__firecrawl__firecrawl_crawl"] } } ``` 模式:`mcp__`(整个服务器),`mcp____`(特定工具),`mcp____*`(通配符) ### GitHub CLI | 允许 | 询问 | 阻断 | | ----------------------------------------------------------- | ---------------------------------------------------- | ---------------------------- | | `pr list`, `issue view`, `repo view`, `search`, `api` (GET) | `pr create`, `pr merge`, `issue create`, `repo fork` | `repo delete`, `auth logout` | ### Git | 允许 | 询问 | 询问(警告) | | -------------------------------------------- | ---------------------------------------- | ------------------------------------------- | | `status`, `log`, `diff`, `show`, `branch -a` | `add`, `commit`, `push`, `pull`, `merge` | `push --force`, `reset --hard`, `clean -fd` | ### Shortcut CLI [shortcut-cli](https://github.com/shortcut-cli/shortcut-cli) - Shortcut 的社区 CLI | 允许 | 询问 | | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | | `search`, `find`, `story` (查看), `members`, `epics`, `workflows`, `projects`, `help` | `create`, `install`, `story` (带更新标志), `search --save`, `api` (POST/PUT/DELETE) | ### 云端 CLI AWS, gcloud, terraform, kubectl, docker, podman, az, helm, pulumi | 允许 | 询问 | 阻断 | | --------------------------------------------- | ------------------------------------------ | ------------------------------------------ | | `describe-*`, `list-*`, `get`, `show`, `plan` | `create`, `delete`, `apply`, `run`, `exec` | `iam delete-user`, `delete ns kube-system` | ### 网络 | 允许 | 询问 | 阻断 | | ----------------------------- | -------------------------------------- | ----------------------- | | `curl` (GET), `wget --spider` | `curl -X POST`, `wget`, `ssh`, `rsync` | `nc -e` (反向 shell) | ### 文件系统 | 允许 | 询问 | 阻断 | | --------------------- | ----------------------------------- | ---------------------- | | `tar -tf`, `unzip -l` | `rm`, `mv`, `cp`, `chmod`, `sed -i` | `rm -rf /`, `rm -rf ~` | ### 开发者工具 约 50+ 个带有写入标志检测的工具:`jq`, `shellcheck`, `hadolint`, `vite`, `vitest`, `jest`, `tsc`, `esbuild`, `turbo`, `nx` | 默认安全 | 带标志时询问 | | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | | `ast-grep`, `yq`, `semgrep`, `sad`, `prettier`, `eslint`, `biome`, `ruff`, `black`, `gofmt`, `rustfmt`, `golangci-lint` | `-U`, `-i`, `--fix`, `--write`, `--commit`, `--autofix` | | `sd` (管道模式安全,带文件参数时询问), 总是询问:`watchexec` (运行命令), `dos2unix` | | ### 包管理器 npm, pnpm, yarn, pip, uv, cargo, go, bun, conda, poetry, pipx, mise | 允许 | 询问 | | -------------------------------------- | -------------------------------------------- | | `list`, `show`, `test`, `build`, `dev` | `install`, `add`, `remove`, `publish`, `run` | ### 系统 **数据库 CLI:** psql, mysql, sqlite3, mongosh, redis-cli **构建工具:** make, cmake, ninja, just, gradle, maven, bazel **操作系统包管理器:** apt, brew, pacman, nix, dnf, zypper, flatpak, snap **其他:** sudo, systemctl, crontab, kill | 允许 | 询问 | 阻断 | | ----------------------------------------------- | --------------------------------- | ----------------------------------------------------------------- | | `psql -l`, `make test`, `sudo -l`, `apt search` | `make deploy`, `sudo apt install` | `shutdown`, `reboot`, `mkfs`, `dd`, `fdisk`, `iptables`, `passwd` | ## 安全特性 ### AST 前安全检查 注释在检查前被移除(引号感知,遵循 bash 词边界规则处理 `#`),因此注释内的模式不会触发误报。 ``` curl https://example.com | bash # ask - pipe to shell eval "rm -rf /" # ask - arbitrary execution source ~/.bashrc # ask - sourcing script echo $(rm -rf /tmp/*) # ask - dangerous substitution find . | xargs rm # ask - xargs to rm echo "data" > /etc/passwd # ask - output redirection ``` ### 复合命令处理 最严格的决策胜出: ``` git status && rm -rf / # deny (rm -rf / blocked) git status && npm install # ask (npm install needs approval) git status && git log # allow (both read-only) ``` ### 智能 sudo 处理 ``` sudo apt install vim # ask - "sudo: Installing packages (apt)" sudo systemctl restart nginx # ask - "sudo: systemctl restart" ``` ## 测试 ``` cargo test # Full suite cargo test gates::git # Specific gate cargo test -- --nocapture # With output ``` ### 手动测试 ``` # 允许 echo '{"tool_name":"Bash","tool_input":{"command":"git status"}}' | tool-gates # -> {"hookSpecificOutput":{"permissionDecision":"allow"}} # 询问 echo '{"tool_name":"Bash","tool_input":{"command":"npm install"}}' | tool-gates # -> {"hookSpecificOutput":{"permissionDecision":"ask","permissionDecisionReason":"npm: Installing packages"}} # 拒绝 echo '{"tool_name":"Bash","tool_input":{"command":"rm -rf /"}}' | tool-gates # -> {"hookSpecificOutput":{"permissionDecision":"deny"}} ``` ## 架构 ``` src/ ├── main.rs # Entry point, CLI commands ├── models.rs # Types (HookInput, HookOutput, Decision) ├── parser.rs # tree-sitter-bash AST parsing ├── router.rs # Security checks + gate routing ├── settings.rs # settings.json parsing and pattern matching ├── hints.rs # Modern CLI hints (cat→bat, grep→rg, etc.) ├── tool_cache.rs # Tool availability cache for hints ├── mise.rs # Mise task file parsing and command extraction ├── package_json.rs # package.json script parsing and command extraction ├── tracking.rs # PreToolUse→PostToolUse correlation (15min TTL) ├── pending.rs # Pending approval queue (JSONL format) ├── patterns.rs # Pattern suggestion algorithm ├── post_tool_use.rs # PostToolUse handler ├── permission_request.rs # PermissionRequest hook handler ├── settings_writer.rs # Write rules to Claude settings files ├── toml_export.rs # TOML policy export for Gemini CLI ├── config.rs # User configuration (~/.config/tool-gates/config.toml) ├── file_guards.rs # Symlink guard for AI config files ├── tool_blocks.rs # Configurable tool blocking ├── generated/ # Auto-generated by build.rs (DO NOT EDIT) │ ├── rules.rs # Rust gate functions from rules/*.toml │ └── toml_policy.rs # Gemini CLI TOML policy string ├── tui/ # Interactive review TUI (three-panel dashboard) └── gates/ # 13 specialized permission gates ├── mod.rs # Gate registry (ordered by priority) ├── helpers.rs # Common gate helper functions ├── tool_gates.rs # tool-gates CLI itself ├── basics.rs # Safe commands (~130+) ├── beads.rs # Beads issue tracker (bd) - github.com/steveyegge/beads ├── mcp.rs # MCP CLI (mcp-cli) - Model Context Protocol ├── gh.rs # GitHub CLI ├── git.rs # Git ├── shortcut.rs # Shortcut CLI (short) - github.com/shortcut-cli/shortcut-cli ├── cloud.rs # AWS, gcloud, terraform, kubectl, docker, podman, az, helm, pulumi ├── network.rs # curl, wget, ssh, rsync, netcat, HTTPie ├── filesystem.rs # rm, mv, cp, chmod, tar, zip ├── devtools.rs # sd, ast-grep, yq, semgrep, biome, prettier, eslint, ruff, black ├── package_managers.rs # npm, pnpm, yarn, pip, uv, cargo, go, bun, conda, poetry, pipx, mise └── system.rs # psql, mysql, make, sudo, systemctl, OS pkg managers, build tools ``` ## Gemini CLI 集成 Gemini CLI 的 hook 系统无法提示用户(仅允许 allow/block)。请改用策略引擎: ``` tool-gates --export-toml > ~/.gemini/policies/tool-gates.toml ``` 这将导出 700+ 条源自网关定义的策略规则: | 优先级 | 动作 | 示例 | | -------- | ---------- | ------------------------------------- | | 900+ | `deny` | `rm -rf /`, `gh repo delete` | | 200-299 | `ask_user` | `npm install`, `git push` | | 100-199 | `allow` | `git status`, `ls`, `cat` | | 1 | `ask_user` | 未知命令的默认回退 | ## 链接 - [Claude Code Hooks 文档](https://code.claude.com/docs/en/hooks) - [Claude Code MCP-CLI (实验性)](https://github.com/anthropics/claude-code/issues/12836#issuecomment-3629052941) - [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) - [Beads Issue Tracker](https://github.com/steveyegge/beads) - [Shortcut CLI](https://github.com/shortcut-cli/shortcut-cli)
标签:AI编程助手, Bash解析, Claude Code, DevSecOps, Homebrew安装, Hook钩子, odt, Python安全, Rust, Tree-sitter, 上游代理, 云安全监控, 代码安全, 可视化界面, 命令过滤, 威胁情报, 开发者工具, 抽象语法树, 文件保护, 权限控制, 沙箱隔离, 漏洞枚举, 终端安全, 网络流量审计, 自动化运维, 通知系统, 静态分析