← ClaudeAtlas

hook-authoringlisted

Use when writing or modifying rnd-framework hook scripts — covers hook anatomy, exit code protocol, stdin parsing, fast-path patterns, and hooks.json registration
oleksify/rnd-framework · ★ 0 · API & Backend · score 75
Install: claude install-skill oleksify/rnd-framework
# Hook Authoring ## Overview rnd-framework hooks are bash scripts invoked by Claude Code at specific lifecycle points. Every hook follows a strict contract: it reads JSON from stdin, makes a decision, and communicates it via exit code + stdout/stderr. Breaking this contract silently breaks the pipeline. ## Hook Anatomy Every PreToolUse hook follows this skeleton: ```bash #!/usr/bin/env bash # hooks/<name>.sh — <One-line purpose>. # shellcheck source=./lib.sh source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" parse_input file_path="$(extract_file_path "$TOOL_INPUT")" # Decision logic here... exit 0 ``` Key points: - `set -euo pipefail` is inherited from `lib.sh` — never add it again - Always source `lib.sh` via `BASH_SOURCE[0]` — never use `$0` (breaks under sourcing) - Use `parse_input` for PreToolUse hooks (sets `TOOL_NAME`, `TOOL_INPUT`, `AGENT_TYPE`) - Use raw `jq` extraction for PostToolUse/event hooks (different stdin schema) ## Exit Code Contract | Exit Code | Stdout | Stderr | Meaning | |---|---|---|---| | `0` | `allow_json` output | — | Auto-allow the tool operation | | `0` | `advisory_json "msg"` output | — | Warn but allow | | `0` | nothing | — | No opinion (default permission prompt) | | `2` | — | `block_msg "reason"` | Block the operation | Any other exit code is treated as a hook failure and logged. Never use `exit 1` for blocking — that signals a script error, not a policy decision. ## Response Functions From `lib.sh`: ```bash allow_json # Pr