A community-driven registry for the Claude Code ecosystem. Not affiliated with Anthropic.
Are you the author? Sign in to claim
Protective hooks preventing code loss via branch protection, checkpointing, and safe squashing
Smart Guardrail System for Safer Claude Code Development
🔥 If this project helps you, please click the ⭐ Star in the top right corner to support us!
🇺🇸 English | 🇨🇳 中文 | 🇯🇵 日本語
Have you ever encountered these frustrating scenarios while Vibe Coding?
❌ Direct modification on main branch → One mistake, important code gets overwritten
❌ Interrupted modifications → Intermediate artifacts lost, unable to rollback to specific states
❌ Chaotic multiple modifications → Don't know which change introduced the bug
❌ Accidentally deleted important files → No timely commits, game over
❌ Manual changes overwritten → AI directly overwrites uncommitted manual changes, cannot distinguish code ownership
Guardrails based on Claude Code Hook
Triple Security Mechanism: 🛡️ Pre-write Interception Alert + 📸 Precise Snapshot Commits + 🔄 Smart Merge Archiving
✅ Protected branch interception → Automatically blocks writes to main branch, suggests creating feature branch
✅ Uncommitted changes protection → Blocks when manual changes are uncommitted, forces commit first to avoid overwriting
✅ File-level precise snapshots → Each modification only commits changed files, avoiding noise
✅ Smart backup mechanism → Automatic backup before gitignore file modifications
✅ Safe history merging → Multiple checkpoints intelligently merged into clean task commits
🛡️ Dual Security Protection
|
📸 Precise Snapshots
|
🔄 Smart Backup
|
📦 History Organization
|
.claude/settings.json| Solution | Traditional Approach | Manual Backup | 🛡️ Guardrails |
|---|---|---|---|
| Branch Protection | ❌ Rely on human memory | ❌ Remedial action after the fact | ✅ Automatic interception alerts |
| Version Tracking | ❌ Lose intermediate states | ⚠️ Manual copy-paste | ✅ Precise automatic snapshots |
| History Organization | ❌ Messy commit records | ❌ Cannot trace back | ✅ Smart merge archiving |
| Ease of Use | ⚠️ Requires experience | ❌ Cumbersome and error-prone | ✅ One-click install and use |
Git installed and initialized (configured with user.name / user.email)
Claude Code installed (version supporting Hooks and PreToolUse exit=2 blocking)
jq (for parsing Hook input JSON)
brew install jqsudo apt-get install -y jq
🌟 Recommended: One-Click InstallationSmart merge, safe and worry-free hljs language-bash hljs language-bash |
📁 Method 2: Manual CopyIntuitive and transparent, complete control hljs language-bash |
🔄 Smart merge - Don't overwrite existing configurations
💾 Automatic backup - Backup settings.json before changes
🔁 Idempotent safety - Multiple runs have no side effects
🧹 Deduplication - Avoid duplicate configuration items
# Project-level uninstall
curl -fsSL https://raw.githubusercontent.com/wangbooth/claude-code-guardrails/main/uninstall.sh | bash
# Keep script files, only remove from settings.json
curl -fsSL https://raw.githubusercontent.com/wangbooth/claude-code-guardrails/main/uninstall.sh | bash -s -- --keep-scripts
# Global uninstall
curl -fsSL https://raw.githubusercontent.com/wangbooth/claude-code-guardrails/main/uninstall.sh | bash -s -- --global
.
├─ .claude/
│ ├─ settings.json # Hook entry and matching rules (template)
│ └─ hooks/
│ ├─ guardrails/
│ │ ├─ guard-branch.sh # Pre-write branch guard (protected branch blocking)
│ │ ├─ auto-commit.sh # Per-modification precise snapshot commits
│ │ └─ squash-checkpoints.sh # Stop/Compact stage safe merging
├─ install.sh # One-click installation (merge/backup/dedup/idempotent)
├─ uninstall.sh # One-click uninstall (can keep scripts)
├─ README.md
├─ LICENSE # MIT
graph LR
A[🔄 Claude Code attempts write] --> B{🛡️ Branch check}
B -->|Protected branch| C[❌ Block and alert]
C --> D[💡 Suggest creating vibe branch]
B -->|Safe branch| E{📝 Uncommitted check}
E -->|Has uncommitted| F[❌ Force commit first]
F --> G[💾 Prompt to save manual changes]
E -->|No uncommitted| H[✅ Allow write]
H --> I[📸 Auto checkpoint]
I --> J[💾 Precisely commit changed files]
J --> K[🔚 Session ends]
K --> L[📦 Smart merge into task commit]
style B fill:#ff9999
style E fill:#ffcc99
style I fill:#99ff99
style L fill:#9999ff
Attempting to write on protected branch → Blocked and alerted, terminal suggests creating vibe branch:
⚠️ Branch 'main' is protected.
Current branch 'main' is protected.
It's recommended to create/switch to a vibe branch before making changes:
建议创建/切换到 vibe 分支再修改,例如:
git checkout -b vibe/20250811142530-claude
Detected uncommitted manual changes → Blocked and prompted to commit first:
⚠️ Detected uncommitted changes in the repository.
检测到仓库中有未提交的更改。
There are uncommitted changes that may be lost if AI overwrites them.
存在未提交的更改,如果被 AI 覆盖可能导致代码丢失。
Consider committing these changes first:
建议先提交这些更改:
git add .
git commit -m "Save work in progress"
Switch to vibe branch and continue working → Auto checkpoint after each Write/Edit/MultiEdit:
checkpoint: Write src/LoginForm.tsx - 14:25
checkpoint: Edit src/types.ts - 14:26
If modifying gitignore files, you'll receive backup reminders:
📦 Backup Notice: '.env' is a gitignored file. A backup has been saved to '.claude/backups/.env.20250811-142530' before claude code modification.
📦 备份提醒: '.env' 是 gitignore 文件,claude code 修改前已备份到 '.claude/backups/.env.20250811-142530'
End session stop / trigger compact → Automatically merge multiple checkpoints into one task commit:
task: modify LoginForm.tsx, types.ts - 2025-08-11
main|master|dev|release*, adjustable in guard-branch.sh.auto-commit.sh to chore(checkpoint): ...; Stop stage outputs vibe/fix/... types (Conventional Commits).PreToolUse, block generic Write|Edit|MultiEdit.PostToolUse or Stop (tickets, PRs, message notifications, etc.).Q: Will it overwrite my existing hooks?
A: No. The installation script uses jq to merge .claude/settings.json, only appends and deduplicates for the same matcher; and generates .bak.* backup before writing back.
Q: If I manually modified code but haven't committed yet, can Claude Code still continue working?
A: No. guard-branch.sh will detect uncommitted changes and block the operation, prompting you to commit first. This prevents AI from overwriting your manual modifications, ensuring clear and traceable code ownership.
Q: Will multiple hooks execute in order?
A: Multiple hooks matched by the same event execute in parallel; if strict ordering is needed, write multiple commands in the same script for serial execution.
Q: Does it support Windows?
A: Scripts are based on POSIX shell. Windows users are recommended to use WSL or Unix-like environments.
⚡ Triple action: Star ⭐ + Fork 🍴 + Share 📢
|
🐛 Found a Bug
|
💡 Feature Suggestion
|
🔀 Code Contribution
|
This project is licensed under the MIT License, see LICENSE file for details
⭐ If this project helps you, please click Star to support us! ⭐
🛡️ Chase the vibe, but honor the craft. 🛡️
Give Claude Code memory that evolves with your codebase via hooks and LLM-compiled knowledge
Security hooks with SSRF protection, MCP compression, and OpenTelemetry tracing
Context management with hooks for state via ledgers, MCP without context pollution
An LLM council that reviews your coding agent's every move for quality assurance
Community Package
@wangbooth on GitHub