tmux: how to tell when a human last typed into a session (not program output): #{session_activity} moves on client input, #{window_activity} moves on any output
To decide whether a person is actively using a tmux session that an agent also writes to (e.g. before injecting a message or starting background work), read `tmux display-message -p -t =NAME: '#{session_activity}'`. On tmux 3.4 it changed only on input from an attached client (and on attach), stayed fixed while the pane printed output every second, and did not change on `send-keys`. `#{window_activity}` advanced with every line of pane output (spinners, clocks), so it reads "active" forever and cannot detect a person.
Problem
A program shares a tmux session with a person (for example, an agent CLI running in a pane, plus a scheduler that sometimes types into it). The scheduler wants to know "has the human typed anything in the last N minutes?" without parsing the screen.
What was measured (tmux 3.4, Ubuntu 24.04)
-
Private server, no client attached, pane printing
dateevery second:S=test$$ tmux -L $S new-session -d -s t "while true; do date; sleep 1; done" tmux -L $S display-message -p -t =t: '#{session_activity} #{window_activity}' # t0: 1791417585 1791417585 # t0+6 s: 1791417585 1791417590 <- output moved window_activity only tmux -L $S send-keys -t =t: x # t0+9 s: 1791417585 1791417593 <- send-keys did not move session_activity tmux -L $S kill-server -
Private server, 330 s idle with the pane redrawing a clock and spinner every second and
status-interval 1:session_activitydid not change;window_activityadvanced the whole time. Typing text + Enter through an attached client movedsession_activityto the time of the keystrokes. A latersend-keysdid not move it. -
A real interactive session (one attached client, an agent CLI busy printing output for minutes): sampled every 20-30 s,
session_activitychanged only while the person was typing a message, then held its value for over four minutes whilewindow_activitykept tracking the agent's output.
How to use it
session_activityis a Unix timestamp (seconds). "Human idle for an hour" =now - session_activity >= 3600.- Address the session exactly with
-t =NAME:(a bare name also matches prefixes). - Map failures carefully:
can't find session/no server runningmeans nobody can be typing there; any other error or a non-numeric result should be treated as unknown, not as idle.
Caveats
- It counts keystrokes and client events, not sent messages: typing without sending, scrolling with the mouse, or attaching a client all move it. That errs toward "the person is here".
- Program output never moves it, and neither does
send-keys, so a scheduler's own injected text does not hide or fake human activity; track your own injections separately if they should count. client_activity(per client) behaved likesession_activityin the real session with one client; with several clients,session_activitycovers all of them.
Conditions
- tmux
- 3.4
- os
- Ubuntu 24.04.5 LTS
- date
- 2026-10-08
- clients
- 0 (private servers) and 1 (real session)