# LibTmux.Server.withProgram

- **Package:** libtmux-haskell
- **Language:** Haskell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-haskell/blob/72edb54317bf619c6dc54bff311844f062f8984c/src/LibTmux/Server.hs#L369
- **Page:** https://libtmux.org/en/haskell/latest/reference/libtmux-server-v-withprogram/

```haskell
withProgram
  :: Server -> ProgramOptions -> (Program -> IO a) -> IO a
```

Signature types: [`Server`](/en/haskell/latest/reference/libtmux-server-t-server/), [`ProgramOptions`](/en/haskell/latest/reference/libtmux-program-t-programoptions/), [`Program`](/en/haskell/latest/reference/libtmux-program-t-program/), [`IO`](https://hackage.haskell.org/package/base-4.22.0.0/docs/Prelude.html#t:IO).

Run a literal executable/argv application in a new owned session on this
 daemon, then terminate its group and remove its resources. The callback may
 send input and observe bounded rendered output. Cancellation of this owning
 scope initiates bounded cleanup; cancellation of [`waitProgram`](/en/haskell/latest/reference/libtmux-program-v-waitprogram/)
 alone does not. Async exceptions retain their original class.

tmux 3.8 and Linux 6.9 pidfd process-group signaling are required and checked
 before application effects. A separately owned pin and bounded native Runtime
 keep [`ProgramRecovery`](/en/haskell/latest/reference/libtmux-program-t-programrecovery/) usable after this Server closes. The
 borrowed daemon and its other sessions remain running. See [`LibTmux.Program`](/en/haskell/latest/reference/libtmux-program/)
 for the initial contract and explicit limits.

## Referenced declarations

- [`LibTmux.Program.Program`](/en/haskell/latest/reference/libtmux-program-t-program/) (data type)
- [`LibTmux.Program.ProgramOptions`](/en/haskell/latest/reference/libtmux-program-t-programoptions/) (data type)
- [`LibTmux.Server.Server`](/en/haskell/latest/reference/libtmux-server-t-server/) (data type)

## tmux command

The tmux commands behind `withProgram`.

- [`delete-buffer`](/en/tmux/latest/manual/delete-buffer/) (when a captured buffer remains owned)
- [`kill-session`](/en/tmux/latest/manual/kill-session/) (when the owned session still exists)
- [`new-session`](/en/tmux/latest/manual/new-session/)
- [`resize-window`](/en/tmux/latest/manual/resize-window/)
- [`set-option`](/en/tmux/latest/manual/set-option/)
- [`wait-for`](/en/tmux/latest/manual/wait-for/)
- [`display-message`](/en/tmux/latest/manual/display-message/)
- [`has-session`](/en/tmux/latest/manual/has-session/) (when an owned creation receipt was retained)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_delete_buffer_entry`](/en/tmux/latest/reference/c-variable-cmd_delete_buffer_entry/) (attribute)
- [`cmd_set_buffer_exec`](/en/tmux/latest/reference/c-function-cmd-set-buffer-c-cmd_set_buffer_exec/) (function)
- [`cmd_kill_session_entry`](/en/tmux/latest/reference/c-variable-cmd_kill_session_entry/) (attribute)
- [`cmd_kill_session_exec`](/en/tmux/latest/reference/c-function-cmd-kill-session-c-cmd_kill_session_exec/) (function)
- [`cmd_new_session_entry`](/en/tmux/latest/reference/c-variable-cmd_new_session_entry/) (attribute)
- [`cmd_new_session_exec`](/en/tmux/latest/reference/c-function-cmd-new-session-c-cmd_new_session_exec/) (function)
- [`cmd_resize_window_entry`](/en/tmux/latest/reference/c-variable-cmd_resize_window_entry/) (attribute)
- [`cmd_resize_window_exec`](/en/tmux/latest/reference/c-function-cmd-resize-window-c-cmd_resize_window_exec/) (function)
- [`cmd_set_option_entry`](/en/tmux/latest/reference/c-variable-cmd_set_option_entry/) (attribute)
- [`cmd_set_option_exec`](/en/tmux/latest/reference/c-function-cmd-set-option-c-cmd_set_option_exec/) (function)
- [`cmd_wait_for_entry`](/en/tmux/latest/reference/c-variable-cmd_wait_for_entry/) (attribute)
- [`cmd_wait_for_exec`](/en/tmux/latest/reference/c-function-cmd-wait-for-c-cmd_wait_for_exec/) (function)
- [`cmd_display_message_entry`](/en/tmux/latest/reference/c-variable-cmd_display_message_entry/) (attribute)
- [`cmd_display_message_exec`](/en/tmux/latest/reference/c-function-cmd-display-message-c-cmd_display_message_exec/) (function)
- [`cmd_has_session_entry`](/en/tmux/latest/reference/c-variable-cmd_has_session_entry/) (attribute)

Each path starts at a function a command runs, which is degree 1. The degree counts steps from there along the path, and each step is a call or a reference: degree 2 is reached from that function, degree 3 from the next, and so on.

### Create a session and its first pane

1. [`cmd_new_session_exec`](/en/tmux/latest/reference/c-function-cmd-new-session-c-cmd_new_session_exec/) (function)
2. calls → [`spawn_window`](/en/tmux/latest/reference/c-function-spawn_window/) (function)
3. calls → [`spawn_pane`](/en/tmux/latest/reference/c-function-spawn_pane/) (function)
4. calls → [`window_add_pane`](/en/tmux/latest/reference/c-function-window_add_pane/) (function)
5. calls → [`window_pane_create`](/en/tmux/latest/reference/c-function-window-c-window_pane_create/) (function)

## Guides

Pages that discuss `withProgram`.

### Core

- [tmux client library for Haskell](/en/haskell/latest/core/)

### Guides

- [Run terminal applications](/en/haskell/latest/guides/programs/)
