ClaudeCodeMod

All shelves / Marketplaces

steeef/claude-hooks

steeef/claude-hooks · 0 stars · 9 plugins

Marketplace Safety and automation hooks for Claude Code

Install

In Claude Code
/plugin marketplace add steeef/claude-hooks

Run inside Claude Code, then install plugins from it. Check the repo's README before you run it.

Open the repo

Plugins 9

After adding the marketplace, install one with /plugin install <name>@claude-hooks.

  1. 1command-safetyBlocks dangerous commands (rm, kubectl delete, terraform destroy)/plugin install command-safety@claude-hooksv1.1.0security
  2. 2git-hooksEnforces safe git workflows (no commits to main, branch naming)/plugin install git-hooks@claude-hooksv1.2.2development
  3. 3file-protectionWarns on large files and large reads/plugin install file-protection@claude-hooksv1.7.3security
  4. 4notificationsDesktop notifications on macOS/plugin install notifications@claude-hooksv1.0.2productivity
  5. 5env-protectionBlocks access to .env files, preventing accidental secret exposure/plugin install env-protection@claude-hooksv1.0.1security
  6. 6git-worktree-hooksBare-container worktrees under ~/wt (clone-on-demand, env-file copy)/plugin install git-worktree-hooks@claude-hooksv1.7.2development
  7. 7gh-formattingRejoins hard-wrapped PR body prose before gh submits it/plugin install gh-formatting@claude-hooksv1.1.0productivity
  8. 8gh-workflowRequires --draft on gh pr create, asks for confirmation on gh pr ready/plugin install gh-workflow@claude-hooksv1.0.0development
  9. 9comment-styleBlocks multi-line or >7-word comments in new/edited code/plugin install comment-style@claude-hooksv1.0.0quality

Files

README.md

claude-hooks

CI

Safety and automation hooks for Claude Code.

Plugins

Plugin Type Purpose
command-safety PreToolUse Blocks dangerous commands (rm, kubectl delete, terraform destroy)
git-hooks PreToolUse/PostToolUse Enforces git safety (no commits to main, blocks dangerous checkout/add patterns)
file-protection PreToolUse Worktree edit guard, blocks edits to CLAUDE.md, warns on very large files
env-protection PreToolUse Blocks access to .env files, prevents accidental secret exposure
notifications Stop/Notification Desktop notifications on macOS
git-worktree-hooks Various Bare-container worktrees under ~/wt (clone-on-demand, env-file copy)
gh-formatting PreToolUse Rejoins hard-wrapped PR body prose before gh submits it
gh-workflow PreToolUse Requires --draft on gh pr create, asks for confirmation on gh pr ready
comment-style PreToolUse Blocks multi-line or >7-word comments in new/edited code

Installation

Via Claude Code Plugin System (Recommended)
  1. Add this repository as a marketplace source:
/plugin marketplace add steeef/claude-hooks
  1. Install the plugins you want:
/plugin install command-safety@steeef/claude-hooks
/plugin install git-hooks@steeef/claude-hooks
/plugin install file-protection@steeef/claude-hooks
/plugin install notifications@steeef/claude-hooks
Manual Installation
Click to expand manual installation instructions
  1. Clone the repository:
git clone https://github.com/steeef/claude-hooks.git
cd claude-hooks
  1. Set the CLAUDE_HOOKS_DIR environment variable (add to your shell rc file):
export CLAUDE_HOOKS_DIR="$HOME/code/claude-hooks"
  1. Configure hooks in ~/.claude/settings.json:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_HOOKS_DIR/plugins/command-safety/hooks/command_hook.py"
          },
          {
            "type": "command",
            "command": "$CLAUDE_HOOKS_DIR/plugins/git-hooks/hooks/git_pre_hook.py"
          }
        ]
      },
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_HOOKS_DIR/plugins/file-protection/hooks/file_hook.py"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_HOOKS_DIR/plugins/git-hooks/hooks/cleanup_hook.py"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_HOOKS_DIR/plugins/notifications/hooks/notification_hook.sh"
          }
        ]
      }
    ],
    "Notification": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_HOOKS_DIR/plugins/notifications/hooks/notification_hook.sh"
          }
        ]
      }
    ]
  }
}

Plugin Details

command-safety

Blocks potentially destructive commands:

  • rm on git-tracked files (allows removal of ignored files like build artifacts)
  • kubectl delete, kubectl scale --replicas=0, kubectl cordon, kubectl drain
  • terraform destroy
