Tmux – Why Tmux Sets TERM Variable to Screen

terminaltmux

Citing tmux man page:

The TERM environment variable must be set to “screen” for all programs running inside tmux. New windows will automatically have “TERM=screen” added to their environment, but care must be taken not to reset this in shell start-up files.

Is this this because tmux session can be attached to any terminal (e.g. remote), screen being lowest common denominator? If I know my terminal, can I force it without unexpected results, or would some unsupported capabilities break (like scrolling)?

Best Answer

It does this to take advantage of the previously-installed terminal description for GNU screen.

Both tmux and screen provide applications with (more or less) the "same" terminal descriptions to simplify connecting from different terminals. The tmux and screen programs are supposed to handle the differences between the internal (TERM=screen) and external (xterm, linux, etc). So the screen terminal description has been installed "everywhere" (usually by ncurses).

There are some differences:

  • GNU screen has a very old problem representing the "standout" feature (which technically is not a specific terminal feature but rather an abstraction for the convenience of curses applications). tmux does not have that limitation. But the improved TERM=tmux is not necessarily "everywhere".
  • GNU screen has a feature for using hybrid terminal descriptions. Given the external TERM=xterm and the existence of "screen.xterm", it will choose that for the internal TERM value. (see for example the terminal database). tmux does not do that.