ClawKit Logo
ClawKitReliability Toolkit
Back to Registry
Official Verified

hook-authoring

Guide for creating Claude Code hooks with security-first design. Use for validation, logging, and policy enforcement

skill-install — Terminal

Install via CLI (Recommended)

clawhub install openclaw/skills/skills/athola/nm-abstract-hook-authoring
Or

Night 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 additionalContext to 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

Author@athola
Stars4473
Views1
Updated2026-05-01
View Author Profile
AI Skill Finder

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 skill
Add to Configuration

Paste this into your clawhub.json to enable this plugin.

{
  "plugins": {
    "official-athola-nm-abstract-hook-authoring": {
      "enabled": true,
      "auto_update": true
    }
  }
}
Safety NoteClawKit audits metadata but not runtime behavior. Use with caution.