# LibTmux.Program

- **Package:** libtmux-haskell
- **Language:** Haskell
- **Kind:** module
- **Source:** https://github.com/libtmux/libtmux-haskell/blob/72edb54317bf619c6dc54bff311844f062f8984c/src/LibTmux/Program.hs
- **Page:** https://libtmux.org/en/haskell/latest/reference/libtmux-program/

Run terminal applications through an owned scope. Use
 [`withProgram`](/en/haskell/latest/reference/libtmux-server-v-withprogram/) for an interactive handle or
 [`runProgram`](/en/haskell/latest/reference/libtmux-server-v-runprogram/) for a final result. These operations borrow the
 selected daemon and own only their new session, application process group,
 native command clients, pin, buffers and files.

A scope sends TERM, waits up to 100ms for leader exit, then sends group KILL
 through a retained Linux pidfd.
 Completed cleanup proves leader exit and an empty retained process group.
 Zombies or uninterruptible members may leave a reachable cleanup recovery.
 Processes that move to another process group/session escape this contract.
 Linux 6.9 process-group pidfd signaling and a local daemon in the same PID
 and filesystem namespaces are required. The selected [`bootstrapShell`](/en/haskell/latest/reference/libtmux-program-v-programoptions-bootstrapshell/) must
 provide Bash dynamic descriptors, timed reads and execfail. It defaults to
 `/bin/bash` and is probed before application creation. The gate has a
 separate one-second startup lease; [`commandTimeout`](/en/haskell/latest/reference/libtmux-program-v-programoptions-commandtimeout/) bounds each native
 command. Neither bounds whole startup: [`executionTimeout`](/en/haskell/latest/reference/libtmux-program-v-programoptions-executiontimeout/) bounds owning
 setup and the callback. Cleanup wakes a blocked gate with an abort claim;
 the descriptor closes before application exec.
 The host operation and tmux 3.8 capability are checked before application
 resources are created.

Output is a bounded rendered snapshot, not stdout/stderr byte streaming.
 Controller-process crash recovery, persistent leases, readiness predicates,
 keep/detach and MCP operations remain unimplemented. Use the scope while its
 callback runs; detached [`ProgramResult`](/en/haskell/latest/reference/libtmux-program-t-programresult/) values survive cleanup.

## Members

### Common operations

- [`inspectProgramCleanup`](/en/haskell/latest/reference/libtmux-program-v-inspectprogramcleanup/) (function): Inspect local ownership without contacting tmux or waiting.
- [`Program`](/en/haskell/latest/reference/libtmux-program-t-program/) (data type): An interactive owner, valid only inside its withProgram callback. The
 borrowed Server may close independently; incomplete cleanup retains its own
 pin and Runtime through :obj:`ProgramRecovery <LibTmux.Program#t:ProgramRecovery>`.
- [`programCleanupFailure`](/en/haskell/latest/reference/libtmux-program-v-programcleanupfailure/) (function): The failure from the cleanup attempt that attached this owner. The
 original callback exception remains the thrown exception.
- [`ProgramOptions`](/en/haskell/latest/reference/libtmux-program-t-programoptions/) (data type): A literal executable and its arguments. The record has no Show instance:
 command and environment values may contain credentials. The working
 directory defaults to the caller's directory; environment values override
 the daemon's inherited application environment. Start from :obj:`programOptions <LibTmux.Program#v:programOptions>`.
- [`programRecoveries`](/en/haskell/latest/reference/libtmux-program-v-programrecoveries/) (function): Retrieve owners from an exception caught with its exception context.
- [`ProgramRecovery`](/en/haskell/latest/reference/libtmux-program-t-programrecovery/) (data type): Reachable cleanup ownership, including a live pin, native Runtime and
 identity-bound application group. Resume does not run the application again.
- [`ProgramResult`](/en/haskell/latest/reference/libtmux-program-t-programresult/) (data type): Detached final output and process status, usable after all scopes close.
- [`readProgramScreen`](/en/haskell/latest/reference/libtmux-program-v-readprogramscreen/) (function): Capture the current rendered terminal. Limits are configured before launch;
 the result reports clipped bytes and possible history loss explicitly. An
 external resize refuses capture before allocation; cleanup remains available.
- [`resumeProgramCleanup`](/en/haskell/latest/reference/libtmux-program-v-resumeprogramcleanup/) (function): Retry cleanup through its retained pin, including after the borrowing
 Server scope ends. Application launch and input are never repeated.
- [`sendProgramInput`](/en/haskell/latest/reference/libtmux-program-v-sendprograminput/) (function): Send literal bytes to the real application PTY. A call admits at most
 1024 bytes, including NUL; terminal line discipline still applies. Sending
 bytes is not evidence that the application consumed them.
- [`terminateProgram`](/en/haskell/latest/reference/libtmux-program-v-terminateprogram/) (function): Request TERM, wait up to 100ms for leader exit, then send KILL to the retained
 process-group identity. Descendants that move to another group/session are
 outside this ownership contract. The returned outcome belongs to the leader.
- [`waitProgram`](/en/haskell/latest/reference/libtmux-program-v-waitprogram/) (function): Observe the real process exit and tmux's final PTY drain. Cancelling this
 observation leaves the owning scope and application running. A destroyed
 pane or lost daemon raises an observation error instead of inventing an exit.
- [`waitProgramFor`](/en/haskell/latest/reference/libtmux-program-v-waitprogramfor/) (function): Bound only this observation. Nothing means the deadline elapsed; it does
 not terminate the application. Async cancellation also leaves it running.

### Other members

- [`ProgramCleanupStatus`](/en/haskell/latest/reference/libtmux-program-t-programcleanupstatus/) (data type): Nonblocking cleanup metadata, without application arguments or output.
- [`ProgramError`](/en/haskell/latest/reference/libtmux-program-t-programerror/) (data type): Program-specific failures. Existing native command failures also retain
 their ordinary correlated recovery. Async exceptions keep their class.
- [`ProgramExit`](/en/haskell/latest/reference/libtmux-program-t-programexit/) (data type): The pane's actual process outcome. A signal is never encoded as 128+signal.
 Successful creation and bootstrap release do not establish successful exec.
- [`programOptions`](/en/haskell/latest/reference/libtmux-program-v-programoptions-pvb1/) (function): Default terminal, bounded history and output, with a literal argv tail.
 An empty tail executes a zero-argument application without tmux shell mode.
- [`ProgramScreen`](/en/haskell/latest/reference/libtmux-program-t-programscreen/) (data type): A rendered terminal snapshot, including retained history. This is not a
 byte stream or a separation of stdout and stderr. Newlines and terminal
 editing follow capture-pane. Byte omission is exact for this snapshot;
 history omission is reported separately.
- [`StartFailure`](/en/haskell/latest/reference/libtmux-program-t-startfailure/) (data type): Setup failed before replacing the bootstrap with the requested executable.
- [`StartPhase`](/en/haskell/latest/reference/libtmux-program-t-startphase/) (data type): Strict application setup, independent of tmux's cwd fallback.

## Referenced by

- [`LibTmux`](/en/haskell/latest/reference/libtmux/) (module)
- [`LibTmux.Recovery`](/en/haskell/latest/reference/libtmux-recovery/) (module)

## Guides

Pages that discuss `LibTmux.Program`.

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