Hooks Configuration Reference
Complete reference for configuring hooks in Radium using TOML configuration files.
Overviewβ
Hooks can be configured in two locations:
- Workspace Configuration:
.radium/hooks.tomlin your workspace root - Extension Configuration:
hooks.tomlin extension directories (automatically discovered)
Workspace configurations take precedence over extension configurations for hooks with the same name.
Configuration File Formatβ
Hooks are configured using TOML format with a [[hooks]] array of hook definitions:
[[hooks]]
name = "my-hook"
type = "before_model"
priority = 100
enabled = true
script = "hooks/my-hook.rs"
[hooks.config]
custom_option = "value"
Hook Definition Fieldsβ
Required Fieldsβ
name (string)β
Unique identifier for the hook within the configuration context.
- Required: Yes
- Example:
"logging-hook","metrics-collector" - Constraints: Cannot be empty
- Validation: Must be unique within the configuration file
type (string)β
Hook type that determines when and how the hook executes.
- Required: Yes
- Valid Values:
"before_model"- Execute before model calls"after_model"- Execute after model calls"before_tool"- Execute before tool execution"after_tool"- Execute after tool execution"tool_selection"- Execute during tool selection"error_interception"- Intercept errors before propagation"error_transformation"- Transform error messages"error_recovery"- Attempt error recovery"error_logging"- Log errors with custom formatting"telemetry_collection"- Collect and aggregate telemetry"custom_logging"- Custom logging hooks"metrics_aggregation"- Aggregate metrics"performance_monitoring"- Monitor performance
Optional Fieldsβ
priority (integer)β
Execution priority for the hook. Higher priority hooks execute first.
- Required: No
- Default:
100 - Range: Any positive integer
- Conventions:
200+- Critical hooks that must run first100-199- Standard hooks (default)<100- Optional hooks
enabled (boolean)β
Whether the hook is enabled and will be executed.
- Required: No
- Default:
true - Note: Disabled hooks are still registered but not executed
script (string)β
Path to the hook implementation script or library.
- Required: If
configis not provided (at least one ofscriptorconfigmust be set) - Example:
"hooks/logging.rs","extensions/my-extension/hooks/cache.rs" - Note: For programmatic hooks, this can be omitted if using
configwith inline configuration
config (table)β
Inline configuration for the hook. Used for hooks that don't require external scripts.
- Required: If
scriptis not provided (at least one ofscriptorconfigmust be set) - Type: TOML table (
[hooks.config]) - Example:
[hooks.config]
log_level = "info"
max_retries = 3
timeout = 5000
Configuration Examplesβ
Basic Model Hookβ
[[hooks]]
name = "input-validator"
type = "before_model"
priority = 200
enabled = true
script = "hooks/validate-input.rs"
[hooks.config]
max_length = 10000
allow_empty = false
Telemetry Collection Hookβ
[[hooks]]
name = "cost-tracker"
type = "telemetry_collection"
priority = 100
enabled = true
[hooks.config]
track_tokens = true
track_costs = true
output_file = "logs/costs.json"
Error Handling Hookβ
[[hooks]]
name = "error-recovery"
type = "error_recovery"
priority = 150
enabled = true
script = "hooks/recover-errors.rs"
[hooks.config]
max_retries = 3
backoff_multiplier = 2.0
retryable_errors = ["timeout", "rate_limit"]
Multiple Hooks in One Fileβ
# Before model hook
[[hooks]]
name = "request-logger"
type = "before_model"
priority = 100
enabled = true
script = "hooks/logging.rs"
[hooks.config]
log_level = "info"
# After model hook
[[hooks]]
name = "response-processor"
type = "after_model"
priority = 100
enabled = true
script = "hooks/process-response.rs"
# Tool execution hook
[[hooks]]
name = "tool-validator"
type = "before_tool"
priority = 150
enabled = true
script = "hooks/validate-tool.rs"
Extension Configurationβ
In extension directories (e.g., extensions/my-extension/hooks.toml):
[[hooks]]
name = "extension-metrics"
type = "metrics_aggregation"
priority = 50
enabled = true
[hooks.config]
namespace = "my-extension"
export_to = "prometheus"
Validation Rulesβ
The configuration system validates hooks when they are loaded. Validation errors prevent the hook from being registered.
Name Validationβ
- β Empty string
- β Non-empty string
- β οΈ Duplicate names in the same file will overwrite previous definitions
Type Validationβ
- β Empty string
- β Invalid hook type (not in the 13 valid types)
- β One of the 13 valid hook types
Script/Config Validationβ
- β Neither
scriptnorconfigprovided - β
At least one of
scriptorconfigprovided - β Both provided (script takes precedence)
Priority Validationβ
- β Any positive integer (no maximum enforced)
- β οΈ Negative numbers are accepted but not recommended
Configuration Discoveryβ
Hooks are automatically discovered from:
-
Workspace Configuration:
.radium/hooks.toml- Highest priority
- Applies to all agents in the workspace
-
Extension Configurations:
extensions/*/hooks.toml- Discovered automatically
- Lower priority than workspace config
- Hooks with same name override extension hooks
-
Programmatic Registration: Hooks registered directly in code
- Can be enabled/disabled via configuration
- Name must match configuration entry
Enabling and Disabling Hooksβ
Hooks can be enabled or disabled in two ways:
Via Configuration Fileβ
Edit .radium/hooks.toml and set enabled = false:
[[hooks]]
name = "my-hook"
type = "before_model"
enabled = false # Disabled
Via CLI Commandsβ
# Disable a hook
rad hooks disable my-hook
# Enable a hook
rad hooks enable my-hook
The CLI updates both the registry and the configuration file automatically.
Validation Commandβ
Validate all hook configurations:
rad hooks validate
This command:
- Loads all hook configurations from workspace and extensions
- Runs validation checks on each hook
- Reports any validation errors
- Provides helpful error messages for fixing issues
Configuration Best Practicesβ
Naming Conventionsβ
- Use descriptive names:
"model-request-logger"not"hook1" - Include hook type in name if useful:
"before-tool-validator" - Use kebab-case for consistency
Priority Guidelinesβ
- Reserve priorities 200+ for critical system hooks
- Use 100-199 for standard application hooks
- Use <100 for optional or experimental hooks
Organizationβ
- Group related hooks in the same file
- Use comments to document hook purpose
- Keep workspace hooks minimal (use extensions for complex hooks)
Testingβ
- Test hooks with
rad hooks test <name>before enabling - Validate configuration with
rad hooks validate - Use descriptive
configsections for hook-specific options
Troubleshootingβ
Hook Not Executingβ
- Check if hook is enabled:
rad hooks info <name> - Verify hook type matches execution point
- Check priority isn't being overridden
- Ensure script path is correct (if using
script)
Validation Errorsβ
Common validation errors and fixes:
- "Hook name cannot be empty": Provide a
namefield - "Invalid hook type": Check
typeagainst valid values list - "Either script or config must be provided": Add
scriptorconfigfield
Configuration Not Loadingβ
- Check file location (
.radium/hooks.tomlfor workspace) - Verify TOML syntax is correct
- Use
rad hooks validateto check for errors - Check file permissions
Related Documentationβ
- Getting Started Guide - Basic usage examples
- Creating Hooks - How to implement hooks
- Hook Types - Detailed hook type reference
- Examples - Configuration examples