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. |
| CompactTrigger | Represents what triggered a compact operation. |
| HookDecision | Represents a hook’s decision to block or allow an operation. |
| HookEventName | Represents the different types of hook events that can be triggered in Claude Code. |
| NotificationType | Represents the type of notification sent by Claude Code. |
| PermissionDecision | Represents the decision for a PreToolUse permission check. |
| PermissionMode | Represents the permission mode under which Claude Code is operating. |
| PermissionRequestBehavior | Represents the behavior decision for a PermissionRequest hook. |
| SessionEndReason | Represents the reason why a session ended. |
| SessionStartSource | Represents the source that triggered a session start event. |
Enums
| Name | Summary |
|---|---|
| CompactTrigger | Represents what triggered a compact operation. |
| HookDecision | Represents a hook’s decision to block or allow an operation. |
| HookEventName | Represents the different types of hook events that can be triggered in Claude Code. |
| NotificationType | Represents the type of notification sent by Claude Code. |
| PermissionDecision | Represents the decision for a PreToolUse permission check. |
| PermissionMode | Represents the permission mode under which Claude Code is operating. |
| PermissionRequestBehavior | Represents the behavior decision for a PermissionRequest hook. |
| SessionEndReason | Represents the reason why a session ended. |
| SessionStartSource | Represents the source that triggered a session start event. |