agentsclimarketplace

Claude code safety hooks

Skill 0SxD/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.

Install
npx -y skills add 0SxD/claude-code-safety-hooks

Assembled 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_PATTERNS in destructive_command_guard.py to add or relax rules for your environment.
  • Edit APPROVED_DOMAINS in validate_research.py to match the authoritative sources for your stack.
  • Edit GATED_EXTENSIONS to 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

Keep looking

Skills are one crate of 326,984. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.