creating-claude-hooks
Skill1.1k starsChanged 51 days agoApache-2.0View on GitHub
Use when creating or publishing Claude Code hooks - covers executable format, event types, JSON I/O, exit codes, security requirements, and PRPM package structure
- Reads credentials
2 other projects use a version of this, 2 of them edited.
Adopted by
Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data
Most recently taken up by
- nek1987/auto-agent-harnessedited, first seen Oct 11, 2026
- pr-pm/prpmedited, first seen Feb 24, 2026
Who's talking about AgentWorkforce/relay
- AgentWorkforce/relaycast“fix(sdk): preserve rich blocks in realtime message events”GitHub · Nov 8, 2026 · 2 reactions
- AgentWorkforce/agentrelay.com“Add QR card redirect for AI Engineer World Fair event”GitHub · Jul 2, 2026 · 2 reactions
- A Hacker News story“Show HN: Simple SDK for agent-to-agent communication”Hacker News · Apr 28, 2026 · 2 points
- JoeElder21/Joeyyy“deps(relay): bump agent-relay from 11.2.0 to 11.11.0 in /connectors/relay in the relay group across 1 …”GitHub · Aug 10, 2026 · 1 reactions
- AgentWorkforce/relayfile“feat: add relayfile control-plane client”GitHub · Jun 29, 2026 · 1 reactions
The biggest 5 of 21 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 21
Talked about on GitHub and Hacker News (21 times).
On GitHub · 20
- Nov 8, 2026fix(sdk): preserve rich blocks in realtime message events — AgentWorkforce/relaycast2 reactions · 3 comments
- Jul 2, 2026Add QR card redirect for AI Engineer World Fair event — AgentWorkforce/agentrelay.com2 reactions · 2 comments
- Aug 10, 2026deps(relay): bump agent-relay from 11.2.0 to 11.11.0 in /connectors/relay in the relay group across 1 directory — JoeElder21/Joeyyy1 reaction
- Jun 29, 2026feat: add relayfile control-plane client — AgentWorkforce/relayfile1 reaction · 4 comments
- Nov 3, 2026Ledger: task outcomes and expected evidence, not only done — solutionscay/skiff0 reactions
15 more on GitHub
- Nov 3, 2026Ledger: delivery records and receipts for sends and hand-offs — solutionscay/skiff0 reactions
- Oct 27, 2026Talk: Agent Led Development — milstan/sisw0 reactions · 1 comment
- Sep 28, 2026[Candidate] agentworkforce/relay/plugins/codex-relay-skill - agent-relay — ProSkillsMD/proskills0 reactions · 2 comments
- Sep 28, 2026[Candidate] agentworkforce/relay/.openskills/writing-relayflows - writing-relayflows — ProSkillsMD/proskills0 reactions · 1 comment
- Sep 27, 2026[Candidate] agentworkforce/relay/.agents/skills/review-fix-signoff-loop - review-fix-signoff-loop — ProSkillsMD/proskills0 reactions · 2 comments
- Sep 27, 2026[Candidate] agentworkforce/relay/.agents/skills/review-animations - review-animations — ProSkillsMD/proskills0 reactions · 2 comments
- Sep 27, 2026[Candidate] agentworkforce/relay/.agents/skills/relay-80-100-workflow - relay-80-100-workflow — ProSkillsMD/proskills0 reactions · 1 comment
- Sep 26, 2026[Candidate] agentworkforce/relay/.agents/skills/emil-design-eng - emil-design-eng — ProSkillsMD/proskills0 reactions · 2 comments
- Sep 26, 2026[Candidate] agentworkforce/relay/.agents/skills/creating-agent-skills-skill - creating-agent-skills — ProSkillsMD/proskills0 reactions · 2 comments
- Sep 26, 2026[Candidate] agentworkforce/relay/.agents/skills/choosing-swarm-patterns - choosing-swarm-patterns — ProSkillsMD/proskills0 reactions · 1 comment
- Sep 14, 2026Relay agent transport returns spawn metadata before task completion — AgentWorkforce/flows0 reactions
- Sep 11, 2026mount daemon can miss notify-flush SIGUSR1 acknowledgement in clean RelayFlow sandbox — AgentWorkforce/relayfile0 reactions
- Sep 10, 2026mount --once can exhaust its timeout on a 429 WebSocket dial before cursor resolution — AgentWorkforce/relayfile0 reactions
- Sep 6, 2026Rust SDK erases repeated 5xx registration diagnostics as Max retries exceeded — AgentWorkforce/relaycast0 reactions · 2 comments
- Aug 15, 2026factory dispatch exits 0 on hard failure — refusals are indistinguishable from success — AgentWorkforce/software-garden0 reactions
On Hacker News · 1
- Apr 28, 2026Show HN: Simple SDK for agent-to-agent communication2 points
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 2
- pr-pm/prpm★ 12449% same
- nek1987/auto-agent-harness★ 4100% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository27 other files it gives its agents.
- AGENTS.mdAGENTS.md
- choosing-swarm-patternsSkill
- creating-agent-skillsSkill
- emil-design-engSkill
- orchestrating-agent-relaySkill
- relay-80-100-workflowSkill
- review-animationsSkill
- review-fix-signoff-loopSkill
- setting-up-relayfileSkill
- using-agent-relaySkill
- writing-relayflowsSkill
- browser-testing-with-screenshotsSkill
- choosing-swarm-patternsSkill
- creating-claude-agentsSkill
- creating-claude-rulesSkill
- creating-skillsSkill
- debugging-websocket-issuesSkill
- deploying-to-staging-environmentSkill
- frontend-designSkill
- github-oauth-nango-integrationSkill
- implementing-command-palettesSkill
- orchestrating-agent-relaySkill
- prpm-json-best-practicesSkill
- relay-80-100-workflowSkill
- review-fix-signoff-loopSkill
- setting-up-relayfileSkill
- using-agent-relaySkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Use this skill when creating, improving, or publishing Claude Code hooks.
- Very specific: line 124
Use stderr (>&2) for errors
- Distinctive: line 211
Run heavy operations in background
- Distinctive: line 212
Use specific matchers, not wildcards
- Distinctive: line 233
Always start with shebang:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Creating Claude Code Hooks
Use this skill when creating, improving, or publishing Claude Code hooks. Provides essential guidance on hook format, event handling, I/O conventions, and package structure.
When to Use This Skill
Activate this skill when:
- User asks to create a new Claude Code hook
- User wants to publish a hook as a PRPM package
- User needs to understand hook format or events
- User is troubleshooting hook execution
- User asks about hook vs skill vs command differences
Quick Reference
Hook File Format
| Aspect | Requirement |
| Location | .claude/hooks/<event-name> |
| Format | Executable file (shell, TypeScript, Python, etc.) |
| Permissions | Must be executable (chmod +x) |
| Shebang | Required (#!/bin/bash or #!/usr/bin/env node) |
| Input | JSON via stdin |
| Output | Text via stdout (shown to user) |
| Exit Codes | 0 = success, 2 = block, other = error |
Available Events
| Event | When It Fires | Common Use Cases |
session-start | New session begins | Environment setup, logging, checks |
user-prompt-submit | Before user input processes | Validation, enhancement, filtering |
tool-call | Before tool execution | Permission checks, logging, modification |
assistant-response | After assistant responds | Formatting, logging, cleanup |
Hook Format Requirements
File Location
Project hooks:
.claude/hooks/session-start
.claude/hooks/user-prompt-submitUser-global hooks:
~/.claude/hooks/session-start
~/.claude/hooks/tool-callExecutable Requirements
Every hook MUST:
- Have a shebang line:
#!/bin/bash
# or
#!/usr/bin/env node
# or
#!/usr/bin/env python3- Be executable:
chmod +x .claude/hooks/session-start- Handle JSON input from stdin:
#!/bin/bash
INPUT=$(cat)
FILE=$(echo "$INPUT" | jq -r '.input.file_path // empty')- Exit with appropriate code:
exit 0 # Success
exit 2 # Block operation
exit 1 # Error (logs but continues)Input/Output Format
JSON Input Structure
Hooks receive JSON via stdin with event-specific data:
{
"event": "tool-call",
"timestamp": "2025-01-15T10:30:00Z",
"session_id": "abc123",
"current_dir": "/path/to/project",
"input": {
"file_path": "/path/to/file.ts",
"command": "npm test",
"old_string": "...",
"new_string": "..."
}
}Stdout Output
- Normal output shows in transcript
- Empty output runs silently
- Use stderr (
>&2) for errors
Exit Codes
| Code | Meaning | Behavior |
0 | Success | Continue normally |
2 | Block | Stop operation, show error |
1 or other | Error | Log error, continue |
Schema Validation
Hooks should validate against the JSON schema:
Schema URL: https://github.com/pr-pm/prpm/blob/main/packages/converters/schemas/claude-hook.schema.json
Required frontmatter fields:
name- Hook identifier (lowercase, hyphens only)description- What the hook doesevent- Event type (optional, inferred from filename)language- bash, typescript, javascript, python, binary (optional)hookType: "hook"- For round-trip conversion
Common Mistakes
| Mistake | Problem | Solution |
| Not quoting variables | Breaks on spaces | Always use "$VAR" |
| Missing shebang | Won't execute | Add #!/bin/bash |
| Not executable | Permission denied | Run chmod +x hook-file |
| Logging to stdout | Clutters transcript | Use stderr: echo "log" >&2 |
| Wrong exit code | Doesn't block when needed | Use exit 2 to block |
| No input validation | Security risk | Always validate JSON fields |
| Slow operations | Blocks Claude | Run in background or use PostToolUse |
| Absolute paths missing | Can't find scripts | Use $CLAUDE_PLUGIN_ROOT |
Basic Hook Examples
Shell Script Hook
#!/bin/bash
# .claude/hooks/session-start
# Log session start
echo "Session started at $(date)" >> ~/.claude/session.log
# Check environment
if ! command -v node &> /dev/null; then
echo "Warning: Node.js not installed" >&2
fi
# Output to user
echo "Development environment ready"
exit 0TypeScript Hook
#!/usr/bin/env node
// .claude/hooks/user-prompt-submit
import { readFileSync } from 'fs';
// Read JSON from stdin
const input = readFileSync(0, 'utf-8');
const data = JSON.parse(input);
// Validate prompt
if (data.prompt.includes('API_KEY')) {
console.error('Warning: Prompt may contain secrets');
process.exit(2); // Block
}
console.log('Prompt validated');
process.exit(0);Best Practices
1. Keep Hooks Fast
Target < 100ms for PreToolUse hooks:
- Cache results where possible
- Run heavy operations in background
- Use specific matchers, not wildcards
2. Handle Errors Gracefully
# Check dependencies exist
if ! command -v jq &> /dev/null; then
echo "jq not installed, skipping" >&2
exit 0
fi
# Validate input
FILE=$(echo "$INPUT" | jq -r '.input.file_path // empty')
if [[ -z "$FILE" ]]; then
echo "No file path provided" >&2
exit 1
fi3. Use Shebangs
Always start with shebang:
#!/bin/bash
#!/usr/bin/env node
#!/usr/bin/env python34. Secure Sensitive Files
BLOCKED=(".env" ".env.*" "*.pem" "*.key")
for pattern in "${BLOCKED[@]}"; do
case "$FILE" in
$pattern)
echo "Blocked: $FILE is sensitive" >&2
exit 2
;;
esac
done5. Quote All Variables
# WRONG - breaks on spaces
prettier --write $FILE
# RIGHT - handles spaces
prettier --write "$FILE"6. Log for Debugging
LOG_FILE=~/.claude-hooks/debug.log
# Log to file
echo "[$(date)] Processing $FILE" >> "$LOG_FILE"
# Log to stderr (shows in transcript)
echo "Hook running..." >&2Publishing as PRPM Package
Package Structure
my-hook/
├── prpm.json # Package manifest
├── HOOK.md # Hook documentation
└── hook-script.sh # Hook executableprpm.json
{
"name": "@username/hook-name",
"version": "1.0.0",
"description": "Brief description shown in search",
"author": "Your Name",
"format": "claude",
"subtype": "hook",
"tags": ["automation", "security", "formatting"],
"main": "HOOK.md"
}HOOK.md Format
---
name: session-logger
description: Logs session start/end times for tracking
event: SessionStart
language: bash
hookType: hook
---
# Session Logger Hook
Logs Claude Code session activity for tracking and debugging.
## Installation
This hook will be installed to `.claude/hooks/session-start`.
## Behavior
- Logs session start time to `~/.claude/session.log`
- Displays environment status
- Runs silent dependency checks
## Requirements
- bash 4.0+
- write access to `~/.claude/`
## Source Code
\`\`\`bash
#!/bin/bash
echo "Session started at $(date)" >> ~/.claude/session.log
echo "Environment ready"
exit 0
\`\`\`Publishing Process
# Test locally first
prpm test
# Publish to registry
prpm publish
# Version bumps
prpm publish patch # 1.0.0 -> 1.0.1
prpm publish minor # 1.0.0 -> 1.1.0
prpm publish major # 1.0.0 -> 2.0.0Security Requirements
Input Validation
# Parse JSON safely
INPUT=$(cat)
if ! FILE=$(echo "$INPUT" | jq -r '.input.file_path // empty' 2>&1); then
echo "JSON parse failed" >&2
exit 1
fi
# Validate field exists
[[ -n "$FILE" ]] || exit 1Path Sanitization
# Prevent directory traversal
if [[ "$FILE" == *".."* ]]; then
echo "Path traversal detected" >&2
exit 2
fi
# Keep in project directory
if [[ "$FILE" != "$CLAUDE_PROJECT_DIR"* ]]; then
echo "File outside project" >&2
exit 2
fiUser Confirmation
Claude Code automatically:
- Requires confirmation before installing hooks
- Shows hook source code to user
- Warns about hook execution
- Displays hook output in transcript
Hooks vs Skills vs Commands
| Feature | Hooks | Skills | Commands |
| Format | Executable code | Markdown | Markdown |
| Trigger | Automatic (events) | Automatic (context) | Manual (/command) |
| Language | Any executable | N/A | N/A |
| Use Case | Automation, validation | Reference, patterns | Quick tasks |
| Security | Requires confirmation | No special permissions | Inherits from session |
Examples:
- Hook: Auto-format files on save
- Skill: Reference guide for testing patterns
- Command:
/review-prquick code review
Related Resources
- claude-hook-writer skill - Detailed hook development guidance
- typescript-hook-writer skill - TypeScript-specific hook development
- Claude Code Docs
- Schema
Checklist for New Hooks
Before publishing:
- Shebang line included
- File is executable (
chmod +x) - Validates all stdin input
- Quotes all variables
- Handles missing dependencies gracefully
- Uses appropriate exit codes
- Logs errors to stderr or file
- Tests with edge cases (spaces, Unicode, missing fields)
- Documents dependencies in HOOK.md
- Includes installation instructions
- Source code included in documentation
- Clear description and tags in prpm.json
- Version number is semantic
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

