Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aont/926d9a613b2a23e9df1138e3c0f30f89 to your computer and use it in GitHub Desktop.

Select an option

Save aont/926d9a613b2a23e9df1138e3c0f30f89 to your computer and use it in GitHub Desktop.

Forcing Consistent Colors in tmux (Regardless of Your Terminal Theme)

When you switch terminal themes, your prompt and UI colors might change—unless you tell tmux exactly which colors to use. tmux lets you bypass theme-dependent names like red or blue and instead target fixed palette indexes (or even truecolor) so your status bar and panes look the same everywhere.

The idea

Use numeric color indices (or RGB) instead of theme names. In tmux, that means:

  • colourN for the 256-color palette (0–255)
  • #RRGGBB for truecolor (24-bit), if your terminal supports it

These don’t depend on your terminal’s color scheme, so your tmux UI stays consistent.

Example: lock the status bar colors

set -g status-style fg=colour231,bg=colour34
  • colour231 is near-white
  • colour34 is a medium/bright green

This pins the status bar to white text on green, regardless of the terminal theme.

Where to put it

Add to ~/.tmux.conf:

# Status bar: white on green, theme-proof
set -g status on
set -g status-style fg=colour231,bg=colour34

Reload your config:

tmux source-file ~/.tmux.conf

Applying fixed colors elsewhere

Pin colors for specific segments or panes the same way:

# Left/right status segments
set -g status-left "#[fg=colour16,bg=colour190,bold] #S #[default]"
set -g status-right "#[fg=colour231,bg=colour60] %Y-%m-%d %H:%M #[default]"

# Active/inactive window styles
set -g window-status-current-style fg=colour16,bg=colour190
set -g window-status-style fg=colour188,bg=colour237

# Pane borders
set -g pane-border-style fg=colour238
set -g pane-active-border-style fg=colour40

Tip: Always include #[default] when you’re done styling inline segments so tmux resets formatting for whatever follows.

256-color vs truecolor

  • 256-color (colourN) works everywhere tmux does and is deterministic across terminals.

  • Truecolor (#RRGGBB) gives exact shades:

    set -g status-style fg=#ffffff,bg=#1db954

    Ensure your terminal and tmux support it. Most modern terminals do.

Enable truecolor safely

  1. Use a truecolor-capable terminal (iTerm2, Alacritty, WezTerm, recent Windows Terminal, etc.).

  2. Prefer TERM like xterm-256color outside tmux, and let tmux set screen-256color or tmux-256color inside. Avoid exotic TERM values.

  3. If colors look off, try:

    set -ga terminal-overrides ",*:Tc"

    This advertises 24-bit color to tmux.

How to discover colourN values

If you want a specific shade but stick to 256 colors, preview the palette:

# Quick 0–255 palette preview
for i in {0..255}; do printf "%3d \x1b[48;5;%sm  \x1b[0m" $i $i; 
  if ! (( (i+1) % 8 )); then echo; fi; 
done

Pick the index you like and plug it into colourN.

Common pitfalls

  • Theme names vs indices: fg=red can vary by theme; fg=colour196 will not.
  • Forgetting resets: Inline status strings (status-left/right) need #[default] to avoid “color leaks.”
  • Wrong $TERM: Values like xterm (no -256color) can reduce color fidelity. Use xterm-256color in your shell and let tmux handle its own $TERM.
  • Remote sessions: Over SSH, ensure the remote environment also supports 256/24-bit colors (same $TERM, similar overrides).

Minimal, theme-proof starter

# Status bar
set -g status on
set -g status-style fg=colour231,bg=colour34

# Windows
set -g window-status-current-style fg=colour16,bg=colour190
set -g window-status-style fg=colour250,bg=colour238

# Panes
set -g pane-active-border-style fg=colour40
set -g pane-border-style fg=colour238

# Optional: truecolor enable (if your terminal supports it)
set -ga terminal-overrides ",*:Tc"

With numeric indices—or explicit #RRGGBB—your tmux colors will stay consistent no matter which terminal theme you use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment