Skip to main content

Scaffold Hooks

Scaffold hooks let you observe scaffold operations and state changes - perfect for monitoring scaffold health, tracking IPC messages, and debugging scaffold behavior.

Overview

Scaffold hooks provide 2 execution points:

Hook Registration

Decorator Syntax

Subscribe API

Scaffold Hook Context

Every scaffold hook receives a ScaffoldExecContext with:

Execution Flow

On Operation Complete Hook

Fires when scaffold @operation completes:

On State Change Hook

Fires when scaffold state changes (via agent.state.set()):

Usage Patterns

Pattern 1: Operation Performance Monitoring

Track operation execution times and results:

Pattern 2: IPC Message Tracking

Monitor inter-scaffold communication via state changes:

Pattern 3: Scaffold Health Monitoring

Monitor scaffold operations for errors:

Pattern 4: State Change Auditing

Audit all scaffold state changes for compliance:

Pattern 5: Operation Result Validation

Validate operation results meet requirements:

Pattern 6: Scaffold Debugging

Debug scaffold behavior with detailed logging:

Integration with Scaffold IPC

Scaffold hooks are essential for monitoring IPC communication:

Best Practices

Performance Considerations

  • Hook overhead: Less than 2ms per scaffold hook
  • State change frequency: Can be high in IPC-heavy systems
  • Operation tracking: Minimal impact on scaffold performance
  • Async support: Scaffold hooks can be async functions

Integration with Agent State

Scaffold hooks have full access to agent state:

Error Handling

Errors in scaffold hooks don’t stop scaffold operations:

What’s Next?

Creating Scaffolds

Learn to build custom scaffolds

Scaffold IPC

Inter-scaffold communication

Subscribe API

Dynamic hook registration

Tool Hooks

Tool execution lifecycle hooks