-
Notifications
You must be signed in to change notification settings - Fork 0
Hooks Variables
Status: ✅ Complete
Last Updated: December 5, 2025
This guide documents variable substitution and parameter binding in hooks. Variables allow you to use event context data in hook actions.
Variables are substituted using {{variable_name}} syntax:
action:
type: "command"
command: "echo"
args:
- "File: {{file_path}}"
- "Size: {{file_size}}"Direct values from event context:
args:
- "{{file_path}}"
- "{{file_size}}"Access nested properties with dot notation:
args:
- "{{metadata.size}}"
- "{{context.user_id}}"Mix literal text with variables:
args:
- "{{file_path}}/subdir"
- "output-{{timestamp}}.txt"Available variables:
-
file_path: Path to the created file -
size: File size in bytes -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Created: {{file_path}} ({{size}} bytes)"Available variables:
-
file_path: Path to the modified file -
old_hash: Hash of the file before modification -
new_hash: Hash of the file after modification -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Modified: {{file_path}}"
- "Old: {{old_hash}}"
- "New: {{new_hash}}"Available variables:
-
file_path: Path to the deleted file -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Deleted: {{file_path}}"Available variables:
-
old_path: Previous file path -
new_path: New file path -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Renamed: {{old_path}} -> {{new_path}}"Available variables:
-
old_path: Previous file path -
new_path: New file path -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Moved: {{old_path}} -> {{new_path}}"Available variables:
-
file_path: Path to the read file -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Read: {{file_path}}"Available variables:
-
directory_path: Path to the created directory -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Directory created: {{directory_path}}"Available variables:
-
directory_path: Path to the deleted directory -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Directory deleted: {{directory_path}}"Available variables:
-
test_file: Path to the test file -
test_count: Number of tests that passed -
duration_ms: Test execution duration in milliseconds -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Tests passed: {{test_count}} tests in {{duration_ms}}ms"Available variables:
-
test_file: Path to the test file -
failed_count: Number of tests that failed -
passed_count: Number of tests that passed -
duration_ms: Test execution duration in milliseconds -
error_message: Error message from the first failure -
timestamp: ISO 8601 timestamp
Example:
action:
type: "ai_prompt"
prompt_template: |
Tests failed:
Failed: {{failed_count}}
Passed: {{passed_count}}
Error: {{error_message}}
Suggest fixes.Available variables:
-
generated_files: Number of files generated -
total_lines: Total lines of code generated -
duration_ms: Generation duration in milliseconds -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Generated {{generated_files}} files ({{total_lines}} lines)"Available variables:
-
build_status: Build status (success/failure) -
output_dir: Output directory path -
duration_ms: Build duration in milliseconds -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Build {{build_status}} in {{duration_ms}}ms"Available variables:
-
deployment_status: Deployment status (success/failure) -
environment: Deployment environment (production/staging/etc) -
version: Deployed version -
duration_ms: Deployment duration in milliseconds -
timestamp: ISO 8601 timestamp
Example:
action:
type: "command"
command: "echo"
args:
- "Deployed v{{version}} to {{environment}}"Parameter binding uses variable substitution to bind event context to tool parameters:
action:
type: "tool_call"
tool_name: "formatter"
tool_path: "/usr/local/bin/prettier"
parameters:
file_path: "{{file_path}}" # From event context
output_dir: "/tmp/formatted" # Literal value
style: "prettier" # Literal valueUse literal values directly:
parameters:
style: "prettier"
config: ".prettierrc.json"Use event context variables:
parameters:
file_path: "{{file_path}}"
old_hash: "{{old_hash}}"Mix literal text with variables:
parameters:
output_path: "{{file_path}}.formatted"
backup_path: "/tmp/backup-{{timestamp}}.bak"Variables are only available if the event provides them. Using an unavailable variable will result in an error.
Use ricecoder hooks inspect <hook-id> to see available variables for a hook's event:
$ ricecoder hooks inspect format-hook
Hook: format-hook
Event: file_modified
Available variables:
- file_path
- old_hash
- new_hash
- timestampIf a variable is not available in the event context:
- Error: Hook execution fails with clear error message
- Message: Indicates which variable is missing
- Resolution: Update hook to use available variables
Example Error:
Error: Variable "file_size" not available in event context
Available variables: file_path, old_hash, new_hash, timestamp
Special characters in variables are automatically escaped:
args:
- "{{file_path}}" # Automatically escaped for shellaction:
type: "command"
command: "echo"
args:
- "Processing: {{file_path}}"action:
type: "command"
command: "echo"
args:
- "Changed from {{old_hash}} to {{new_hash}}"action:
type: "command"
command: "echo"
args:
- "[{{timestamp}}] File modified: {{file_path}}"action:
type: "command"
command: "echo"
args:
- "Tests: {{passed_count}} passed, {{failed_count}} failed"action:
type: "tool_call"
tool_name: "formatter"
tool_path: "/usr/local/bin/prettier"
parameters:
file_path: "{{file_path}}"
output_dir: "/tmp/formatted"Problem: Variable like {{file_path}} is not being replaced.
Solutions:
- Verify variable name is correct (case-sensitive)
- Check event type provides the variable
- Use
ricecoder hooks inspectto see available variables - Verify variable syntax is correct:
{{variable_name}}
Problem: Hook fails with "variable not available" error.
Solutions:
- Check which variables are available for the event
- Use
ricecoder hooks inspectto see available variables - Update hook to use available variables
- See event documentation for available variables
Problem: Variable values contain special characters that break commands.
Solutions:
- Variables are automatically escaped for shell
- For tool parameters, use literal values for special characters
- Use quotes around variable substitutions if needed
- Hooks System Guide - Main hooks guide
- Hooks Configuration Guide - Configuration options
- Hooks Events Guide - Available events
- Hooks Actions Guide - Action types
- Troubleshooting Guide - General troubleshooting
Last updated: December 5, 2025