wezterm.on() function and can be used to extend WezTerm’s functionality.
Event System Architecture
WezTerm’s event system consists of three main categories:- GUI Events - Emitted by the GUI layer during application lifecycle
- Window Events - Emitted by window and pane operations
- Multiplexer (Mux) Events - Emitted by the multiplexer layer
Registering Event Handlers
Event handlers are registered using thewezterm.on() function:
Event Handler Parameters
Each event receives different parameters depending on its purpose. Common parameter types include:Represents the GUI window. Provides methods to manipulate window state, set status bars, and perform actions.
Represents a terminal pane. Provides access to pane content, user variables, and metadata.
Contains information about a tab including its title, active pane, and state.
The effective configuration for the window or event context.
Event Types
Synchronous vs Asynchronous Events
Synchronous Events execute on the main thread and must return quickly:format-tab-title- Must return immediately to avoid blocking the UImux-is-process-stateful- Quick decision on process stateaugment-command-palette- Returns additional palette entries
wezterm.run_child_process().
Asynchronous Events can perform longer-running operations:
gui-startup- Can spawn multiple windows and configure workspacesupdate-status- Can fetch remote data or perform computationswindow-resized- Can adjust configuration based on dimensions
Fire-and-Forget Events
Some events are informational and don’t expect a return value:bell- Notifies that a bell was rungwindow-focus-changed- Notifies of focus state changeswindow-config-reloaded- Notifies of configuration reload
Intercepting Events
Some events allow you to override default behavior by returning a value:open-uri- Returnfalseto prevent default URI openingnew-tab-button-click- Returnfalseto prevent default action
Example: Multi-Event Configuration
Here’s an example that uses multiple events together:Event Best Practices
Performance Considerations
- Keep synchronous events fast - Don’t perform heavy computations or I/O
- Avoid loops in config-reloaded - Only call
set_config_overrides()when values actually change - Cache expensive operations - Store results when possible instead of recalculating
Error Handling
Event Ordering
Some events fire in a specific order:mux-startup- First event when mux server startsgui-startup- When GUI starts (doesn’t fire forwezterm connect)gui-attached- After attaching to a domain
Common Patterns
Workspace-Specific Configuration
Dynamic Color Schemes
Custom URI Handlers
See Also
- GUI Events - Application lifecycle events
- Window Events - Window and pane events
- Mux Events - Multiplexer events
- wezterm Module - Core API functions including event registration