Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

Hook Policy Engine

БесплатноБез исполняемых скриптовНе проверен

Hook policy engine with 8 installable packs for safety, verification, context recovery, and teammate quality gates

TheLobbiот TheLobbi★ 22 звезды на GitHub

Об этом скилле

Hook Policy Engine

Installable hook policy packs for Claude Code. Each pack is a hardened bash script registered in .claude/settings.json. Install individually or all at once via /cc-hooks install.


1. Hook Events Reference

Event When it fires stdin payload stdout expected
PreToolUse Before a tool call executes {tool_name, tool_input} {"decision":"approve"} or {"decision":"block","reason":"..."}
PostToolUse After a tool call completes {tool_name, tool_input, tool_response} {"decision":"approve"} or {"decision":"block","reason":"..."}
PostToolUseFailure After a tool call errors {tool_name, tool_input, error} {"decision":"approve"} (errors are logged)
Notification Claude sends a message {message} {"decision":"approve"}
Stop Claude is about to stop (end of turn) {stop_reason} {"decision":"approve"} or {"decision":"block","reason":"..."}
UserPromptSubmit User submits a prompt {prompt} {"decision":"approve"} or {"decision":"block","reason":"..."}
SessionStart New session begins {session_id} {"decision":"approve"}

stdin format for PreToolUse/PostToolUse:

{
  "tool_name": "Write",
  "tool_input": {
    "file_path": "/path/to/file",
    "content": "..."
  },
  "tool_response": "..."
}

All hooks must exit 0. Non-zero exit codes cause the harness to log an error and default to approve.


2. If-Based Filtering (matcher field)

The matcher field in settings.json is a regex matched against tool_name. A hook only fires when the regex matches the tool being called.

Registration structure

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          { "type": "command", "command": "bash .claude/hooks/protect-sensitive-files.sh" }
        ]
      }
    ]
  }
}

Common matcher patterns

Matcher Fires on
"Write|Edit" Write or Edit tool calls only
"Task" Task tool calls only (create, update, etc.)
"Compact" Compaction events only
"Bash" Bash tool calls only
"Write|Edit|Bash" Write, Edit, or Bash
"" All tool calls (no filter)
"^(?!Bash)" Everything except Bash

Multiple hooks under the same event+matcher execute in order. If any returns {"decision":"block"}, the operation is blocked. All hooks receive the same stdin JSON.


3. The 8 Packs

Pack 1: protect-sensitive-files

Event: PreToolUse
Matcher: "Write|Edit"
Purpose: Blocks writes to sensitive files before they happen.

settings.json registration:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [{ "type": "command", "command": "bash .claude/hooks/protect-sensitive-files.sh" }]
      }
    ]
  }
}

Script: .claude/hooks/protect-sensitive-files.sh

#!/usr/bin/env bash
set -euo pipefail

INPUT=$(cat)
FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE" ]; then
  echo '{"decision":"approve"}'
  exit 0
fi

# Resolve to absolute path for reliable matching
RESOLVED=$(realpath -m "$FILE" 2>/dev/null || echo "$FILE")

BLOCKED_PATTERNS=(
  ".env"
  "*.key"
  "*.pem"
  "*.p12"
  "*.pfx"
  "*.crt"
  "*.cer"
  "secrets/"
  "credentials"
  ".aws/credentials"
  ".ssh/id_rsa"
  ".ssh/id_ed25519"
  ".npmrc"
  ".pypirc"
)

for pattern in "${BLOCKED_PATTERNS[@]}"; do
  # Match against both resolved path and basename
  BASENAME=$(basename "$RESOLVED")
  case "$RESOLVED" in
    *"$pattern"*) ;;
    *) case "$BASENAME" in *"$pattern"*) ;; *) continue ;; esac ;;
  esac
  jq -n --arg f "$FILE" \
    '{"decision":"block","reason":("Blocked write to sensitive file: "+$f+" — store secrets in environment variables or a secrets manager, never in source files")}'
  exit 0
done

echo '{"decision":"approve"}'

Example behavior:

  • Write to .env → blocked with reason
  • Edit to config/app.ts → approved
  • Write to secrets/api-key.txt → blocked

Pack 2: auto-format-after-edit

Event: PostToolUse
Matcher: "Write|Edit"
Purpose: Runs the appropriate formatter after every file write, keeping code style consistent without manual intervention.

settings.json registration:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [{ "type": "command", "command": "bash .claude/hooks/auto-format-after-edit.sh" }]
      }
    ]
  }
}

Script: .claude/hooks/auto-format-after-edit.sh

#!/usr/bin/env bash
set -euo pipefail

INPUT=$(cat)
FILE=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE" ] || [ ! -f "$FILE" ]; then
  echo '{"decision":"approve"}'
  exit 0
fi

# Security: reject path traversal outside project root
PROJECT_ROOT=$(
Полный SKILL.md на GitHub

Установить Hook Policy Engine в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Write
Edit
Bash
Glob
Grep

FAQ

Что делает скилл Hook Policy Engine?

Hook policy engine with 8 installable packs for safety, verification, context recovery, and teammate quality gates

Как установить скилл Hook Policy Engine?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл Hook Policy Engine запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить Hook Policy Engine с