hook-authoring
Guide for creating Claude Code hooks with security-first design. Use for validation, logging, and policy enforcement
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/athola/nm-abstract-hook-authoringNight Market Skill — ported from claude-night-market/abstract. For the full experience with agents, hooks, and commands, install the Claude Code plugin.
Table of Contents
- Overview
- Key Capabilities
- Quick Start
- Your First Hook (JSON - Claude Code)
- Your First Hook (Python - Claude Agent SDK)
- Hook Event Types
- Claude Code vs SDK
- JSON Hooks (Claude Code)
- Python SDK Hooks
- Security Essentials
- Critical Security Rules
- Example: Secure Logging Hook
- Performance Guidelines
- Performance Best Practices
- Example: Efficient Hook
- Scope Selection
- Decision Framework
- Scope Comparison
- Common Patterns
- Validation Hook
- Logging Hook
- Context Injection Hook
- Testing Hooks
- Unit Testing
- Module References
- Tools
- Related Skills
- Next Steps
- References
Hook Authoring Guide
Overview
Hooks are event interceptors that allow you to extend Claude Code and Claude Agent SDK behavior by executing custom logic at specific points in the agent lifecycle. They enable validation before tool use, logging after actions, context injection, workflow automation, and security enforcement.
This skill teaches you how to write effective, secure, and performant hooks for both declarative JSON (Claude Code) and programmatic Python (Claude Agent SDK) use cases.
Key Capabilities
- PreToolUse: Validate, filter, or transform tool inputs before execution; inject context (2.1.9+)
- PostToolUse: Log, analyze, or modify tool outputs after execution
- UserPromptSubmit: Inject context or filter user messages before processing
- Stop/SubagentStop: Cleanup, final reporting, or result aggregation
- TeammateIdle/TaskCompleted: Multi-agent coordination and orchestration (2.1.33+)
- PreCompact: State preservation before context window compaction
New in 2.1.9: PreToolUse hooks can now return
additionalContextto inject information before a tool executes. This enables patterns like cache hints, security warnings, or relevant context injection.
Quick Start
Your First Hook (JSON - Claude Code)
Create a simple logging hook in .claude/settings.json:
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-athola-nm-abstract-hook-authoring": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
extract
Analyze a codebase and build a knowledge base of business logic, architecture, data flow, and engineering patterns. The foundation for gauntlet challenges and agent integration
discourse
>- Scan community discussion channels (HN, Lobsters, Reddit, tech blogs) for experience reports and opinions on a topic
synthesize
>- Merge, deduplicate, rank, and format research findings from multiple channels into a coherent report. Use after research agents return their results
workflow-monitor
Detect workflow failures and inefficient patterns, then create GitHub issues for improvement via /fix-workflow
architecture-paradigm-hexagonal
Hexagonal (Ports and Adapters) architecture isolating domain logic from infrastructure