# LibTmux::Server::set_hook

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** Perl
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-perl/blob/352715a4fa66a96eed7763b90daaa536aa2f121d/packages/core/lib/LibTmux/Server.pm#L1094
- **Page:** https://libtmux.org/en/perl/latest/reference/libtmux-server-set_hook/

```
sub set_hook($self, %args)
```

`set_hook(name => hook_or_hook[index], command => explicit_tmux_command_string, target => session_id?, global => boolean?)`.

Set a native hook or sparse hook[index] entry for an explicit session target or global scope. command is deliberately a tmux command string, unlike literal process argv. [`"show_hooks"`](/en/perl/latest/reference/libtmux-server-show_hooks/) preserves native indexes/quoting rather than inventing a flattened hook list.

Returns `undef` after command acceptance. Performs I/O; failures propagate through [`LibTmux::X`](/en/perl/latest/reference/libtmux-x/). Captured objects are not modified.


```perl
    $server->set_hook(target => $session->id, name => 'after-select-window[3]', command => 'display-message hook');
```

## Methods

## Parameters

- `args`

## 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) |
| OCaml | [`Libtmux_unix.Client.set_hook`](/en/ocaml/latest/reference/libtmux_unix-client-set_hook/) (function) |

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) |
| OCaml | [`Libtmux_unix.Client.set_hook`](/en/ocaml/latest/reference/libtmux_unix-client-set_hook/) (function) |

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