← スキル一覧に戻る

writing-hooks
by erikpr1994
⭐ 0🍴 0📅 2026年1月22日
SKILL.md
name: writing-hooks description: "Use when creating hooks for prompt interception, permission handling, or event-triggered automation with timeout and bypass handling."
Writing Hooks
Overview
Hooks intercept events (prompts, permissions, tool calls) to inject behavior. Good hooks are fast, have graceful failures, and define bypass conditions.
When to Create
Create a hook when:
- Behavior should apply to ALL relevant events
- Pre-processing or validation is needed
- Automation can replace manual steps
- Skill activation should be automatic
Don't create for:
- Occasional interventions (use rules)
- Complex logic (use commands or skills)
- User-initiated workflows (use commands)
Structure Template
---
name: hook-name
type: [UserPromptSubmit | PermissionRequest | ToolExecution]
timeout_ms: [number]
---
# Hook Name
## Purpose
[What this hook accomplishes]
## Trigger Event
[Exact event type and conditions]
## Input Format
[JSON structure received]
## Processing Logic
[What the hook does]
## Output Format
[JSON structure returned or modification made]
## Timeout Handling
[What happens if hook exceeds timeout]
## Bypass Conditions
[When hook should be skipped]
## Error Handling
[Graceful failure behavior]
Quality Checklist
- Hook type correctly identified
- Timeout is reasonable (< 5000ms for prompt hooks)
- Input/output JSON formats defined
- Bypass conditions explicit
- Error handling prevents blocking
- Graceful degradation (fails open, not closed)
- No side effects on main context
- Cross-platform if using scripts
Testing Requirements
- Trigger test - Hook fires on correct events
- Timeout test - Behavior when timeout exceeded
- Bypass test - Skipped when conditions met
- Error test - Graceful failure on exceptions
- Performance test - Stays within timeout
- Platform test - Works on Windows/Mac/Linux
Examples
Good Hook (Skill Activation):
---
name: skill-activation
type: UserPromptSubmit
timeout_ms: 3000
---
## Purpose
Analyze prompts and recommend relevant skills.
## Trigger Event
Every UserPromptSubmit event.
## Input Format
{
"session_id": "string",
"prompt": "string"
}
## Processing Logic
1. Parse prompt for keywords
2. Match against skill-rules.json
3. Append skill recommendations to prompt
## Output Format
{
"prompt": "original + skill recommendations"
}
## Timeout Handling
Return original prompt unchanged.
## Bypass Conditions
- Prompt starts with /command
- Prompt is < 5 characters
## Error Handling
Log error, return original prompt.
Good Hook (Permission):
---
name: safe-permissions
type: PermissionRequest
timeout_ms: 5000
---
## Purpose
Auto-approve safe operations, block dangerous ones.
## Processing Logic
Tier 1 (fast approve): Read, Write, Glob, Grep
Tier 2 (fast deny): rm -rf /, force push main
Tier 3 (analyze): Everything else via LLM
## Bypass Conditions
- User in --dangerous mode
Bad Hook:
---
name: helper-hook
---
Does helpful things when stuff happens.
(No type, no timeout, no error handling)
Common Mistakes
| Mistake | Fix |
|---|---|
| No timeout defined | Add reasonable timeout_ms |
| Fails closed | Fail open (return unchanged input) |
| No bypass conditions | Define when to skip |
| Platform-specific | Use cross-platform scripts |
| Side effects | Hooks should be pure/stateless |
| Too slow | Optimize or move logic elsewhere |
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です