Skip to main content

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
ClaudeEssentials solves all of this with a single NuGet package.

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 mode
  • PostToolUseHookInput<T, R> — Tool input plus the response
  • StopHookInput — Session context when Claude wants to stop
  • SessionStartHookInput — 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 permission
  • PostToolUseHookOutput — Add context for Claude to consider
  • StopHookOutput — Block stopping or add a warning
  • SessionStartHookOutput — Inject project context

Serialization Helpers

ClaudeHooksSerializer provides typed methods that use the pre-compiled ClaudeHooksJsonContext:
// Deserialize input
var input = ClaudeHooksSerializer.DeserializePreToolUseInput(json);

// Serialize output
var json = ClaudeHooksSerializer.SerializePreToolUseOutput(output);

Use Cases

Auto-approve read-only tools while requiring confirmation for file modifications. Block dangerous commands entirely.
Use Stop hooks to ensure tests pass before Claude completes a task. Warn about uncommitted changes.
Detect project type on SessionStart and inject relevant context—framework version, test commands, team guidelines.
Log every tool call for compliance. Track what Claude does across sessions.

Get Started