Skip to main content

Summary

The CloudNimble.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:
  1. Reads JSON from stdin
  2. Processes the input
  3. Writes JSON to stdout
  4. 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

Enums