Skip to main content

Definition

Assembly: CloudNimble.ClaudeEssentials.dll Namespace: CloudNimble.ClaudeEssentials.Hooks Inheritance: System.Object

Syntax

CloudNimble.ClaudeEssentials.Hooks.ClaudeHooksSerializer

Summary

Provides static helper methods for serializing and deserializing Claude Code hook types. All methods use the AOT-compatible ClaudeHooksJsonContext for serialization.

Usage

ClaudeHooksSerializer provides AOT-compatible static methods for JSON serialization using source-generated contexts.

Deserializing Input

// Read and deserialize from stdin
string json = Console.In.ReadToEnd();

var preToolUse = ClaudeHooksSerializer.DeserializePreToolUseInput(json);
var postToolUse = ClaudeHooksSerializer.DeserializePostToolUseInput(json);
var stop = ClaudeHooksSerializer.DeserializeStopInput(json);
var notification = ClaudeHooksSerializer.DeserializeNotificationInput(json);

Serializing Output

// Create and serialize output
var output = new PreToolUseHookOutput<object> { Continue = true };
string json = ClaudeHooksSerializer.SerializePreToolUseOutput(output);
Console.WriteLine(json);

Using Custom Types

For strongly-typed tool inputs, create your own JsonSerializerContext:
[JsonSerializable(typeof(PreToolUseHookInput<MyToolInput>))]
public partial class MyJsonContext : JsonSerializerContext { }

var input = ClaudeHooksSerializer.DeserializePreToolUseInput<MyToolInput>(
    json, MyJsonContext.Default.PreToolUseHookInputMyToolInput);

Properties

DefaultOptions

Gets the default JsonSerializerOptions configured for Claude Code hooks. This instance is configured with the ClaudeHooksJsonContext for AOT compatibility.

Syntax

public static System.Text.Json.JsonSerializerOptions DefaultOptions { get; }

Property Value

Type: System.Text.Json.JsonSerializerOptions

Methods

DeserializeNotificationInput

Deserializes a JSON string to a NotificationHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.NotificationHookInput DeserializeNotificationInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.NotificationHookInput? The deserialized hook input, or null if deserialization fails.

DeserializePermissionRequestInput

Deserializes a JSON string to a PermissionRequestHookInput1` with dynamic tool input.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.PermissionRequestHookInput<object> DeserializePermissionRequestInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.PermissionRequestHookInput<object>? The deserialized hook input, or null if deserialization fails.

DeserializePostToolUseInput

Deserializes a JSON string to a PostToolUseHookInput2` with dynamic types.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.PostToolUseHookInput<object, object> DeserializePostToolUseInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.PostToolUseHookInput<object, object>? The deserialized hook input, or null if deserialization fails.

DeserializePostToolUseInput

Deserializes a JSON string to a PostToolUseHookInput2` with specific types.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.PostToolUseHookInput<TToolInput, TToolResponse> DeserializePostToolUseInput<TToolInput, TToolResponse>(string json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<CloudNimble.ClaudeEssentials.Hooks.Inputs.PostToolUseHookInput<TToolInput, TToolResponse>> typeInfo) where TToolInput : class where TToolResponse : class

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.
typeInfoSystem.Text.Json.Serialization.Metadata.JsonTypeInfo<CloudNimble.ClaudeEssentials.Hooks.Inputs.PostToolUseHookInput<TToolInput, TToolResponse>>The JSON type info for the specific input type.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.PostToolUseHookInput<TToolInput, TToolResponse>? The deserialized hook input, or null if deserialization fails.

Type Parameters

  • TToolInput - The type of the tool input.
  • TToolResponse - The type of the tool response.

DeserializePreCompactInput

Deserializes a JSON string to a PreCompactHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.PreCompactHookInput DeserializePreCompactInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.PreCompactHookInput? The deserialized hook input, or null if deserialization fails.

DeserializePreToolUseInput

Deserializes a JSON string to a PreToolUseHookInput1` with dynamic tool input.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.PreToolUseHookInput<object> DeserializePreToolUseInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.PreToolUseHookInput<object>? The deserialized hook input, or null if deserialization fails.

DeserializePreToolUseInput

