agentsclimarketplace

Add hook

Skill VytCepas/project-init/.agents/skills/add_hook

Adds a deterministic hook that fires automatically on tool events. Use when asked to enforce a rule on every commit, block a dangerous pattern, validate output, or gate any tool call.From its SKILL.md

Install
npx -y skills add VytCepas/project-init --skill add_hook

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 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.

SKILL.md

4.2 KB, as published. Nobody here has run it

Step 0 — Confirm the current schema (best-effort)

The event names and output schema below are a snapshot and can lag Claude Code releases. If a docs-lookup tool is available to you — the Context7 MCP, or WebFetch when it's permitted — confirm the event name / output field against the current reference (https://docs.claude.com/en/docs/claude-code/hooks) before relying on it. This skill's allowed-tools does not grant those tools, so skip this step cleanly whenever the tool is unavailable, unapproved, egress is disabled (--no-egress / air-gapped), or the lookup fails — fall back to the embedded reference below. Don't request extra permissions and never block on it.

Step 1 — Choose an event

Pick the event that matches when the hook should fire:

Tool execution (most common):

  • PreToolUse — before a tool runs; output block JSON to block it
  • PostToolUse — after a tool runs; cannot block, can log or validate
  • PostToolBatch — after a batch of parallel tool calls completes
  • PostToolUseFailure — after a tool fails
  • PermissionRequest — when Claude asks for permission; can auto-approve
  • PermissionDenied — when permission is denied; can request a retry

Session lifecycle:

  • SessionStart — when a session begins
  • SessionEnd — when a session closes
  • PreCompact — before context compaction (can block)
  • Stop — when Claude stops generating (end of turn)
  • StopFailure — when a turn fails

User input:

  • UserPromptSubmit — when the user submits a prompt
  • UserPromptExpansion — when a typed command expands into a prompt (can block)

Agent / task events:

  • SubagentStart / SubagentStop — subagent lifecycle
  • TaskCreated / TaskCompleted — task lifecycle (via TaskCreate / completion)

File/config events:

  • FileChanged, CwdChanged, ConfigChange

Step 2 — Write the hook script

Create .claude/hooks/<name>.sh:

#!/usr/bin/env bash
# Hook receives JSON on stdin from Claude Code.
INPUT=$(cat)

# exit 0 = allow (or no-op for non-blocking events)
# PreToolUse block: stdout JSON {"hookSpecificOutput":{"hookEventName":
#   "PreToolUse","permissionDecision":"deny","permissionDecisionReason":"..."}}
# stdout JSON with {"additionalContext":"..."} = inject context
# Always exit 0 — exit 1 means hook error, not a block

# Example: block pushes to main
CMD=$(echo "$INPUT" | python3 -c "
import json, sys
try:
    data = json.load(sys.stdin)
except Exception:
    sys.exit(0)
print((data.get('tool_input', {}) or {}).get('command', '') or '')
" 2>/dev/null || true)

[ -z "$CMD" ] && exit 0

if echo "$CMD" | grep -qE 'git push.*(main|master)'; then
  python3 -c "import json,sys; print(json.dumps({'hookSpecificOutput':{'hookEventName':'PreToolUse','permissionDecision':'deny','permissionDecisionReason':sys.argv[1]}}))" \
    "Direct push to main is not allowed. Use a branch and PR."
  exit 0
fi
exit 0

Make it executable: chmod +x .claude/hooks/<name>.sh

Step 3 — Wire it in settings.json

Add to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{"type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/<name>.sh", "timeout": 10}]
      }
    ]
  }
}

Matchers: tool name (Bash, Write, Edit), pipe-separated (Write|Edit), or * for all tools.

Alternative — Inline hook in a skill

Hooks can also live in a skill's frontmatter and fire only while the skill is active:

---
name: my-skill
hooks:
  PreToolUse:
    - matcher: "Bash"
      hooks:
        - type: command
          command: "./.claude/hooks/check.sh"
---

Step 4 — Test

Trigger the wired tool and verify the hook fires. Check $CLAUDE_PROJECT_DIR is set correctly in the command path.

Keep looking

Skills are one crate of 607,721. 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.