# libtmux._internal.constants.Hooks

- **Module:** libtmux._internal.constants
- **Package:** libtmux
- **Language:** Python
- **Kind:** class
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/_internal/constants.py#L633
- **Page:** https://libtmux.org/reference/py/libtmux-_internal-constants-hooks/

tmux hooks data structure.

Parses tmux hook output into typed :class:`SparseArray` fields, preserving
array indices for hooks that can have multiple commands at different indices.
A field holds an empty :class:`SparseArray` when tmux reports no commands
for that hook.

## Example

Parse raw tmux hook output:

```python
>>> from libtmux._internal.constants import Hooks
```

## Example

```python
>>> raw = [
...     "session-renamed[0] set-option -g status-left-style bg=red",
...     "session-renamed[1] display-message 'session renamed'",
... ]
>>> hooks = Hooks.from_stdout(raw)
```

## Example

Access individual hook commands by index:

```python
>>> hooks.session_renamed[0]
'set-option -g status-left-style bg=red'
>>> hooks.session_renamed[1]
"display-message 'session renamed'"
```

## Example

Get all commands as a list (sorted by index):

```python
>>> hooks.session_renamed.as_list()
['set-option -g status-left-style bg=red', "display-message 'session renamed'"]
```

## Example

Sparse indices are preserved (gaps in index numbers):

```python
>>> raw_sparse = [
...     "pane-focus-in[0] refresh-client",
...     "pane-focus-in[5] display-message 'focus'",
... ]
>>> hooks_sparse = Hooks.from_stdout(raw_sparse)
>>> 0 in hooks_sparse.pane_focus_in
True
>>> 5 in hooks_sparse.pane_focus_in
True
>>> 3 in hooks_sparse.pane_focus_in
False
>>> sorted(hooks_sparse.pane_focus_in.keys())
[0, 5]
```

## Example

Iterate over values in index order:

```python
>>> for cmd in hooks_sparse.pane_focus_in.iter_values():
...     print(cmd)
refresh-client
display-message 'focus'
```

## Example

Multiple hook types in one parse:

```python
>>> raw_multi = [
...     "after-new-window[0] select-pane -t 0",
...     "after-new-window[1] send-keys 'clear' Enter",
...     "window-renamed[0] refresh-client -S",
... ]
>>> hooks_multi = Hooks.from_stdout(raw_multi)
>>> len(hooks_multi.after_new_window)
2
>>> len(hooks_multi.window_renamed)
1
```

## Members

- `alert_activity` (attribute)
- `alert_bell` (attribute)
- `alert_silence` (attribute)
- `client_active` (attribute)
- `client_attached` (attribute)
- `client_detached` (attribute)
- `client_focus_in` (attribute)
- `client_focus_out` (attribute)
- `client_resized` (attribute)
- `client_session_changed` (attribute)
- `pane_died` (attribute)
- `pane_exited` (attribute)
- `pane_focus_in` (attribute)
- `pane_focus_out` (attribute)
- `pane_set_clipboard` (attribute)
- `session_created` (attribute)
- `session_closed` (attribute)
- `session_renamed` (attribute)
- `window_linked` (attribute)
- `window_renamed` (attribute)
- `window_resized` (attribute)
- `window_unlinked` (attribute)
- `pane_title_changed` (attribute)
- `client_light_theme` (attribute)
- `client_dark_theme` (attribute)
- `client_detached_control` (attribute)
- `client_session_changed_control` (attribute)
- `config_error` (attribute)
- `continue_control` (attribute)
- `exit_control` (attribute)
- `extended_output` (attribute)
- `layout_change` (attribute)
- `message_control` (attribute)
- `output` (attribute)
- `pane_mode_changed` (attribute)
- `paste_buffer_changed` (attribute)
- `paste_buffer_deleted` (attribute)
- `pause_control` (attribute)
- `session_changed_control` (attribute)
- `session_renamed_control` (attribute)
- `session_window_changed` (attribute)
- `sessions_changed` (attribute)
- `subscription_changed` (attribute)
- `unlinked_window_add` (attribute)
- `unlinked_window_close` (attribute)
- `unlinked_window_renamed` (attribute)
- `window_add` (attribute)
- `window_close` (attribute)
- `window_layout_changed` (attribute)
- `window_pane_changed` (attribute)
- `window_renamed_control` (attribute)
- `after_bind_key` (attribute)
- `after_capture_pane` (attribute)
- `after_copy_mode` (attribute)
- `after_display_message` (attribute)
- `after_display_panes` (attribute)
- `after_kill_pane` (attribute)
- `after_list_buffers` (attribute)
- `after_list_clients` (attribute)
- `after_list_keys` (attribute)
- `after_list_panes` (attribute)
- `after_list_sessions` (attribute)
- `after_list_windows` (attribute)
- `after_load_buffer` (attribute)
- `after_lock_server` (attribute)
- `after_new_session` (attribute)
- `after_new_window` (attribute)
- `after_paste_buffer` (attribute)
- `after_pipe_pane` (attribute)
- `after_queue` (attribute)
- `after_refresh_client` (attribute)
- `after_rename_session` (attribute)
- `after_rename_window` (attribute)
- `after_resize_pane` (attribute)
- `after_resize_window` (attribute)
- `after_save_buffer` (attribute)
- `after_select_layout` (attribute)
- `after_select_pane` (attribute)
- `after_select_window` (attribute)
- `after_send_keys` (attribute)
- `after_set_buffer` (attribute)
- `after_set_environment` (attribute)
- `after_set_hook` (attribute)
- `after_set_option` (attribute)
- `after_show_environment` (attribute)
- `after_show_messages` (attribute)
- `after_show_options` (attribute)
- `after_split_window` (attribute)
- `after_unbind_key` (attribute)
- `command_error` (attribute)
- `from_stdout` (method) — Parse raw tmux hook output into a Hooks instance.
- `__repr__` (method) — Omit default fields in object representation.
