# libtmux.Session.set_hooks

- **Module:** libtmux.Session
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/hooks.py#L437
- **Page:** https://libtmux.org/reference/py/libtmux-session-set_hooks/

```
libtmux.Session.set_hooks(self, hook: str, values: HookValues, clear_existing: bool = False, global_: bool | None = None, scope: OptionScope | _DefaultOptionScope | None = DEFAULT_OPTION_SCOPE) -> Self
```

Set multiple indexed hooks at once.

## Parameters

- `self`
- `hook` (str) — Hook name, e.g. 'session-renamed'
- `values` (HookValues) — Values to set. Can be:
- dict[int, str]: {0: 'cmd1', 1: 'cmd2'} - explicit indices
- SparseArray[str]: preserves indices from another hook
- list[str]: ['cmd1', 'cmd2'] - sequential indices starting at 0
- `clear_existing` (bool) — If True, unset all existing hook values first
- `global_` (bool | None) — Use global hooks
- `scope` (OptionScope | _DefaultOptionScope | None) — Scope for the hook

## Returns

Self
    Returns self for method chaining.

## Example

Set hooks with explicit indices:

```python
>>> session.set_hooks('session-renamed', {
...     0: 'display-message "hook 0"',
...     1: 'display-message "hook 1"',
... })
Session($...)
```

## Example

```python
>>> hooks = session.show_hook('session-renamed')
>>> sorted(hooks.keys())
[0, 1]
```

## Example

```python
>>> session.unset_hook('session-renamed')
Session($...)
```

## Example

Set hooks from a list (sequential indices):

```python
>>> session.set_hooks('after-new-window', [
...     'select-pane -t 0',
...     'send-keys "clear" Enter',
... ])
Session($...)
```

## Example

```python
>>> hooks = session.show_hook('after-new-window')
>>> sorted(hooks.keys())
[0, 1]
```

## Example

Replace all existing hooks with ``clear_existing=True``:

```python
>>> session.set_hooks(
...     'session-renamed',
...     {0: 'display-message "new"'},
...     clear_existing=True,
... )
Session($...)
```

## Example

```python
>>> hooks = session.show_hook('session-renamed')
>>> sorted(hooks.keys())
[0]
```

## Example

```python
>>> session.unset_hook('session-renamed')
Session($...)
```

## Example

```python
>>> session.unset_hook('after-new-window')
Session($...)
```
