The Problem
Claude Code hooks communicate via JSON over stdin/stdout. Building hook processors means:- Manually crafting JSON schemas that match Claude’s expectations
- Handling snake_case property names and nullable fields
- Ensuring your code works with AOT compilation for fast startup
- Testing serialization round-trips to catch subtle bugs
Design Principles
AOT-First
Source-generated serialization means zero reflection at runtime. Your hooks start instantly.
Type-Safe
Strongly-typed models catch errors at compile time, not when Claude calls your hook.
Zero Dependencies
Only requires System.Text.Json. No bloat, no conflicts, no surprises.
Predictable
Every input deserializes correctly. Every output serializes to valid JSON. Guaranteed by tests.
What’s Included
Input Models
Strongly-typed classes for every hook event Claude Code can trigger:PreToolUseHookInput<T>— Tool name, input parameters, permission modePostToolUseHookInput<T, R>— Tool input plus the responseStopHookInput— Session context when Claude wants to stopSessionStartHookInput— Project path, source (startup vs resume)- And more:
Notification,UserPromptSubmit,PreCompact,SessionEnd
Output Models
Response types with all the fields Claude Code expects:PreToolUseHookOutput<T>— Allow, deny, or ask for permissionPostToolUseHookOutput— Add context for Claude to considerStopHookOutput— Block stopping or add a warningSessionStartHookOutput— Inject project context
Serialization Helpers
ClaudeHooksSerializer provides typed methods that use the pre-compiled ClaudeHooksJsonContext:
Use Cases
Enforce Team Policies
Enforce Team Policies
Auto-approve read-only tools while requiring confirmation for file modifications. Block dangerous commands entirely.
Quality Gates
Quality Gates
Use Stop hooks to ensure tests pass before Claude completes a task. Warn about uncommitted changes.
Context Injection
Context Injection
Detect project type on SessionStart and inject relevant context—framework version, test commands, team guidelines.
Audit & Logging
Audit & Logging
Log every tool call for compliance. Track what Claude does across sessions.