# tmux capture-pane

Source: https://libtmux.org/en/tmux/3.7c/manual/capture-pane/

> Capture the contents of a pane.

Capture the contents of a pane.

## Common uses

Run these commands inside tmux, in the pane you want to capture. TMUX_PANE identifies that pane.

Print the visible pane

```tmux-shell
tmux capture-pane -p -t "$TMUX_PANE"
```

Include up to 1,000 history lines and join wrapped lines

```tmux-shell
tmux capture-pane -p -J -S -1000 -t "$TMUX_PANE"
```

## Syntax

```tmux-usage
tmux capture-pane [-aCeFHJLMNpPqT] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]
```

Alias: `capturep`.

## Options

### Output and line range

* [`-p`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-output-and-line-range-p)

  Print to standard output. Without this flag, tmux saves the capture in a paste buffer.

* [`-b name`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-output-and-line-range-b)

  Choose the paste buffer when -p is omitted. Without -b, tmux creates a new buffer.

* [`-t pane`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-output-and-line-range-t)

  Choose the pane to capture. Inside tmux, "$TMUX_PANE" identifies the current pane.

* [`-S start`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-output-and-line-range-s)

  First line to capture. Zero is the first visible line; negative numbers reach into history. Use - for the start of history.

* [`-E end`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-output-and-line-range-e)

  Last line to capture. Use a line number, or - for the end of the visible pane. By default, capture only the visible pane.

### Text formatting

* [`-J`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-j)

  Join wrapped lines and preserve trailing spaces. Implies -T.

* [`-e`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-e)

  Keep escape sequences for text attributes and colors.

* [`-C`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-c)

  Escape non-printable characters as octal \xxx sequences.

* [`-N`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-n)

  Preserve trailing spaces at the end of each line.

* [`-T`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-t)

  Ignore trailing positions that contain no character.

* [`-H`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-h)

  Capture only hyperlink targets, separated by spaces when a line contains several.

* [`-L`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-l)

  Prefix each line with its line number.

* [`-F`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-text-formatting-f)

  Prefix each line with its flags: - none, D unused, O output, P prompt, X extended cells, H hyperlinks.

### Screens and pending output

* [`-a`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-screens-and-pending-output-a)

  Capture the alternate screen instead of the normal screen. History is unavailable. Fails if no alternate screen exists.

* [`-q`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-screens-and-pending-output-q)

  With -a, suppress the error when no alternate screen exists.

* [`-M`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-screens-and-pending-output-m)

  Capture the mode screen, such as copy mode, when the pane is in a mode.

* [`-P`](https://libtmux.org/en/tmux/3.7c/manual/capture-pane/#capture-pane-options-screens-and-pending-output-p)

  Capture a received but incomplete escape sequence, rather than the pane contents.

Original manual wording

Capture the contents of a pane. If `-p` is given, the output goes to stdout, otherwise to the buffer specified with `-b` or a new buffer if omitted. If `-a` is given, the alternate screen is used, and the history is not accessible. If no alternate screen exists, an error will be returned unless `-q` is given. Similarly, if the pane is in a mode, `-M` uses the screen for the mode. If `-e` is given, the output includes escape sequences for text and background attributes. `-C` also escapes non-printable characters as octal \xxx. `-T` ignores trailing positions that do not contain a character. `-N` preserves trailing spaces at each line's end and `-J` preserves trailing spaces and joins any wrapped lines; `-J` implies `-T`. `-P` captures only any output that the pane has received that is the beginning of an as-yet incomplete escape sequence. `-L` includes the line number at the start of each line and `-F` includes the flags (where ‘`-`’ is no flags, ‘`D`’ is an unused line, ‘`O`’ is a line marked as output, ‘`P`’ is a line marked as a prompt, ‘`X`’ is a line containing extended cells and ‘`H`’ is a line with hyperlinks). With `-H`, only hyperlinks in the specified lines are captured. Multiple hyperlinks on the same line are separated by spaces.

`-S` and `-E` specify the starting and ending line numbers, zero is the first line of the visible pane and negative numbers are lines in the history. ‘`-`’ to `-S` is the start of the history and to `-E` the end of the visible pane. The default is to capture only the visible contents of the pane.

## Guides

* [Capture pane output](https://libtmux.org/en/tmux/guides/capturing-output/)

## C implementation

Internal declarations in tmux 3.7c:

* [`cmd_capture_pane_entry`](https://libtmux.org/en/tmux/3.7c/reference/c-variable-cmd_capture_pane_entry/)
* [`cmd_capture_pane_exec`](https://libtmux.org/en/tmux/3.7c/reference/c-function-cmd-capture-pane-c-cmd_capture_pane_exec/)

## Use from a library

Each API describes its own defaults, errors and execution model.

* [Python](https://libtmux.org/en/py/latest/reference/libtmux-pane-capture_pane/)
* [TypeScript](https://libtmux.org/en/ts/latest/reference/pane-pane-capture/)
* [Rust](https://libtmux.org/en/rs/latest/reference/pane-pane-capture/)
* [Go](https://libtmux.org/en/go/latest/reference/tmux-pane-capture/)
* [Java](https://libtmux.org/en/java/latest/reference/io-github-libtmux-pane-pane-capture/)
* [Kotlin](https://libtmux.org/en/kotlin/latest/reference/io-github-libtmux-kotlin-pane-capture/)
* [Scala](https://libtmux.org/en/scala/latest/reference/io-github-libtmux-scaladsl-pane-capture/)
* [F#](https://libtmux.org/en/fsharp/latest/reference/libtmux-fsharp-pane-capture/)
* [C#](https://libtmux.org/en/csharp/latest/reference/libtmux-pane-captureasync/)
* [C++](https://libtmux.org/en/cxx/latest/reference/libtmux-pane-capture/)
* [Swift](https://libtmux.org/en/swift/latest/reference/server-capture\(_-includinghistory-\)/)
* [Ruby](https://libtmux.org/en/ruby/latest/reference/libtmux-pane-capture/)
* [Lua](https://libtmux.org/en/lua/latest/reference/libtmux-pane-capture/)

tmux sources and license

Syntax comes from `tmux 3.7c list-commands`. See the [global options](https://libtmux.org/en/tmux/3.7c/manual/full/#DESCRIPTION) for sockets and configuration, and [command syntax and targets](https://libtmux.org/en/tmux/3.7c/manual/full/#COMMANDS).

Behavior is taken from the [tmux 3.7c manual](https://github.com/tmux/tmux/blob/79072dd1a9f5fb437a5859e362a496fd57ec0981/tmux.1).

[Command declaration](https://github.com/tmux/tmux/blob/79072dd1a9f5fb437a5859e362a496fd57ec0981/cmd-capture-pane.c#L42)

```
Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```
