> ## Documentation Index
> Fetch the complete documentation index at: https://ai.easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Summary of the CloudNimble.ClaudeEssentials.Hooks Namespace

## 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)

```csharp theme={null}
using CloudNimble.ClaudeEssentials.Hooks;
using CloudNimble.ClaudeEssentials.Hooks.Inputs;
using CloudNimble.ClaudeEssentials.Hooks.Outputs;

// Read input from stdin
var json = Console.In.ReadToEnd();
var input = ClaudeHooksSerializer.DeserializePreToolUseInput(json);

// Process and respond
var output = new PreToolUseHookOutput<object> { Continue = true };
Console.WriteLine(ClaudeHooksSerializer.SerializePreToolUseOutput(output));
```

### Hook Configuration

Configure hooks in `~/.claude/settings.json` or `.claude/settings.json`:

```json theme={null}
{
"hooks": {
  "PreToolUse": [
    {
      "matcher": "Write|Edit",
      "hooks": [{ "type": "command", "command": "my-hook.exe" }]
    }
  ]
}
}
```

## Examples

### PreToolUse: Auto-approve safe tools

```csharp theme={null}
var input = ClaudeHooksSerializer.DeserializePreToolUseInput(Console.In.ReadToEnd());

var output = new PreToolUseHookOutput<object>
{
HookSpecificOutput = new PreToolUseSpecificOutput<object>
{
    PermissionDecision = input?.ToolName == "Read"
        ? PermissionDecision.Allow
        : PermissionDecision.Ask,
    PermissionDecisionReason = "Read operations are safe"
}
};

Console.WriteLine(ClaudeHooksSerializer.SerializePreToolUseOutput(output));
```

### PostToolUse: Log tool executions

```csharp theme={null}
var input = ClaudeHooksSerializer.DeserializePostToolUseInput(Console.In.ReadToEnd());

File.AppendAllText("hooks.log", $"{DateTime.Now}: {input?.ToolName}\n");

Console.WriteLine(ClaudeHooksSerializer.SerializePostToolUseOutput(new PostToolUseHookOutput()));
```

### Stop: Require confirmation before stopping

```csharp theme={null}
var input = ClaudeHooksSerializer.DeserializeStopInput(Console.In.ReadToEnd());

var output = new StopHookOutput
{
Decision = HookDecision.Block,
Reason = "Please confirm all tests pass before stopping."
};

Console.WriteLine(ClaudeHooksSerializer.SerializeStopOutput(output));
```

## Types

### &#x20;Classes