Customizing the rm guidance

When rm is blocked, the "what to do instead" guidance comes from a pluggable handler script, not hardcoded text. By default that's the bundled plugins/command-safety/hooks/rm_handlers/trash_handler.sh, which reproduces this plugin's original behavior (move to TRASH/, log to TRASH-FILES.md).

To use a different tool instead, set CLAUDE_HOOKS_RM_HANDLER to the path of your own executable:

export CLAUDE_HOOKS_RM_HANDLER="$HOME/.claude/hooks/my_rm_handler.sh"

Handler contract:

  • Invoked as <handler> <target1> <target2> ... — the blocked target paths as argv (may be empty).
  • Must print guidance text to stdout and exit 0.
  • That output becomes the "how to fix it" portion of the block message shown to Claude — describe your own tool's usage, recovery, and listing commands however you like.

If the configured handler is missing, non-executable, errors, times out (5s), or prints nothing, the hook falls back to the bundled default handler, then to a generic notice if even that fails — so a broken handler config never silently shows guidance for a tool you're not using.

git-hooks

Enforces safe git workflows:

  • Blocks commits to main/master - forces feature branch workflow (configurable allowlist)
  • Blocks dangerous checkout - prevents git checkout main -- file overwrites
  • Blocks dangerous add patterns - prevents git add -A, --force flags
  • Suggests worktrees - recommends git worktrees for feature branches
  • Cleanup hook - clears branch tracking state after commands
file-protection

Protects important files and encourages worktree workflow:

  • Worktree edit guard - deny-then-ask speed bump for edits outside a git worktree (tied to session_id, not a timer)
  • Blocks CLAUDE.md edits - project instructions should be edited manually
  • Large file warning - warns before editing files over 10,000 lines (speed bump pattern with flag file)
env-protection

Prevents accidental exposure of secrets in .env files:

  • Blocks .env reads - both Bash commands (cat .env, grep .env) and Read tool
  • Allows safe operations - ls, mv, cp, touch on .env files
  • Allows templates - .env.example, .env.template, .env.sample
  • Safe CLI - env-safe script for inspecting variable names without values
notifications

Desktop notifications on macOS using osascript:

  • Triggers on Stop events (task completion)
  • Triggers on Notification events
gh-formatting

Rejoins hard-wrapped PR body prose before gh submits it:

  • Fires on gh pr {create,edit} and gh api .../pulls/... calls that carry --body-file <path> or -F body=@<path>
  • Rewrites the referenced file in place, joining hard-wrapped paragraphs into one line each
  • Leaves fenced code, lists, blockquotes, headers, tables, and thematic breaks untouched
  • Never blocks; inline --body "..." invocations (no file to rewrite) are left alone
gh-workflow

Enforces a draft-first PR workflow:

  • gh pr create is denied unless the exact token --draft or -d is present; -h/--help and --dry-run are always allowed
  • gh pr ready always asks for confirmation, since it transitions a PR out of draft; --undo and -h/--help are allowed without asking
comment-style

Denies Write/Edit/MultiEdit when the new/changed text adds a comment that spans more than one line, or exceeds 7 words -- line-comment languages only (#, //, --, ;). Shebangs, tool-directive pragmas (noqa, type:, eslint-disable, etc), and license/copyright headers are exempt.

Development

Requirements: Python 3.11+

# Install dependencies
uv sync

# Run tests
uv run pytest -v

# Run pre-commit hooks
uvx --with pre-commit-uv pre-commit run --all-files

Acknowledgments

Based on pchalasani/claude-code-tools.

License

MIT License - see LICENSE for details.

Facts

Kind
Marketplace
Repo
steeef/claude-hooks
Group
Uncategorized
Stars
0
Marketplace name
claude-hooks
Owner
Stephen Price
License
MIT
Language
Python
Created
2026-01-08
Last push
2026-10-02
Plugins
9

Next on this shelf

  1. 2520StevieClear/claude-mem-privacy-forkStevieClear/claude-mem-privacy-fork0
  2. 2521stickystyle/regentstickystyle/regent0
  3. 2522StyleList94/claude-pluginsStyleList94/agent-plugins0
  4. 2523sultano/claude-code-marketplacesultano/claude-code-marketplace0
  5. 2524Sunalamye/WebViewBridgeSunalamye/WebViewBridge0
  6. 2525surfertas/claude-react-rtksurfertas/claude-react-rtk0