Claude code safety hooks
Two deterministic Claude Code hooks: a PreToolUse Bash command guard and a PreToolUse research-output validator that requires approved-source citations.
npx -y skills add 0SxD/claude-code-safety-hooksAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Two deterministic Claude Code hooks: a PreToolUse Bash command guard against destructive operations, and a PreToolUse research-output validator that requires approved-source citations on Write/Edit calls.
SKILL.md
1.9 KB, 370 tokens by cl100k_base, as published. Nobody here has run it
claude-code-safety-hooks
A focused, stdlib-only hook bundle for Claude Code that enforces two structural safety rules on agent sessions.
Hooks included
destructive_command_guard.py
Fires on every Bash PreToolUse event. Checks the command string against three tiers of regex patterns: unconditional blocks (fork bombs, filesystem wipes), destructive-but-recoverable patterns (rm -rf, git reset --hard, DROP TABLE, kill -9), and file-write bypass patterns (echo/cat/tee/Python one-liners that write .py files without going through the Write tool). Returns exit 2 with a structured denial on a match; exit 0 otherwise.
validate_research.py
Fires on Write and Edit PreToolUse events. Blocks writes to .py files unless a research.md file at the project root was modified in the last hour and contains at least one citation URL from a configurable approved-domains list. Resolves the project root from the target file's location (not the shell cwd) via git, with a fallback filesystem walk. Logs approved citation URLs to .claude/research_citations.log. Returns exit 2 with an actionable denial on block; exit 0 otherwise.
Use case
Drop these two scripts into any Claude Code project and add them to PreToolUse in settings.json. They require no external dependencies and work on Python 3.10+.
Customization
- Edit
DESTRUCTIVE_PATTERNSin destructive_command_guard.py to add or relax rules for your environment. - Edit
APPROVED_DOMAINSin validate_research.py to match the authoritative sources for your stack. - Edit
GATED_EXTENSIONSto gate file types other than .py.
License
MIT. Copyright (c) 2026 0SxD.
What ships with it: 5 files
25.4 KB alongside SKILL.md, 2 of them executable
- destructive_command_guard.pyruns8.5 KB
- .gitignore233 B
- LICENSE1.1 KB
- README.md4.4 KB
- validate_research.pyruns11.2 KB