Skip to content

tty.WriteStream.getColorDepth() returns 8 inside tmux despite COLORTERM=truecolor #62404

@jacobcxdev

Description

@jacobcxdev

Bug

In lib/internal/tty.js, getColorDepth() checks env.TMUX (line 174) before env.COLORTERM (line 215). When TMUX is set, it returns COLORS_256 (8) immediately, never reaching the COLORTERM === 'truecolor' check that would return COLORS_16m (24).

tmux has supported true color since v2.2 (2016). Modern tmux sets COLORTERM=truecolor when the outer terminal supports RGB via terminal-features or terminal-overrides. The current ordering ignores this.

Note: PR #30474 previously reordered COLORTERM before the TERM check but did not address the TMUX check ordering.

Reproduction

const tty = require('tty');
console.log('TMUX:', process.env.TMUX || '(unset)');
console.log('COLORTERM:', process.env.COLORTERM || '(unset)');
console.log('getColorDepth():', process.stdout.getColorDepth());

Inside tmux (with COLORTERM=truecolor):

TMUX: /private/tmp/tmux-501/default,9842,1
COLORTERM: truecolor
getColorDepth(): 8    # ← wrong, should be 24

With TMUX= unset:

TMUX: (unset)
COLORTERM: truecolor
getColorDepth(): 24   # ← correct

Suggested fix

Move the COLORTERM truecolor/24bit check (line 215) before the TMUX check (line 174):

// Check COLORTERM first — tmux sets this when RGB is supported
if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') {
  return COLORS_16m;
}

if (env.TMUX) {
  return COLORS_256;
}

This preserves the TMUX → 256 fallback for tmux sessions that don't have truecolor configured, while correctly returning 16m for those that do.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions