# Libtmux_eio.Client.set_hook

- **Module:** Libtmux_eio
- **Package:** libtmux-eio
- **Language:** OCaml
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-ocaml/blob/205dfda49742592b479247049d186956e4a4cfe9/eio/libtmux_eio.mli#L378
- **Public owner:** Libtmux_eio
- **Page:** https://libtmux.org/en/ocaml/latest/reference/libtmux_eio-client-set_hook/

```
val set_hook :
  ?index:int ->
  ?append:bool ->
  t ->
  Libtmux.Options.scope ->
  name:string -> Libtmux.Hook.command list -> (unit, Libtmux.Error.t) result
```

Set a hook to a nonempty command list. Without an index, replace the whole hook array, or fill the lowest free index when appending. An explicit `@name` custom hook stores command text as a user option; it requires complete replacement and has no array indexes. `read_hook` returns its `Libtmux.Options.Text` value; bulk hook capture includes built-ins. Commands may cause arbitrary tmux effects when triggered. Hooks that print output are outside the supported control transport contract.

## Parameters

- `index?` (`int`)
- `append?` (`bool`)
- `arg1` (`t`)
- `arg2` (`Libtmux.Options.scope`)
- `name` (`string`)
- `arg3` (`Libtmux.Hook.command list`)

## tmux command

The tmux commands behind `set_hook`.

- [`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)

## tmux hooks

Events that run tmux commands, with the scope each hook belongs to and where tmux fires it.

- [Hooks](/en/tmux/latest/catalog/hooks/) (hook)

## In other ports

Bind a command to a global hook

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Server.set_hook`](/en/py/latest/reference/libtmux-server-set_hook/) (method) |
| Lua | [`libtmux.Server:set_hook`](/en/lua/latest/reference/libtmux-server-set_hook/) (method) |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | [`server.Server.setHook`](/en/ts/latest/reference/server-server-sethook/) (method) |
| Rust | [`server.Server.set_hook`](/en/rs/latest/reference/server-server-set_hook/) (method) |
| Go | no equivalent on `Server` |
| Java | reached through `Server.hooks`, whose `Hooks` carries the write |
| C# | reached through `Server.Hooks`, whose `TmuxHooks` carries the write |
| C++ | no equivalent on `Server` |
| Swift | [`Server.setHook(_:to:at:in:)`](/en/swift/latest/reference/server-sethook(_-to-at-in-)/) (method) |
| Perl | [`LibTmux::Server::set_hook`](/en/perl/latest/reference/libtmux-server-set_hook/) (method). Use global => true; command is an explicit native tmux command string. |

No equivalent is recorded in Ruby, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Bind a command to a session hook

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Session.set_hook`](/en/py/latest/reference/libtmux-session-set_hook/) (method) |
| Lua | [`libtmux.Session:set_hook`](/en/lua/latest/reference/libtmux-session-set_hook/) (method) |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | [`session.Session.setHook`](/en/ts/latest/reference/session-session-sethook/) (method) |
| Rust | [`session.Session.set_hook`](/en/rs/latest/reference/session-session-set_hook/) (method) |
| Go | [`tmux.Session.SetHook`](/en/go/latest/reference/tmux-session-sethook/) (method) |
| Java | reached through `Session.hooks`, whose `Hooks` carries the write |
| C# | reached through `Session.Hooks`, whose `TmuxHooks` carries the write |
| C++ | [`libtmux::Session::set_hook`](/en/cxx/latest/reference/libtmux-session-set_hook/) (method) |
| Swift | [`Server.setHook(_:to:at:in:)`](/en/swift/latest/reference/server-sethook(_-to-at-in-)/) (method) |
| Perl | [`LibTmux::Server::set_hook`](/en/perl/latest/reference/libtmux-server-set_hook/) (method). Use an explicit session target ID; command is an explicit native tmux command string. |

No equivalent is recorded in Ruby, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Bind a command to a window hook

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Window.set_hook`](/en/py/latest/reference/libtmux-window-set_hook/) (method) |
| Lua | [`libtmux.Window:set_hook`](/en/lua/latest/reference/libtmux-window-set_hook/) (method) |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | [`window.Window.setHook`](/en/ts/latest/reference/window-window-sethook/) (method) |
| Rust | [`window.Window.set_hook`](/en/rs/latest/reference/window-window-set_hook/) (method) |
| Go | [`tmux.Window.SetHook`](/en/go/latest/reference/tmux-window-sethook/) (method) |
| Java | reached through `Window.hooks`, whose `Hooks` carries the write |
| C# | reached through `Window.Hooks`, whose `TmuxHooks` carries the write |
| C++ | no equivalent on `Window` |
| Swift | [`Server.setHook(_:to:at:in:)`](/en/swift/latest/reference/server-sethook(_-to-at-in-)/) (method) |
| Perl | No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands. |

No equivalent is recorded in Ruby, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Bind a command to a pane hook

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Pane.set_hook`](/en/py/latest/reference/libtmux-pane-set_hook/) (method) |
| Lua | [`libtmux.Pane:set_hook`](/en/lua/latest/reference/libtmux-pane-set_hook/) (method) |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | [`pane.Pane.setHook`](/en/ts/latest/reference/pane-pane-sethook/) (method) |
| Rust | [`pane.Pane.set_hook`](/en/rs/latest/reference/pane-pane-set_hook/) (method) |
| Go | [`tmux.Pane.SetHook`](/en/go/latest/reference/tmux-pane-sethook/) (method) |
| Java | reached through `Pane.hooks`, whose `Hooks` carries the write |
| C# | reached through `Pane.Hooks`, whose `TmuxHooks` carries the write |
| C++ | no equivalent on `Pane` |
| Swift | [`Server.setHook(_:to:at:in:)`](/en/swift/latest/reference/server-sethook(_-to-at-in-)/) (method) |
| Perl | No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands. |

No equivalent is recorded in Ruby, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.
