claude-code-plugin-ref…
Explain plugin, skill, command, agent, and hook mechanics used here. Use when authoring or debugging plugins. Do not use for ops; use night-market-operations.
Guide creating Claude Code hooks with security-first design. Use for validation and enforcement.
$ npx -y skills add athola/claude-night-market --skill hook-authoring --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/hook-authoringContext preview
The summary Claude sees to decide when to auto-load this skill.
Guide creating Claude Code hooks with security-first design. Use for validation and enforcement.
name: hook-authoring description: 'Guide creating Claude Code hooks with security-first design. Use for validation and enforcement.' alwaysApply: false category: hook-development tags: - hooks - sdk - security - performance - automation - validation dependencies: [] estimated_tokens: 1200 complexity: intermediate model_hint: standard provides: patterns: - hook-authoring - security-patterns - performance-optimization infrastructure: - hook-validation - testing-framework usage_patterns: - writing-hooks - hook-validation - security-patterns - performance-optimization - sdk-integration
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.
> **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.
Create a simple logging hook in `.claude/settings.json`:
{
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "echo \"$(date): Executed $(jq -r '.tool_name')\" >> ~/.claude/audit.log"
}]
}
]
}**Note**: Use string matchers (`"Bash"`) not object matchers (`{"toolName": "Bash"}`).
**Verification:** Run the command with `--help` flag to verify availability.
This logs every Bash command execution with a timestamp.
Create a validation hook using the SDK:
from claude_agent_sdk import AgentHooks
class ValidationHooks(AgentHooks):
async def on_pre_tool_use(self, tool_name: str, tool_input: dict) -> dict | None:
"""Validate tool inputs before execution."""
if tool_name == "Bash":
command = tool_input.get("command", "")
if "rm -rf /" in command:
raise ValueError("Dangerous command blocked by hook")
# Return None to proceed unchanged, or modified dict to transform
return None**Verification:** Run the command with `--help` flag to verify availability.
Quick reference for all supported hook events:
| Event | Trigger Point | Parameters | Common Use Cases | |-------|--------------|------------|------------------| | **PreToolUse** | Before tool execution | `tool_name`, `tool_input` | Validation, filtering, input transformation | | **PostToolUse** | After tool execution | `tool_name`, `tool_input`, `tool_output` | Logging, metrics, output transformation | | **UserPromptSubmit** | User sends message | `message` | Context injection, content filtering | | **PermissionRequest** | Permission dialog shown | `tool_name`, `tool_input` | Auto-approve/deny with custom logic | | **Notification** | Claude Code sends notification | `message` | Custom notification handling | | **Stop** | Agent completes | `reason`, `result` | Final cleanup, summary reports | | **SubagentStop** | Subagent completes | `subagent_id`, `result` | Result processing, aggregation | | **TeammateIdle** | Teammate agent becomes idle | `agent_id`, `session_id` | Work assignment, load balancing (2.1.33+) | | **TaskCompleted** | Task finishes execution | `task_id`, `result` | Coordination, chaining, reporting (2.1.33+) | | **PreCompact** | Before context compact | `context_size` | State preservation, checkpointing | | **SessionStart** | Session starts/resumes | `session_id`, `source`, `agent_type` | Initialization, context loading | | **SessionEnd** |
A plugin marketplace for Claude Code. Install only the plugins you need to run git workflows, code review, spec-driven development, and autonomous agents from inside your Claude Code session.
Explain plugin, skill, command, agent, and hook mechanics used here. Use when authoring or debugging plugins. Do not use for ops; use night-market-operations.
States load-bearing decisions, invariants, and weak points. Use when judging a design change. Do not use for gating; use night-market-change-control.
Rebuild the dev environment: uv, Python tiers, pins, traps. Use when onboarding or toolchain breaks. Do not use for daily commands; use night-market-operations.
Classify, gate, and review changes. Use when landing a PR, releasing, or amending rules. Do not use for failure triage; use night-market-debugging-playbook.
Search and record project memory (Discussions, journal, ADRs). Use before re-investigating anything. Do not use for settled battles; see failure-archaeology.
Bind loop 'done' to unfakeable gates. Use to harden egregore/herald loops or promote completion_integrity. Not for QA gates; use night-market-validation-and-qa.