Summary
TheCloudNimble.ClaudeEssentials.Hooks namespace provides strongly-typed C# models for building Claude Code hooks. These models represent the JSON input/output schemas that Claude Code uses to communicate with hook executables.
Key Components
- Inputs: Classes for deserializing JSON received from Claude Code via stdin
- Outputs: Classes for serializing JSON responses to stdout
- Enums: Type-safe representations of hook events, decisions, and modes
- ClaudeHooksSerializer: AOT-compatible helper methods for JSON serialization
- ClaudeHooksJsonContext: Source-generated JSON context for Native AOT support
Usage
Basic Hook Pattern
A Claude Code hook is an executable that:- Reads JSON from stdin
- Processes the input
- Writes JSON to stdout
- Exits with an appropriate code (0 = success, 2 = blocking error)
Hook Configuration
Configure hooks in~/.claude/settings.json or .claude/settings.json:
Examples
PreToolUse: Auto-approve safe tools
PostToolUse: Log tool executions
Stop: Require confirmation before stopping
Types
Classes
| Name | Summary |
|---|---|
| ClaudeHooksJsonContext | Provides AOT-compatible JSON serialization context for Claude Code hook types. This context uses source generators to pre-compile serialization code, eliminating the need for runtime reflection. |
| ClaudeHooksSerializer | Provides static helper methods for serializing and deserializing Claude Code hook types. All methods use the AOT-compatible ClaudeHooksJsonContext for serialization. |