Deserializes a JSON string to a PreToolUseHookInput1` with a specific tool input type.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.PreToolUseHookInput<TToolInput> DeserializePreToolUseInput<TToolInput>(string json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<CloudNimble.ClaudeEssentials.Hooks.Inputs.PreToolUseHookInput<TToolInput>> typeInfo) where TToolInput : class

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.
typeInfoSystem.Text.Json.Serialization.Metadata.JsonTypeInfo<CloudNimble.ClaudeEssentials.Hooks.Inputs.PreToolUseHookInput<TToolInput>>The JSON type info for the specific input type.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.PreToolUseHookInput<TToolInput>? The deserialized hook input, or null if deserialization fails.

Type Parameters

  • TToolInput - The type of the tool input.

DeserializeSessionEndInput

Deserializes a JSON string to a SessionEndHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.SessionEndHookInput DeserializeSessionEndInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.SessionEndHookInput? The deserialized hook input, or null if deserialization fails.

DeserializeSessionStartInput

Deserializes a JSON string to a SessionStartHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.SessionStartHookInput DeserializeSessionStartInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.SessionStartHookInput? The deserialized hook input, or null if deserialization fails.

DeserializeStopInput

Deserializes a JSON string to a StopHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.StopHookInput DeserializeStopInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.StopHookInput? The deserialized hook input, or null if deserialization fails.

DeserializeSubagentStopInput

Deserializes a JSON string to a SubagentStopHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.SubagentStopHookInput DeserializeSubagentStopInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.SubagentStopHookInput? The deserialized hook input, or null if deserialization fails.

DeserializeUserPromptSubmitInput

Deserializes a JSON string to a UserPromptSubmitHookInput.

Syntax

public static CloudNimble.ClaudeEssentials.Hooks.Inputs.UserPromptSubmitHookInput DeserializeUserPromptSubmitInput(string json)

Parameters

NameTypeDescription
jsonstringThe JSON string to deserialize.

Returns

Type: CloudNimble.ClaudeEssentials.Hooks.Inputs.UserPromptSubmitHookInput? The deserialized hook input, or null if deserialization fails.

SerializeNotificationOutput

Serializes a NotificationHookOutput to JSON.

Syntax

public static string SerializeNotificationOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.NotificationHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.NotificationHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializePermissionRequestOutput

Serializes a PermissionRequestHookOutput1` with dynamic tool input to JSON.

Syntax

public static string SerializePermissionRequestOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.PermissionRequestHookOutput<object> output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.PermissionRequestHookOutput<object>The hook output to serialize.

Returns

Type: string The JSON string representation.

SerializePostToolUseOutput

Serializes a PostToolUseHookOutput to JSON.

Syntax

public static string SerializePostToolUseOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.PostToolUseHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.PostToolUseHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializePreCompactOutput

Serializes a PreCompactHookOutput to JSON.

Syntax

public static string SerializePreCompactOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.PreCompactHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.PreCompactHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializePreToolUseOutput

Serializes a PreToolUseHookOutput1` with dynamic tool input to JSON.

Syntax

public static string SerializePreToolUseOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.PreToolUseHookOutput<object> output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.PreToolUseHookOutput<object>The hook output to serialize.

Returns

Type: string The JSON string representation.

SerializePreToolUseOutput

Serializes a PreToolUseHookOutput1` with a specific tool input type to JSON.

Syntax

public static string SerializePreToolUseOutput<TToolInput>(CloudNimble.ClaudeEssentials.Hooks.Outputs.PreToolUseHookOutput<TToolInput> output, System.Text.Json.Serialization.Metadata.JsonTypeInfo<CloudNimble.ClaudeEssentials.Hooks.Outputs.PreToolUseHookOutput<TToolInput>> typeInfo) where TToolInput : class

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.PreToolUseHookOutput<TToolInput>The hook output to serialize.
typeInfoSystem.Text.Json.Serialization.Metadata.JsonTypeInfo<CloudNimble.ClaudeEssentials.Hooks.Outputs.PreToolUseHookOutput<TToolInput>>The JSON type info for the specific output type.

Returns

Type: string The JSON string representation.

Type Parameters

  • TToolInput - The type of the tool input.

SerializeSessionEndOutput

Serializes a SessionEndHookOutput to JSON.

Syntax

public static string SerializeSessionEndOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.SessionEndHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.SessionEndHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializeSessionStartOutput

Serializes a SessionStartHookOutput to JSON.

Syntax

public static string SerializeSessionStartOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.SessionStartHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.SessionStartHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializeStopOutput

Serializes a StopHookOutput to JSON.

Syntax

public static string SerializeStopOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.StopHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.StopHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializeSubagentStopOutput

Serializes a SubagentStopHookOutput to JSON.

Syntax

public static string SerializeSubagentStopOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.SubagentStopHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.SubagentStopHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.

SerializeUserPromptSubmitOutput

Serializes a UserPromptSubmitHookOutput to JSON.

Syntax

public static string SerializeUserPromptSubmitOutput(CloudNimble.ClaudeEssentials.Hooks.Outputs.UserPromptSubmitHookOutput output)

Parameters

NameTypeDescription
outputCloudNimble.ClaudeEssentials.Hooks.Outputs.UserPromptSubmitHookOutputThe hook output to serialize.

Returns

Type: string The JSON string representation.