safety-guard
affaan-m/everything-claude-code
Prevent destructive operations on production systems and autonomous agents with configurable protection modes.
What is safety-guard?
Safety Guard intercepts dangerous commands and restricts file edits to protect production systems and autonomous agents. Use it when working on critical infrastructure, running agents in full-auto mode, or when you need to limit changes to specific directories.
- Intercepts destructive commands (rm -rf, git push --force, DROP TABLE, etc.) and requires confirmation before execution
- Locks file edits to a specific directory tree while allowing reads elsewhere
- Combines careful mode and freeze mode for maximum protection in autonomous agent scenarios
- Suggests safer alternatives to dangerous operations
- Logs all blocked actions for audit trails
How to install safety-guard
npx skills add https://github.com/affaan-m/everything-claude-code --skill safety-guardHow to use safety-guard
- 1.Enable Careful Mode to intercept dangerous commands: the skill will warn and ask for confirmation when destructive patterns are detected
- 2.Enable Freeze Mode to restrict edits to a directory: run `/safety-guard freeze src/components/` to allow writes only to that tree
- 3.Enable Guard Mode for maximum protection: run `/safety-guard guard --dir src/api/ --allow-read-all` to combine both protections
- 4.Disable protection when needed: run `/safety-guard off` to unlock all restrictions
Use cases
- Protecting production systems from accidental destructive commands while working on them
- Running autonomous agents in full-auto mode with restricted write access to critical areas
- Limiting agent edits to a specific component directory (e.g., src/components/) during development
- Preventing accidental git force pushes, database drops, or npm publishes
- Securing sensitive operations like migrations or deployments
- DevOps engineers managing production systems
- Teams running autonomous agents without constant supervision
- Developers working on large codebases who want to isolate changes to specific directories
- Organizations with strict change control requirements
safety-guard FAQ
It watches for patterns like rm -rf (especially on /, ~, or project root), git push --force, git reset --hard, DROP TABLE/DATABASE, docker system prune, kubectl delete, chmod 777, sudo rm, npm publish, and any command with --no-verify.
Yes. Freeze Mode only restricts writes. With --allow-read-all flag in Guard Mode, agents can read anywhere but only write to the specified directory.
Safety Guard shows what the command does, asks for confirmation, and suggests a safer alternative before allowing execution.
All blocked actions are logged to ~/.claude/safety-guard.log for audit and review purposes.
Yes. Guard Mode is designed specifically for autonomous agents running in full-auto mode, combining careful command interception with directory-level write restrictions.
Full instructions (SKILL.md)
Source of truth, from affaan-m/everything-claude-code.
name: safety-guard description: Use this skill to prevent destructive operations when working on production systems or running agents autonomously. metadata: origin: ECC
Safety Guard — Prevent Destructive Operations
When to Use
- When working on production systems
- When agents are running autonomously (full-auto mode)
- When you want to restrict edits to a specific directory
- During sensitive operations (migrations, deploys, data changes)
How It Works
Three modes of protection:
Mode 1: Careful Mode
Intercepts destructive commands before execution and warns:
Watched patterns:
- rm -rf (especially /, ~, or project root)
- git push --force
- git reset --hard
- git checkout . (discard all changes)
- DROP TABLE / DROP DATABASE
- docker system prune
- kubectl delete
- chmod 777
- sudo rm
- npm publish (accidental publishes)
- Any command with --no-verify
When detected: shows what the command does, asks for confirmation, suggests safer alternative.
Mode 2: Freeze Mode
Locks file edits to a specific directory tree:
/safety-guard freeze src/components/
Any Write/Edit outside src/components/ is blocked with an explanation. Useful when you want an agent to focus on one area without touching unrelated code.
Mode 3: Guard Mode (Careful + Freeze combined)
Both protections active. Maximum safety for autonomous agents.
/safety-guard guard --dir src/api/ --allow-read-all
Agents can read anything but only write to src/api/. Destructive commands are blocked everywhere.
Unlock
/safety-guard off
Implementation
Uses PreToolUse hooks to intercept Bash, Write, Edit, and MultiEdit tool calls. Checks the command/path against the active rules before allowing execution.
Integration
- Enable by default for
codex -a neversessions - Pair with observability risk scoring in ECC 2.0
- Logs all blocked actions to
~/.claude/safety-guard.log
Related skills
More from affaan-m/everything-claude-code and the wider catalog.
security-review
Security checklist and patterns for authentication, input validation, secrets, and sensitive features.
golang-patterns
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable applications.
coding-standards
Baseline coding conventions for naming, readability, immutability, and quality across projects.
frontend-patterns
React and Next.js patterns for components, state management, performance, and modern frontend practices.
backend-patterns
REST/GraphQL API design, database optimization, and server-side patterns for Node.js, Express, and Next.js.
golang-testing
Go testing patterns: table-driven tests, subtests, benchmarks, fuzzing, and TDD methodology.