cc-safety-net

kenryu42MIT活跃维护

在 AI 编程代理执行工具调用前拦截破坏性 Git 命令、文件系统操作和敏感文件访问,为 Claude Code、Cursor、Codex 等十余种代理提供统一的安全防护层。

A pre-execution guard for AI coding agents. It blocks destructive Git and file system commands, plus common attempts to access sensitive files, before a tool call runs. Supports Amp Code, Antigravity CLI, Claude Code, Codex, Cursor, DeepSeek Harness, Devin CLI, GitHub Copilot CLI, Grok Build, Hermes Agent, Kimi Code, OpenClaw, OpenCode, and Pi.

v2.7.8发布于 2026-11-09 15:26 UTC1,990star +39 / 7 天93fork同步于 2026-11-10 17:47 UTC

怎么上手

由 README 提炼,执行前请确认
npx -y cc-safety-net@latest install
npx -y cc-safety-net@latest doctor
硬件要求按 README 说明

README 未说明硬件要求;需 Node.js 22 或更高版本,支持 Windows、macOS、Linux。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

在 AI 编码代理执行工具调用前拦截破坏性命令和敏感文件访问的预执行防护层

在 AI 编程代理执行工具调用前拦截破坏性 Git 命令、文件系统操作和敏感文件访问,为 Claude Code、Cursor、Codex 等十余种代理提供统一的安全防护层。

核心能力

  • 解析命令真实语义,包装或调换参数无法绕过
  • 拦截 git reset --hard、force push、rm -rf 和 curl | bash
  • 阻止 shell 与文件工具读取 SSH 密钥、.env、~/.aws 等
  • 用 npx cc-safety-net gui 在图形界面切换 Standard/Strict/Paranoid 预设
  • 支持官方 Terraform/AWS/gcloud/Azure 规则包与自定义 JSON 规则

容易踩的坑

