From epieczko-betty
**hook.define** is a Betty skill that creates and registers validation hooks for Claude Code. Hooks enable automatic validation and policy enforcement by triggering skills on events like file edits, commits, and pushes.
npx claudepluginhub joshuarweaver/cascade-code-general-misc-1 --plugin epieczko-bettyThis skill uses the workspace's default tool permissions.
**hook.define** is a Betty skill that creates and registers validation hooks for Claude Code. Hooks enable automatic validation and policy enforcement by triggering skills on events like file edits, commits, and pushes.
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Guides building MCP servers enabling LLMs to interact with external services via tools. Covers best practices, TypeScript/Node (MCP SDK), Python (FastMCP).
Generates original PNG/PDF visual art via design philosophy manifestos for posters, graphics, and static designs on user request.
hook.define is a Betty skill that creates and registers validation hooks for Claude Code. Hooks enable automatic validation and policy enforcement by triggering skills on events like file edits, commits, and pushes.
Transform manual validation into automatic safety rails:
python skills/hook.define/hook_define.py <event> <command> [options]
| Parameter | Required | Description | Example |
|---|---|---|---|
event | Yes | Hook event trigger | on_file_edit |
command | Yes | Command to execute | api.validate {file_path} zalando |
--pattern | No | File pattern to match | *.openapi.yaml |
--blocking | No | Block on failure (default: true) | true |
--timeout | No | Timeout in ms (default: 30000) | 10000 |
--description | No | Human-readable description | Validate OpenAPI specs |
| Event | Triggers When | Use Case |
|---|---|---|
on_file_edit | File is edited in editor | Syntax validation |
on_file_save | File is saved | Code generation |
on_commit | Git commit attempted | Breaking change detection |
on_push | Git push attempted | Full validation suite |
on_tool_use | Any tool is used | Audit logging |
on_agent_start | Agent begins execution | Context injection |
on_workflow_end | Workflow completes | Cleanup/notification |
python skills/hook.define/hook_define.py \
on_file_edit \
"python betty/skills/api.validate/api_validate.py {file_path} zalando" \
--pattern="*.openapi.yaml" \
--blocking=true \
--timeout=10000 \
--description="Validate OpenAPI specs against Zalando guidelines"
Result: Every time a *.openapi.yaml file is edited, it's automatically validated against Zalando guidelines. If validation fails, the edit is blocked.
python skills/hook.define/hook_define.py \
on_commit \
"python betty/skills/api.compatibility/check_breaking_changes.py {file_path}" \
--pattern="specs/**/*.yaml" \
--blocking=true \
--description="Prevent commits with breaking API changes"
Result: Commits are blocked if they contain breaking API changes.
python skills/hook.define/hook_define.py \
on_file_save \
"python betty/skills/api.generate-models/auto_generate.py {file_path}" \
--pattern="specs/*.openapi.yaml" \
--blocking=false \
--description="Auto-regenerate models when specs change"
Result: When an OpenAPI spec is saved, models are regenerated automatically (non-blocking).
python skills/hook.define/hook_define.py \
on_tool_use \
"python betty/skills/audit.log/log_api_change.py {tool_name}" \
--blocking=false \
--description="Log all tool usage for compliance"
Result: All tool usage is logged for audit trails (non-blocking).
{
"status": "success",
"data": {
"hook_config": {
"name": "api-validate-all-openapi-yaml",
"command": "python betty/skills/api.validate/api_validate.py {file_path} zalando",
"blocking": true,
"timeout": 10000,
"when": {
"pattern": "*.openapi.yaml"
},
"description": "Validate OpenAPI specs against Zalando guidelines"
},
"hooks_file_path": "/home/user/betty/.claude/hooks.yaml",
"event": "on_file_edit",
"total_hooks": 1
}
}
The skill creates/updates .claude/hooks.yaml:
hooks:
on_file_edit:
- name: api-validate-all-openapi-yaml
command: python betty/skills/api.validate/api_validate.py {file_path} zalando
blocking: true
timeout: 10000
when:
pattern: "*.openapi.yaml"
description: Validate OpenAPI specs against Zalando guidelines
.claude/hooks.yaml if it exists.claude/hooks.yaml# workflows/setup_api_validation.yaml
steps:
- skill: hook.define
args:
- "on_file_edit"
- "api.validate {file_path} zalando"
- "--pattern=*.openapi.yaml"
- "--blocking=true"
Agents can dynamically create hooks based on project needs:
# Agent detects OpenAPI specs in project
# Automatically sets up validation hooks
| Pattern | Matches |
|---|---|
*.openapi.yaml | All OpenAPI files in current directory |
*.asyncapi.yaml | All AsyncAPI files in current directory |
specs/**/*.yaml | All YAML files in specs/ and subdirectories |
src/**/*.ts | All TypeScript files in src/ and subdirectories |
**/*.py | All Python files anywhere |
| Operation | Suggested Timeout | Reasoning |
|---|---|---|
| Syntax validation | 5,000 - 10,000 ms | Fast, local checks |
| Zally API call | 10,000 - 30,000 ms | Network latency |
| Model generation | 30,000 - 60,000 ms | Compilation time |
| Full test suite | 300,000 ms (5 min) | Comprehensive testing |
If a blocking hook fails:
❌ Hook 'validate-openapi' failed:
- Missing required field: info.x-api-id
- Property 'userId' should use snake_case
Operation blocked. Fix errors and try again.
If a hook exceeds timeout:
⚠️ Hook 'validate-openapi' timed out after 10000ms
Operation blocked for safety.
PyYAML: Required for YAML file handling
pip install pyyaml
context.schema: For validation rule definitions
.claude/hooks.yaml - Hook configurations for Claude Code0.1.0 - Initial implementation with basic hook definition support