# pane.Pane.waitForExit

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

```
waitForExit(
  options?: ProgramWaitOptions,
): Promise<ProgramExit>
```

Resolve with how this pane's program ended, whoever started it.

At once for a pane already dead under [`remain-on-exit`](/en/tmux/latest/catalog/options/remain-on-exit/); otherwise when
tmux reports the exit, with the status a closing pane takes with it.
A signal that ended the pane's process shows as [`signalCode`](/en/ts/latest/reference/types-programexit-signalcode/) with `exitCode`
null.
Giving up leaves the program running: a timeout throws
[`WaitTimeoutError`](/en/ts/latest/reference/errors-waittimeouterror/) and an abort throws [`TmuxTransportError`](/en/ts/latest/reference/errors-tmuxtransporterror/) of
kind `cancelled`; with neither it waits as long as the program runs. A
pane killed from outside, which fires no event, raises
[`ObjectNotFoundError`](/en/ts/latest/reference/errors-objectnotfounderror/) within about two seconds of the kill. A read every
second notices the pane gone, and the wait gives the event a closing pane
fires up to a second to arrive.

Requires tmux 3.8 or newer.

## Examples

```ts
const build = await window.split({ shellCommand: "sleep 1; exit 3" });
const exit = await build.waitForExit({ timeoutMs: 10_000 });
exit.exitCode; // 3
```

## Parameters

- `options?` (`ProgramWaitOptions`)

## tmux command

The tmux commands behind `waitForExit`.

- [`wait-for`](/en/tmux/latest/manual/wait-for/)

## tmux C API

The C declarations in tmux that implement these commands.

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