Skip to main content

Introduction to Control Mode

tmux’s control mode provides a textual interface for programmatic interaction with tmux. It allows applications to communicate with tmux using a simple, text-based protocol instead of terminal escape sequences.
Control mode is designed for applications that need to programmatically control tmux, such as terminal multiplexer frontends, testing tools, or automation scripts.

Starting Control Mode

Basic Invocation

Start tmux in control mode with the -C flag:

Disable Echo

Use -CC to disable echo:
This prevents tmux from echoing back commands, useful for programmatic clients.

Protocol Overview

In control mode, communication happens through:
  • Input: Commands sent to tmux on stdin, one per line
  • Output: Responses and notifications on stdout

Command Structure

Send tmux commands as text:

Response Format

Each command produces a response block:
Or on error:

Example Session

Notifications

Control mode sends notifications for events. Notifications never occur inside output blocks.

Common Notifications

Buffer and Subscription Events

Client Control

Setting Client Size

Control the size of windows/panes visible to the control mode client:

Client Flags

Control mode clients can have special flags:
Available flags:
  • active-pane - Client has independent active pane
  • ignore-size - Client doesn’t affect window size
  • no-detach-on-destroy - Don’t detach when session destroyed
  • no-output - Client doesn’t receive pane output
  • pause-after=seconds - Pause output when behind
  • read-only - Client is read-only
  • wait-exit - Wait for empty line before exiting

Output Control

Pane Output Actions

Control pane output flow:

The pause-after Flag

Automatically pause panes when output is behind:
Without the pause-after flag, control mode clients that can’t keep up will be disconnected with a “too far behind” error after 300 seconds.

Subscriptions

Subscribe to format changes to receive notifications:

Subscription Types

The subscription what field can be:
  • Empty - Check attached session
  • %0, %1 - Specific pane ID
  • %* - All panes in attached session
  • @0, @1 - Specific window ID
  • @* - All windows in attached session

Subscription Notifications

When subscribed format changes:
Example:

Reading Pane Content

Output Notification

By default, pane output is sent via %output notifications:
Non-printable characters are octal-escaped (\nnn).

Extended Output

With pause-after flag, output uses extended format:
The number (1234) is the age in milliseconds that tmux buffered the output.

Capturing Pane Content

Capture pane content programmatically:

Sending Input to Panes

Send keystrokes or text to panes:

Practical Examples

Simple Control Mode Client

Monitoring Client

Automated Testing

Session Manager

Advanced Control Mode Usage

Event-Driven Architecture

Control mode is perfect for building tmux frontends, testing frameworks, and automation tools that need precise control over tmux sessions.