Claude.Hooks.Hook.Behaviour behaviour (claude v0.1.0)

Behaviour for implementing Claude Code hooks.

Hooks must implement:

  • config/0 to return their hook configuration as a %Claude.Hooks.Hook{} struct
  • run/2 to execute the hook logic
  • description/0 to provide a human-readable description

Summary

Callbacks

Returns the hook configuration as a %Claude.Hook{} struct.

Returns a human-readable description of what this hook does.

Executes the hook logic.

Callbacks

config()

@callback config() :: Claude.Hooks.Hook.t()

Returns the hook configuration as a %Claude.Hook{} struct.

This configuration will be automatically encoded to JSON and written to the settings.json file during installation.

description()

@callback description() :: String.t()

Returns a human-readable description of what this hook does.

run(event_type, file_path)

@callback run(event_type :: String.t(), file_path :: String.t()) :: :ok | {:error, term()}

Executes the hook logic.

Parameters

  • event_type - The type of event that triggered this hook (e.g., "Write", "Edit")
  • file_path - The path to the file being processed

Return values

  • :ok - Hook executed successfully
  • {:error, reason} - Hook execution failed