How to pipe pane output to external commands?

Quick Answer

Use Ctrl+b : then pipe-pane -o 'cat >> ~/session.log' to send all pane output to a file. Stop piping with pipe-pane (no arguments).

pipe-pane -o 'cat >> ~/session.log'

Detailed Explanation

The pipe-pane command sends all output from a pane to an external command or script. This is incredibly useful for logging sessions, monitoring build processes, or filtering output in real-time.

Basic Usage

# Start logging all output
pipe-pane -o 'cat >> ~/session.log'

# Log with timestamps
pipe-pane -o 'ts >> ~/timestamped.log'

# Stop piping (no arguments)
pipe-pane

Filtering Output

You can pipe output through filters to capture only what you need:

# Only log errors
pipe-pane 'grep -i error >> ~/errors.log'

# Monitor build completion
pipe-pane 'grep "Build complete" | notify-send "Build Done"'

# Log to syslog
pipe-pane 'logger -t tmux-session'

Pipe-Pane Flags

  • -o: Only output (default, excludes typed commands)
  • -I: Include input (commands you type)
  • -t: Target specific pane

Checking Pipe Status

# Check if current pane is piped
tmux display -p '#{?pane_pipe,PIPED,NOT_PIPED}'

# List all panes with pipe status
tmux list-panes -F '#{pane_index}: #{?pane_pipe,PIPED,NOT_PIPED}'

Pro Tip

Use pipe-pane 'tee ~/session.log' to both log output AND display it normally in the pane. The tee command splits the output.

Common Use Cases

  • Session Recording: Keep a log of everything for debugging
  • Build Monitoring: Get alerts when compilation finishes
  • Error Tracking: Automatically capture and process errors
  • System Monitoring: Watch log files and trigger actions

Key Binding Example

Add this to ~/.tmux.conf to toggle logging:

# Press Ctrl+b P to toggle pane logging
bind-key P if-shell 'tmux display -p "#{?pane_pipe,1,0}" | grep -q 1' \
  'pipe-pane' \
  'pipe-pane "cat >> ~/logs/#{session_name}-#{window_index}.log"'