Skip to main content
Back

CC Safety Net Stops AI Coding Agents From Silently Wiping Your Work

A PreToolUse hook that parses command intent before letting your AI agent run it, blocking rm -rf, git reset --hard, and secret file reads across 12 coding CLIs.

Repo, Full Access
  • CC Safety Net is a PreToolUse hook blocking destructive commands before AI coding agents execute them (GitHub).
  • Uses semantic command parsing, so flag reordering and shell wrappers cannot bypass rules like simple prefix denies do.
  • Blocks rm -rf on protected paths, git reset --hard, git push --force, and unsafe find -delete patterns.
  • Protects secrets by blocking reads of SSH keys, .env files, AWS, Kubernetes, Docker, and gcloud configs.
  • Supports 12 coding CLIs including Claude Code, Codex, Cursor, Copilot CLI, and Gemini CLI (docs).
  • Install with npx -y cc-safety-net@latest install; MIT licensed, requires Node 18+.

AI coding agents are getting better at writing code and, unfortunately, better at deleting it too. A single rm -rf ~/ or a stray git checkout -- can wipe hours of work while the agent keeps chatting like nothing happened. CC Safety Net is an open source guardrail that sits between your agent and the shell, and it now has roughly 1.5k stars on GitHub.

The tool is a PreToolUse hook that blocks destructive commands and access to secrets like SSH keys and .env files before AI coding agents run them. It parses command semantics, so flag reordering, shell wrappers, and interpreter one-liners can't bypass it. The authors built it after an agent silently wiped hours of progress with a single rm -rf ~/, which convinced them that soft rules in a CLAUDE.md or AGENTS.md file cannot replace hard technical constraints.

Why prefix-matched deny lists fall short

Most coding CLIs already ship with some form of deny list, but they operate on raw string prefixes. Claude Code's .claude/settings.json supports deny rules for Bash commands using simple prefix matching rather than pattern matching or semantic analysis. A rule like Bash(git checkout) blocks both git checkout -b new-branch (safe) and git checkout -- file (dangerous), and Bash(rm -rf) blocks rm -rf /tmp/cache while allowing rm -r -f / because of the different flag order.

CC Safety Net does semantic command analysis instead. It parses arguments, understands flag combinations, recursively analyzes shell wrappers, and distinguishes safe operations such as writes to temp directories or paths within cwd from dangerous ones. So