必须保留 @latest 限定符,裸写 cc-safety-net 可能命中 npx 缓存里的旧版本;它只是预执行检查,不是沙箱,不隔离进程、不设文件权限、不监控网络出口;配置文件损坏时会回退到安全默认值而非报错停止。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.7.8
  1. v2.7.8最新正式版2026-11-09 · 2026-11-09 15:26 UTC

    Standard mode no longer blocks scp and sftp commands that pass an SSH key with -i, matching the exception already made for ssh.

    Fixed

    • Fixed standard mode blocking scp and sftp when an SSH private key is given as the -i identity file, such as scp -i ~/.ssh/deploy_key deploy@host:/srv/app/file.tar.gz .. The key authenticates the connection and is never printed, so it is no longer treated as a secret read for any built-in rule, including home-directory rules. (#336)
      • The key stays checked where it can still be exposed: as an scp or sftp source operand, when -S hands it to another program, when an option value swallows the -i (for example scp -X -i ~/.ssh/id_rsa ...), and in -F or -o values such as IdentityFile= or ProxyCommand=. Strict and paranoid modes are unchanged.
  2. v2.7.72026-11-09 · 2026-11-09 02:24 UTC
    查看更新说明

    A fix for standard mode, which blocked ssh commands that authenticate with an identity file passed through -i.

    Fixed

    • Fixed standard mode treating the identity file of ssh -i as a sensitive-file read, so a command such as ssh -i ~/.ssh/deploy_key host.example uptime is no longer blocked by a built-in rule. ssh uses the key only to authenticate and never prints it. Clustered forms like -vi and an -i placed after options that take a value are both recognized. (#334)
      • -F, -o values such as IdentityFile= or ProxyCommand=, the remote command, an -i after the destination, and configured denyPaths entries all stay checked, and strict and paranoid modes still block the identity file.
  3. v2.7.62026-11-08 · 2026-11-08 08:57 UTC
    查看更新说明

    Restores user and project policy configuration on Windows, where reading and writing policy files failed on affected Node.js versions.

    Fixed

    • Fixed user and project policy files failing to read and write on Windows with Unable to access user policy filesystem safely.. rule init, rule tool add, rule tool list, and rule verify now work, and the hook no longer degrades to a fallback configuration. The path-versus-handle file identity check still requires a matching file ID, but no longer compares the volume serial on Windows, where path and handle stats disagree on Node.js 22.12–22.17, 23.x, and 24.0–24.3. (#332)
  4. v2.7.52026-11-08 · 2026-11-08 02:53 UTC
    查看更新说明

    Shell tools that run their commands on another machine, such as a plugin tool backed by adb shell or ssh, can now be declared so their commands are analyzed instead of going unchecked.

    Added

    • Added --no-cwd-arg to cc-safety-net rule tool add, and the equivalent { "name": "phone_shell", "cwd": false } form in command_tools, for declaring a shell tool whose working directory is not on this machine. Commands from such a tool are analyzed like a built-in shell command, no working-directory argument is read, and a relative path is judged against the session directory. (#331, #330)
    • Added an error when cc-safety-net rule tool add is given both --cwd-arg and --no-cwd-arg.

    Changed

    • Changed the OpenCode and Cursor adapters to ignore the workdir and working_directory arguments for a tool declared with cwd: false, so a remote working directory that does not exist locally no longer makes the call unusable.
    • Changed the DeepSeek Harness notice about an undeclared shell tool to recommend rule tool add <name> --no-cwd-arg when the tool runs its commands on a remote host or the location cannot be determined, instead of advising against declaring it at all.
    • Changed cc-safety-net rule tool list to report Cwd argument: none for a tool declared with cwd: false.
    • Changed the published JSON Schema (assets/cc-safety-net.schema.json) to accept false for a command_tools entry's cwd, and the rule.json validation message for an invalid cwd now states that false is allowed.
  5. v2.7.42026-11-06 · 2026-11-06 06:54 UTC
    查看更新说明

    This release teaches the PowerShell parser about here-strings (@'…'@ and @"…"@), which fixes both a false positive on quoted source text and several destructive commands that slipped through unchecked.

    Fixed

    • Fixed a false positive where the body of a PowerShell here-string was analyzed as code, so piping source text such as s = 'var x = originalArmy.Key;' through @'…'@ | python - was blocked as sensitive-path access. This applies when the command is analyzed as PowerShell — the powershell route or a powershell -Command wrapper; the auto route still denies the bare form. (#327)
    • Fixed missed detections after a here-string whose body contains an apostrophe. Commands like @'…don't…'@; Remove-Item -Recurse -Force C:\ and @'…don't…'@; Get-Content id.key were allowed and are now blocked.
    • Fixed detection of destructive commands handed to Invoke-Expression as a here-string.
    • Improved here-string handling for carriage-return line endings and for expandable @"…"@ bodies, so a path such as $env:USERPROFILE\.ssh\config written in a here-string is resolved and blocked.
    • Fixed a PowerShell double-quoted string ending in a backslash, such as Get-Content "C:\tmp\" ; Get-Content id.key, leaving the rest of the command unchecked by the secret guard.
    • Allowed a here-string that only mentions a destructive command in its text, such as a Makefile body containing rm -rf piped to Set-Content.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    CI codecov Version macOS Windows Linux License: MIT

    English · 简体中文 · 日本語

    https://github.com/user-attachments/assets/353c1441-9156-483c-b8e5-32fce7905a83

    CC Safety Net (Coding CLI Safety Net) blocks destructive commands and access to secrets such as SSH keys and .env files before the tool call runs. It parses what the command does. Wrapping the command or reordering flags does not hide it. A broken config file falls back to safe defaults instead of stopping your agent. It is not a sandbox: it does not contain processes, set filesystem permissions, or watch network egress.

    [!NOTE] Full documentation → covers installation, configuration, reference material, guides, and the security model. This README is the short version.

    Sponsors

    How it works

    Supported coding CLIs

    CC Safety Net supports these coding agent CLIs on Windows, macOS, and Linux.

    Features

    • Blocks destructive commands such as git reset --hard, git push --force, and rm -rf on dangerous targets, and install scripts piped from the internet (curl … | bash), even inside bash -c or python -c. See Blocked commands.
    • Blocks secret access to SSH keys, .env files, ~/.aws, and coding-CLI credentials, from the shell and from the agent's file tools. See Secret protection.
    • Tunes the policy in a GUI. Run npx cc-safety-net gui to pick the Standard, Strict, or Paranoid preset and turn rules on or off. See Dashboard.
    • Adds blocks through rulebooks: official packs for Terraform, AWS, gcloud, and Azure, or your own JSON. See Official rulebooks.
    • Shares policy through git. Commit .cc-safety-net/ so clones and cloud sessions get the same rules. See Team setup.
    • Embeds in your own tools. Call checkCommand from Node.js without installing the hook. See Library API.

    Quick start

    You need Node.js 22 or higher. Install into the coding CLIs on this machine, then check that protection is working:

    npx -y cc-safety-net@latest install
    npx -y cc-safety-net@latest doctor
    

    Update with npx -y cc-safety-net@latest update and uninstall with npx -y cc-safety-net uninstall. Keep the @latest qualifier: a bare cc-safety-net spec can run an older copy from the npx cache. Per-CLI requirements are in Installation.

    Development

    See CONTRIBUTING.md to report a bug or request a feature.

    License

    MIT