# tmux_hook:set/3

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/d1b6308440cf9eb8f6647e7ae434bce60e849368/apps/libtmux_erlang/src/tmux_hook.erl#L99
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_hook-set-3/

```
set(Scope, Key, Commands)
-spec set(scope(),
          {binary(), non_neg_integer()},
          commands()) ->
             {ok, tmux_operation:completed()} |
             {error, tmux_operation:failure()}.
```

Replace one {Name, Index} entry with validated command values. An explicit index is required; other entries remain. Indexes range from zero to 2147483647. The rendered command text is bounded before dispatch. Native commands still interpret their arguments and formats when the hook later runs. Use `append/3` for native vacant-index selection and `clear/2` to mask inherited hooks with an empty local array.

Performs I/O. tmux parses commands before replacing an existing entry, but a
failed first write can already create an empty local override. Registration
and later execution are separate; this call promises no transaction, rollback
or completion of future effects.

## Parameters

- `Scope` (`scope()`)
- `Key` (`{binary(), non_neg_integer()}`)
- `Commands` (`commands()`)

## tmux command

The tmux commands behind `set/3`.

- [`set-hook`](/en/tmux/latest/manual/set-hook/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_set_hook_entry`](/en/tmux/latest/reference/c-variable-cmd_set_hook_entry/) (attribute)
- [`cmd_set_option_exec`](/en/tmux/latest/reference/c-function-cmd-set-option-c-cmd_set_option_exec/) (function)

## Guides

Pages that discuss `set/3`.

- [Register a hook and await its effect](/en/erlang/latest/guides/hooks/)
- [Read and change scoped options](/en/erlang/latest/guides/options/)
