# libtmux.Pane.capture_pane

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/pane.py#L473
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-pane-capture_pane/

tmux command: [`capture-pane`](/en/tmux/latest/manual/capture-pane/)

```
libtmux.Pane.capture_pane(
    self,
    start: t.Literal["-"] | int | None = ...,
    end: t.Literal["-"] | int | None = ...,
    escape_sequences: bool = ...,
    escape_non_printable: bool = ...,
    join_wrapped: bool = ...,
    preserve_trailing: bool = ...,
    trim_trailing: bool = ...,
    alternate_screen: bool = ...,
    quiet: bool = ...,
    mode_screen: bool = ...,
    pending: bool = ...,
    hyperlinks: bool = ...,
    line_numbers: bool = ...,
    line_flags: bool = ...,
    to_buffer: str,
) -> None

libtmux.Pane.capture_pane(
    self,
    start: t.Literal["-"] | int | None = ...,
    end: t.Literal["-"] | int | None = ...,
    escape_sequences: bool = ...,
    escape_non_printable: bool = ...,
    join_wrapped: bool = ...,
    preserve_trailing: bool = ...,
    trim_trailing: bool = ...,
    alternate_screen: bool = ...,
    quiet: bool = ...,
    mode_screen: bool = ...,
    pending: bool = ...,
    hyperlinks: bool = ...,
    line_numbers: bool = ...,
    line_flags: bool = ...,
    to_buffer: None = ...,
) -> list[str]

libtmux.Pane.capture_pane(
    self,
    start: t.Literal["-"] | int | None = None,
    end: t.Literal["-"] | int | None = None,
    escape_sequences: bool = False,
    escape_non_printable: bool = False,
    join_wrapped: bool = False,
    preserve_trailing: bool = False,
    trim_trailing: bool = False,
    alternate_screen: bool = False,
    quiet: bool = False,
    mode_screen: bool = False,
    pending: bool = False,
    hyperlinks: bool = False,
    line_numbers: bool = False,
    line_flags: bool = False,
    to_buffer: str | None = None,
) -> list[str] | None
```

Capture text from pane.

[`$ tmux capture-pane`](/en/tmux/latest/manual/capture-pane/) to pane.
[`$ tmux capture-pane -S -10`](/en/tmux/latest/manual/capture-pane/) to pane.
[`$ tmux capture-pane -E 3`](/en/tmux/latest/manual/capture-pane/) to pane.
[`$ tmux capture-pane -S - -E -`](/en/tmux/latest/manual/capture-pane/) to pane.

## Examples

```python
>>> pane = window.split(shell='sh')
>>> pane.capture_pane()
['$']
```

```python
>>> pane.send_keys('echo "Hello world"', enter=True)
```

```python
>>> pane.capture_pane()
['$ echo "Hello world"', 'Hello world', '$']
```

```python
>>> print(chr(10).join(pane.capture_pane()))
$ echo "Hello world"
Hello world
$
```

## Parameters

- `start` (`t.Literal["-"] | int | None`): Specify the starting line number.
Zero is the first line of the visible pane.
Positive numbers are lines in the visible pane.
Negative numbers are lines in the history.
``-`` is the start of the history.
Default: None
- `end` (`t.Literal["-"] | int | None`): Specify the ending line number.
Zero is the first line of the visible pane.
Positive numbers are lines in the visible pane.
Negative numbers are lines in the history.
``-`` is the end of the visible pane.
Default: None
- `escape_sequences` (`bool`): Include ANSI escape sequences for text and background attributes
(``-e`` flag). Useful for capturing colored output.
Default: False
- `escape_non_printable` (`bool`): Escape non-printable characters as octal ``\\xxx`` format
(``-C`` flag). Useful for binary-safe capture.
Default: False
- `join_wrapped` (`bool`): Join wrapped lines and preserve trailing spaces (``-J`` flag).
Lines that were wrapped by tmux will be joined back together.
Default: False
- `preserve_trailing` (`bool`): Preserve trailing spaces at each line's end (``-N`` flag).
Default: False
- `trim_trailing` (`bool`): Trim trailing positions with no characters (``-T`` flag).
Only includes characters up to the last used cell.
Requires tmux 3.4+. If used with tmux < 3.4, a warning
is issued and the flag is ignored.
Default: False
- `alternate_screen` (`bool`): Capture from the alternate screen (``-a`` flag).
Default: False (added 0.56)
- `quiet` (`bool`): Suppress errors silently (``-q`` flag).
Default: False (added 0.56)
- `mode_screen` (`bool`): Capture from the mode screen (e.g. copy mode) instead of the
pane (``-M`` flag). Requires tmux 3.6+.
Default: False (added 0.56)
- `pending` (`bool`): Capture *pending output* — the bytes tmux has read from the
pane but not yet committed to the terminal (``-P`` flag).
These are bytes that begin an incomplete escape sequence
and are still pending the parser's ground state (tmux's
``input_pending()`` / ``since_ground`` buffer), distinct
from the default capture (the pane's screen history).
Useful for diagnosing programs whose output stalls
mid-sequence.
Default: False (added 0.57)
- `hyperlinks` (`bool`): Capture only hyperlink targets in the selected lines (``-H``
flag). Requires tmux 3.7+. If used with tmux < 3.7, a warning
is issued and the flag is ignored.
Default: False
- `line_numbers` (`bool`): Prefix each captured line with its line number (``-L`` flag).
Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued
and the flag is ignored.
Default: False
- `line_flags` (`bool`): Prefix each captured line with its flags, e.g. ``H`` for a line
with a hyperlink (``-F`` flag). Requires tmux 3.7+. If used with
tmux < 3.7, a warning is issued and the flag is ignored.
Default: False
- `to_buffer` (`str | None`): Write the capture into the named tmux buffer (``-b`` flag)
instead of returning it. When set, ``-p`` is omitted and
the wrapper returns ``None``. (added 0.56)

## Returns

list[str] or None
    Captured pane content, or ``None`` when *to_buffer* is set.

## In other ports

### Read a pane’s visible contents

- Ruby: [`LibTmux::Pane#capture`](/en/ruby/latest/reference/libtmux-pane-capture/) (method)
- Lua: [`libtmux.Pane:capture`](/en/lua/latest/reference/libtmux-pane-capture/) (method)
- TypeScript: [`pane.Pane.capture`](/en/ts/latest/reference/pane-pane-capture/) (method)
- Rust: [`pane.Pane.capture`](/en/rs/latest/reference/pane-pane-capture/) (method)
- Go: [`tmux.Pane.Capture`](/en/go/latest/reference/tmux-pane-capture/) (method)
- Java: [`io.github.libtmux.Pane.Pane.capture`](/en/java/latest/reference/io-github-libtmux-pane-pane-capture/) (method)
- C#: [`LibTmux.Pane.CaptureAsync`](/en/csharp/latest/reference/libtmux-pane-captureasync/) (method)
- C++: [`libtmux::Pane::capture`](/en/cxx/latest/reference/libtmux-pane-capture/) (method)
- Swift: [`Server.capture(_:includingHistory:)`](/en/swift/latest/reference/server-capture(_-includinghistory-)/) (method)
- Kotlin: [`io.github.libtmux.kotlin.Pane.capture`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-pane-capture/) (method)
- Scala: [`io.github.libtmux.scaladsl.Pane.capture`](/en/scala/latest/reference/io-github-libtmux-scaladsl-pane-capture/) (method)
- F#: [`LibTmux.FSharp.Pane.capture`](/en/fsharp/latest/reference/libtmux-fsharp-pane-capture/) (function)
