# tmux_hook:run/2

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

```
run(Context, Name0)
-spec run(context(), binary()) ->
             {ok, tmux_operation:completed()} |
             {error, tmux_operation:failure()}.
```

Request native [set-hook](/en/tmux/latest/manual/set-hook/) -R in the explicit `t:context/0`. tmux resolves the hook through that context's effective tables; global table flags do not select a separate execution scope. A session uses its current window and pane. A window link fixes the observed session/index and expected physical window; a pane context additionally checks that pane's observed parent.

Performs I/O. The result is the native command outcome, not an acknowledgement
of background work launched by its commands. A missing or empty effective hook
can succeed without effects. Wait on an application completion condition when
effects matter. Existence and membership checks precede dispatch. If the
target disappears after preflight, tmux can still fall back to another
context. This is not atomic compare-and-act. Use fresh links after known
topology changes.

## Parameters

- `Context` (`context()`)
- `Name0` (`binary()`)

## tmux command

The tmux commands behind `run/2`.

- [`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 `run/2`.

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