| Name | Summary |
| - | - |
| [ClaudeHooksJsonContext](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ClaudeHooksJsonContext.md) | 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](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ClaudeHooksSerializer.md) | Provides static helper methods for serializing and deserializing Claude Code hook types.  All methods use the AOT-compatible [ClaudeHooksJsonContext](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ClaudeHooksJsonContext.md) for serialization. |
| [ClaudeModel](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ClaudeModel.md) | Represents the Claude model family used in a session or tool invocation. |
| [CompactTrigger](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/CompactTrigger.md) | Represents what triggered a compact operation. |
| [ConfigOperation](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ConfigOperation.md) | Represents the type of operation performed on a Claude Code configuration entry. |
| [ContentBlockType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ContentBlockType.md) | Represents the type of a content block within a Claude message or response. |
| [GitDiffStatus](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/GitDiffStatus.md) | Represents the diff status of a file in a git operation. |
| [GrepOutputMode](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/GrepOutputMode.md) | Represents the output mode for grep search results. [GrepOutputMode.FilesWithMatches](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/GrepOutputMode.md#fileswithmatches) is the default. |
| [HookDecision](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/HookDecision.md) | Represents a hook's decision to block an operation. |
| [HookEventName](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/HookEventName.md) | Represents the different types of hook events that can be triggered in Claude Code. |
| [NotebookCellType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/NotebookCellType.md) | Represents the type of a cell within a Jupyter notebook. |
| [NotebookEditMode](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/NotebookEditMode.md) | Represents the edit operation mode applied to a Jupyter notebook cell. |
| [NotificationType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/NotificationType.md) | Represents the type of notification sent by Claude Code. |
| [PermissionDecision](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/PermissionDecision.md) | Represents the decision for a PreToolUse permission check. |
| [PermissionMode](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/PermissionMode.md) | Represents the permission mode under which Claude Code is operating. |
| [PermissionRequestBehavior](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/PermissionRequestBehavior.md) | Represents the behavior decision for a PermissionRequest hook. |
| [SessionEndReason](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/SessionEndReason.md) | Represents the reason why a session ended. |
| [SessionStartSource](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/SessionStartSource.md) | Represents the source that triggered a session start event. |
| [TaskExecutionStatus](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/TaskExecutionStatus.md) | Represents the execution status of a Claude Code task. Named `TaskExecutionStatus` to avoid  collision with [TaskStatus](https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskstatus). |
| [TodoItemStatus](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/TodoItemStatus.md) | Represents the status of a to-do item tracked by Claude Code. |
| [WorktreeAction](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/WorktreeAction.md) | Represents the action to take when exiting a git worktree. |
| [WriteOperationType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/WriteOperationType.md) | Represents the type of write operation performed on a file. |

### &#x20;Enums

| Name | Summary |
| - | - |
| [ClaudeModel](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ClaudeModel.md) | Represents the Claude model family used in a session or tool invocation. |
| [CompactTrigger](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/CompactTrigger.md) | Represents what triggered a compact operation. |
| [ConfigOperation](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ConfigOperation.md) | Represents the type of operation performed on a Claude Code configuration entry. |
| [ContentBlockType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/ContentBlockType.md) | Represents the type of a content block within a Claude message or response. |
| [GitDiffStatus](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/GitDiffStatus.md) | Represents the diff status of a file in a git operation. |
| [GrepOutputMode](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/GrepOutputMode.md) | Represents the output mode for grep search results. [GrepOutputMode.FilesWithMatches](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/GrepOutputMode.md#fileswithmatches) is the default. |
| [HookDecision](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/HookDecision.md) | Represents a hook's decision to block an operation. |
| [HookEventName](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/HookEventName.md) | Represents the different types of hook events that can be triggered in Claude Code. |
| [NotebookCellType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/NotebookCellType.md) | Represents the type of a cell within a Jupyter notebook. |
| [NotebookEditMode](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/NotebookEditMode.md) | Represents the edit operation mode applied to a Jupyter notebook cell. |
| [NotificationType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/NotificationType.md) | Represents the type of notification sent by Claude Code. |
| [PermissionDecision](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/PermissionDecision.md) | Represents the decision for a PreToolUse permission check. |
| [PermissionMode](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/PermissionMode.md) | Represents the permission mode under which Claude Code is operating. |
| [PermissionRequestBehavior](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/PermissionRequestBehavior.md) | Represents the behavior decision for a PermissionRequest hook. |
| [SessionEndReason](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/SessionEndReason.md) | Represents the reason why a session ended. |
| [SessionStartSource](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/SessionStartSource.md) | Represents the source that triggered a session start event. |
| [TaskExecutionStatus](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/TaskExecutionStatus.md) | Represents the execution status of a Claude Code task. Named `TaskExecutionStatus` to avoid  collision with [TaskStatus](https://learn.microsoft.com/dotnet/api/system.threading.tasks.taskstatus). |
| [TodoItemStatus](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/TodoItemStatus.md) | Represents the status of a to-do item tracked by Claude Code. |
| [WorktreeAction](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/WorktreeAction.md) | Represents the action to take when exiting a git worktree. |
| [WriteOperationType](https://ai.easyaf.dev/claudeessentials/api-reference/CloudNimble/ClaudeEssentials/Hooks/WriteOperationType.md) | Represents the type of write operation performed on a file. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.