In `tmux`, capture what appeared in the terminal pane:

```bash
tmux capture-pane -p -S - -t :.0
```

- `-p` prints it to stdout.
- `-S -` includes the entire pane history.
- `-t :.0` means current window, pane 0; omit it for the current pane.

Save it:

```bash
tmux capture-pane -p -S - -t :.0 > last-terminal.txt
```

This captures displayed stdout/stderr and any typed command text. It cannot recover hidden stdin, such as passwords or input redirected from a file.

For the *command text only* in Bash:

```bash
fc -ln -1
```

For reliable capture of a future command—including stdout and stderr—use:

```bash
your-command 2>&1 | tee command-output.txt
```

If it needs interactive stdin too, record the whole terminal session:

```bash
script -q session.log
# run commands and type input
exit
```

`session.log` records everything shown and typed in that terminal session.
