# server.Server.setHook

- **Module:** server
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ts/blob/073b9d7dedad900bff6f5ec0ea47794e40225870/packages/libtmux/src/server.ts#L1136
- **Page:** https://libtmux.org/en/ts/latest/reference/server-server-sethook/

```
setHook(
  name: string,
  command: string,
  options?: SetHookOptions,
): Promise<void>
```

Bind a tmux command to a global hook.

A hook holds a list of commands. Without `append` this writes the whole
list, so it replaces whatever the hook already ran.

## Examples

```ts
await server.setHook("session-created", "display-message 'hello'");
await server.setHook("session-created", "display-message 'and this'", { append: true });
```

## Parameters

- `name` (`string`)
- `command` (`string`)
- `options?` (`SetHookOptions`)

## tmux command

The tmux commands behind `setHook`.

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

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