Claude Code hook

claude-guardrails

Hardened security setup combining permission deny rules, shell hooks and prompt-injection defenses.

40 stars 6 forksHooks Source

Install

Install
npx claude-guardrails install
From source
git clone https://github.com/dwarvesf/claude-guardrails.git

From the README

claude-guardrails

Hardened security configuration for Claude Code — deny rules, hooks, and prompt injection defense out of the box.

Why This Exists

Claude Code can read your filesystem, run shell commands, and fetch URLs autonomously. A poisoned file in a cloned repo can hijack its behavior via prompt injection. A careless tool call can leak your SSH keys or .env secrets. These configs add defense-in-depth so you don't have to think about it on every session.

Full vs Lite

Quick Start

The script merges into your existing ~/.claude/settings.json (backing it up first) and is safe to run repeatedly.

Install from source (git clone)

Manual installation

If you prefer to install manually, see full/SETUP.md for step-by-step instructions. The key steps are:

1. Copy the variant's settings.json to ~/.claude/settings.json (or merge permissions.deny and hooks.PreToolUse arrays into your existing config)
2. Append the variant's CLAUDE-security-section.md to ~/.claude/CLAUDE.md
3. Copy patterns/secrets.json to ~/.claude/hooks/patterns/secrets.json (shared pattern list for the two scanners below)
4. Copy scan-secrets.sh to ~/.claude/hooks/scan-secrets/ and add the UserPromptSubmit hook entry to settings
5. Copy scan-commit.sh to ~/.claude/hooks/scan-commit/ (its PreToolUse hook entry is already in the variant's settings.json)
6. (Full only) Copy prompt-injection-defender.sh to ~/.claude/hooks/prompt-injection-defender/ and add the PostToolUse hook entry to settings

Uninstall

Uninstall from source

The uninstall uses a surgical remove approach — it reads the variant's config to identify exactly which deny rules and hooks were added, then subtracts only those entries from your ~/.claude/settings.json. Your own custom rules, hooks, and other settings are left untouched. It…
Read the full README on GitHub

How hooks work

  • Hooks are shell commands Claude Code runs at fixed points: before or after a tool call, when you submit a prompt, when Claude stops, on notifications and at session start.
  • They are set in the hooks section of ~/.claude/settings.json (or .claude/settings.json for a project), or come bundled in a plugin.
  • A hook can block a tool call, add context, or run a formatter or test. Read the scripts before you install them: they run on your machine with your permissions.
Claude Code docs

Details

Type
Hooks
Language
Shell
License
MIT
Last updated
31 October 2026
Topics
ai-safetyclaude-codedeveloper-toolsprompt-injectionsecurity

FAQ

What is claude-guardrails?

Hardened security setup combining permission deny rules, shell hooks and prompt-injection defenses. It is a hook for Claude Code, from dwarvesf/claude-guardrails on GitHub.

How do I install claude-guardrails?

Run npx claude-guardrails install, then follow the setup in the README.

Is claude-guardrails popular?

dwarvesf/claude-guardrails has 40 GitHub stars and 6 forks, and is included in 1 curated Claude Code list. It was last updated on 31 October 2026.

More hooks

Browse the most popular Claude Code mods, all hooks, or the skills and MCP server directories.