# tmux_pane:wait_exit/2

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/38478dff54579a4f408005d0265031abdf3a880a/apps/libtmux_erlang/src/tmux_pane.erl#L308
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_pane-wait_exit-2/

```
wait_exit(Pane, Options)
-spec wait_exit(tmux_model:pane(), wait_exit_options()) ->
                   {ok, wait_exit_result()} |
                   {error, map()}.
```

Wait for a retained pane's process. Return its native status or signal (`t:exit/0`) and a fresh pane row. Set [`remain-on-exit`](/en/tmux/latest/catalog/options/remain-on-exit/) to `on` before starting a job whose exit you need. A live pane with another setting returns `remain_on_exit_required`.

A live wait binds the process and pins its PTY allocation. The owner
holds that pin through the final read without consuming terminal bytes.
Respawn returns `stale_pane` and replacement of the daemon returns
`stale_server`. An exit already published at the first read is a current
observation. The fast path has no live-generation pin.

On tmux 3.8, the wait uses a filtered native [`pane-died`](/en/tmux/latest/catalog/hooks/pane-died/) event. On older
supported daemons, it registers a private indexed hook and channel.
Both paths recheck native state before acting on an exit notification.
Keep the endpoint open through cleanup. The supervised owner retires the
wait client when the call ends or its caller dies. A native unset failure
can leave a legacy hook installed.

`deadline_ms` bounds the native wait, starting after the initial
observation. Setup readiness and cleanup waits each have a 900 ms limit.
State probes and final capture each use their own 2,500 ms command budget.
Client retirement can add its cleanup allowance.

- `deadline` means the wait reached its bound. A still-running pane can
  be waited on again.
- `exit_status_unavailable` means the original process exited and tmux
  has yet to publish a native status or signal.
- `pane_generation_unavailable` means the wait could not bind its
  original process and terminal.
- `target_gone` means the pane disappeared.

See [pane-exit errors](diagnostics.md#read-a-pane-exit-error) for remedies.
To capture a job's final screen, use the [job guide](jobs.md) pattern that
acknowledges terminal parsing before exit.

Invalid options fail before I/O.

## Parameters

- `Pane` (`tmux_model:pane()`)
- `Options` (`wait_exit_options()`)

## Examples

```erlang
1> tmux_pane:wait_exit(invalid_row, #{deadline_ms => 0}).
{error,#{code => invalid_option,path => [deadline_ms]}}
```

## tmux command

The tmux commands behind `wait_exit/2`.

- [`display-message`](/en/tmux/latest/manual/display-message/)
- [`set-hook`](/en/tmux/latest/manual/set-hook/)

## tmux C API

The C declarations in tmux that implement these commands.

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

## Guides

Pages that discuss `wait_exit/2`.

- [Support and remaining gaps](/en/erlang/latest/guides/compatibility/)
- [Owned operations](/en/erlang/latest/guides/operations/)
