withzombies/hyperpowers/building-hooks
Claude Code and agent skill by withzombies/hyperpowers
- community
Checking that the SKILL.md file is still in the repository.
Use when creating Claude Code hooks - covers hook patterns, composition, testing, progressive enhancement from simple to advanced
Install
npx vskill@latest install withzombies/hyperpowers/building-hooksSKILL.md
<skill_overview> Hooks encode business rules at application level; start with observation, add automation, enforce only when patterns clear. </skill_overview>
<rigidity_level> MEDIUM FREEDOM - Follow progressive enhancement (observe → automate → enforce) strictly. Hook patterns are adaptable, but always start non-blocking and test thoroughly. </rigidity_level>
<quick_reference>
| Phase | Approach | Example | |
|---|---|---|---|
| 1. Observe | Non-blocking, report only | Log edits, display reminders | |
| 2. Automate | Background tasks, non-blocking | Auto-format, run builds | |
| 3. Enforce | Blocking only when necessary | Block dangerous ops, require fixes |
Most used events: UserPromptSubmit (before processing), Stop (after completion)
Critical: Start Phase 1, observe for a week, then Phase 2. Only add Phase 3 if absolutely necessary. </quick_reference>
<when_to_use> Use hooks for:
- Automatic quality checks (build, lint, format)
- Workflow automation (skill activation, context injection)
- Error prevention (catching issues early)
- Consistent behavior (formatting, conventions)
Never use hooks for:
- Complex business logic (use tools/scripts)
- Slow operations that block workflow (use background jobs)
- Anything requiring LLM reasoning (hooks are deterministic)
</when_to_use>
<hook_lifecycle_events>
| Event | When Fires | Use Cases | |
|---|---|---|---|
| UserPromptSubmit | Before Claude processes prompt | Validation, context injection, skill activation | |
| Stop | After Claude finishes | Build checks, formatting, quality reminders | |
| PostToolUse | After each tool execution | Logging, tracking, validation | |
| PreToolUse | Before tool execution | Permission checks, validation | |
| ToolError | When tool fails | Error handling, fallbacks | |
| SessionStart | New session begins | Environment setup, context loading | |
| SessionEnd | Session closes | Cleanup, logging | |
| Error | Unhandled error | Error recovery, notifications |
</hook_lifecycle_events>
<progressive_enhancement>
Phase 1: Observation (Non-Blocking)
Goal: Understand patterns before acting
Examples:
- Log file edits (PostToolUse)
- Display reminders (Stop, non-blocking)
- Track metrics
Duration: Observe for 1 week minimum
Phase 2: Automation (Background)
Goal: Automate tedious tasks
Examples:
- Auto-format edited files (Stop)
- Run builds after changes (Stop)
- Inject helpful context (UserPromptSubmit)
Requirement: Fast (<2 seconds), non-blocking
Phase 3: Enforcement (Blocking)
Goal: Prevent errors, enforce standards
Examples:
- Block dangerous operations (PreToolUse)
- Require fixes before continuing (Stop, blocking)
- Validate inputs (UserPromptSubmit, blocking)
Requirement: Only add when patterns clear from Phase 1-2 </progressive_enhancement>
<common_hook_patterns>
Pattern 1: Build Checker (Stop Hook)
Problem: TypeScript errors left behind
Solution:
Configuration:
Result: Zero errors left behind
Pattern 2: Auto-Formatter (Stop Hook)
Problem: Inconsistent formatting
Solution:
Result: All code consistently formatted
Pattern 3: Error Handling Reminder (Stop Hook)
Problem: Claude forgets error handling
Solution:
Result: Claude self-checks without blocking
Pattern 4: Skills Auto-Activation
See: hyperpowers:skills-auto-activation for complete implementation
Summary: Analyzes prompt keywords, injects skill activation reminder before Claude processes. </common_hook_patterns>
<hook_composition>
Naming for Order Control
Multiple hooks for same event run in alphabetical order by filename.
Use numeric prefixes:
Hook Dependencies
If Hook B depends on Hook A's output:
- Option 1: Numeric prefixes (A before B)
- Option 2: Combine into single hook
- Option 3: File-based communication
Example:
</hook_composition>
<testing_hooks>
Test in Isolation
Test with Mock Data
Test Non-Blocking Behavior
- Hook exits quickly (<2 seconds)
- Doesn't block Claude
- Provides clear output
Test Blocking Behavior
- Blocking decision correct
- Reason message helpful
- Escape hatch exists
Debugging
Enable logging:
Check execution:
Common issues:
- Timeout (>10 second default)
- Wrong working directory
- Missing environment variables
- File permissions
</testing_hooks>
<examples> <example> <scenario>Developer adds blocking hook immediately without observation</scenario>
<code>
Developer frustrated by TypeScript errors
Creates blocking Stop hook immediately:
#!/bin/bash npm run build
if [ $? -ne 0 ]; then echo "BUILD FAILED - BLOCKING" exit 1 # Blocks Claude fi </code>
<why_it_fails>
- No observation period to understand patterns
- Blocks even for minor errors
- No escape hatch if hook misbehaves
- Might block during experimentation
- Frustrates workflow when building is slow
- Haven't identified when blocking is actually needed
</why_it_fails>
<correction> Phase 1: Observe (1 week)
After 1 week, review:
- How often do errors appear?
- Are they usually fixed quickly?
- Do they cause real problems or just noise?
Phase 2: If errors are frequent, automate
Phase 3: Only if observation shows blocking is necessary
Never reached - non-blocking works fine!
What you gain:
- Understood patterns before acting
- Non-blocking keeps workflow smooth
- Helpful messages without friction
- Can experiment without frustration
</correction> </example>
<example> <scenario>Hook is slow, blocks workflow</scenario>
<code>
#!/bin/bash
Stop hook that's too slow
Run full test suite (takes 45 seconds!)
npm test
Run linter (takes 10 seconds)
npm run lint
Run build (takes 30 seconds)
npm run build
Total: 85 seconds of blocking!
</code>
<why_it_fails>
- Hook takes 85 seconds to complete
- Blocks Claude for entire duration
- User can't continue working
- Frustrating, likely to be disabled
- Defeats purpose of automation
</why_it_fails>
<correction> Make hook fast (<2 seconds):
Or run slow checks in background:
What you gain:
- Hook completes instantly
- Workflow not blocked
- Still get quality checks
- User can continue working
</correction> </example>
<example> <scenario>Hook has no error handling, fails silently</scenario>
<code>
#!/bin/bash
Hook with no error handling
file=$(tail -1 ~/.claude/edit-log.txt) prettier --write "$file" </code>
<why_it_fails>
- If edit-log.txt missing → hook fails silently
- If file path invalid → prettier errors not caught
- If prettier not installed → silent failure
- No logging, can't debug
- User has no idea hook ran or failed
</why_it_fails>
<correction> Add error handling:
What you gain:
- Errors logged and visible
- Graceful handling of missing files
- Can debug when issues occur
- Clear feedback to user
- Hook doesn't fail silently
</correction> </example> </examples>
<security> Hooks run with your credentials and have full system access.
Best Practices
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/building-hooks/SKILL.md
Popularity
- Repository stars
- 69
- Repository forks
- 12
- 7-day trend score
- 21
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/withzombies/hyperpowers/building-hooks)