# tmux.Pane.CaptureToFile

- **Module:** tmux.Pane
- **Package:** github.com/libtmux/libtmux-go/tmux
- **Language:** Go
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-go/blob/5f808882015a975a65acc7f9da5b3ff0d5cbdc91/tmux/pane_capture.go#L179
- **Page:** https://libtmux.org/reference/go/tmux-pane-capturetofile/

```
tmux.Pane.CaptureToFile(ctx: context.Context, path: string, request: CapturePaneRequest) -> ([]string, error)
```

CaptureToFile captures the receiver's exact linked pane through a tmux buffer and the file at path, returning the same lines [Pane.Capture] returns.

Printed captures cannot safely cross a control connection, so [Pane.Capture]
and [Pane.CaptureBytes] use a subprocess or reject a connection. CaptureToFile
stages through a scratch buffer so capture, save, and cleanup can all use the
connection's command lanes.

path must name a file the tmux server can write and this process can read.
It is replaced and left for the caller. Concurrent calls must use distinct
paths. The scratch tmux buffer is deleted before return when possible.

Validation and version gating match [Pane.Capture]. Capture, save, and
file-read failures return an error with no lines; buffer cleanup is best effort.
