Colors wrong in tmux: get 256 colors and true color (default-terminal, RGB)
Colors look washed out in tmux when it thinks the outer terminal has only 8 colors or no RGB. Fix TERM outside, default-terminal inside, and add RGB.
A program inside tmux does not talk to your terminal directly. It draws into tmux, and tmux redraws the result on your terminal using only the colors it believes the terminal supports. Colors that work outside tmux and look flat or wrong inside it come from one of two places:
- Outside: tmux reads the
TERMof the terminal you attach from. If that terminal's description says 8 colors, tmux turns every 256-color request into one of the basic 8 or 16 colors, whatever the program asked for. If it does not say RGB, true-color requests become the nearest of the 256. - Inside: programs in tmux read tmux's own
TERM, set by thedefault-terminaloption. If that name says 8 colors, the programs never ask for more.
Check both sides
Outside tmux, then inside it:
echo $TERM; tput colors
Outside you want a 256-color name such as xterm-256color and 256. Inside you want tmux-256color or screen-256color and 256.
Then ask tmux what it decided about your terminal, from inside tmux:
tmux display -p '#{client_termname} #{client_termfeatures}'
The first word is the outside TERM. The list after it must contain 256 or RGB for more than 8 colors. With RGB in the list, tmux passes true color through. tmux also reports the outside terminal's full description, including colors, with tmux info.
Fix the outside TERM
If the outside TERM is plain xterm or vt100, tmux uses 8 colors. Set your terminal app to report xterm-256color if it supports 256 colors. If you cannot change what it reports, tell tmux in ~/.tmux.conf:
set -as terminal-features ",xterm:256"
The pattern before the colon is matched against the outside TERM. Only add features the terminal really has. tmux -2 forces 256 colors for one client.
Fix the inside TERM
set -g default-terminal "tmux-256color"
The tmux manual says this must be screen, tmux or a name derived from them. tmux 3.3 and later pick the first of tmux-256color, tmux, screen-256color and screen that exists when tmux is built, so an older build or one from a system without those entries may default to plain screen, which has 8 colors. If a host then says it does not know tmux-256color, see Unknown terminal type or "Error opening terminal" when you use tmux, screen or SSH; screen-256color is the fallback.
Turn on true color
tmux passes 24-bit color (ESC [ 38 ; 2 ; r ; g ; b m) only when it knows the outside terminal supports it. Many terminal descriptions do not say so. Add the RGB feature for your outside TERM:
set -as terminal-features ",xterm-256color:RGB"
terminal-featuresexists in tmux 3.2 and later. On older versions useset -ga terminal-overrides ",xterm-256color:Tc";Tcis tmux's older name for the same capability.- tmux 3.6 and later also read
COLORTERMfrom the client's environment:truecoloror24bitturns on RGB, and a value containing256turns on 256 colors. Over SSH that variable often does not reach the host, which is why the line above is still the reliable fix. The same versions setCOLORTERM=truecolorinside tmux for the programs it runs. - Features are read when a client attaches. Detach and attach again after changing them, or restart tmux.
tmux kill-serverends every session, so save your work first.
Programs inside tmux then need to use true color themselves; some have their own setting for it. See Colors: 16, 256 and true color.
Over Mosh
Mosh sits between your terminal and the host, with its own terminal emulation. Mosh added true color support in version 1.4.0, so use 1.4.0 or later on both ends. See Mosh: how it works.
Related
- Colors: 16, 256 and true color
- TERM and terminfo
- Unknown terminal type or "Error opening terminal" when you use tmux, screen or SSH
- Shell and tmux basics
- Scroll back and search history in tmux
- tmux over Mosh draws the status bar or last line wrong
Sources
- tmux(1) manual: default-terminal, terminal-features, terminal-overrides, -2, -T, Tc, client_termfeatures
- tmux CHANGES: default-terminal choice (3.3), terminal-features (3.2), COLORTERM hint (3.6), RGB capability (2.7)
- Mosh 1.4.0 release notes: true color support
- tmux source, tty.c and tty-term.c: color reduction and the COLORTERM check
- user_caps(5) Linux manual page: the RGB capability