AOT-ready .NET models for building Claude Code hook processors.
Claude Code hooks let you intercept and customize Claude's behavior. ClaudeEssentials provides strongly-typed C# models for all hook events, with source-generated JSON serialization for instant startup.
dotnet add package ClaudeEssentialsusing CloudNimble.ClaudeEssentials.Hooks;
using CloudNimble.ClaudeEssentials.Hooks.Enums;
using CloudNimble.ClaudeEssentials.Hooks.Outputs;
// Read JSON from stdin
var json = Console.In.ReadToEnd();
var input = ClaudeHooksSerializer.DeserializePreToolUseInput(json);
// Auto-approve read-only tools
var output = new PreToolUseHookOutput<object>
{
Continue = true,
HookSpecificOutput = new PreToolUseSpecificOutput<object>
{
PermissionDecision = input.ToolName is "Read" or "Glob"
? PermissionDecision.Allow
: PermissionDecision.Ask
}
};
// Write response to stdout
Console.WriteLine(ClaudeHooksSerializer.SerializePreToolUseOutput(output));| Hook | Purpose |
|---|---|
PreToolUse |
Approve, deny, or modify tool calls before execution |
PostToolUse |
Add context or take action after tools complete |
Stop |
Enforce policies before Claude ends a session |
SessionStart |
Inject project context when sessions begin |
Notification |
React to permission prompts and notifications |
UserPromptSubmit |
Process user prompts before they're sent |
PreCompact |
Customize context compaction behavior |
- AOT Ready - Source-generated serialization, zero reflection
- Strongly Typed - Full IntelliSense and compile-time safety
- Lightweight - No dependencies beyond System.Text.Json
Full documentation available at easyaf.dev/claudeessentials
MIT