TTYHAWK 0.1.1  (C) kwy404, MIT
Self test ...... 2.6 kB, 0 deps  [ OK ]
Probing terminal:
  TERM=xterm-256color COLORTERM=truecolor
  colorLevel ... 3 truecolor  [ OK ]
  unicode ...... true         [ OK ]
  hyperlinks ... true         [ OK ]
  isCI ......... false        [ OK ]
  size ......... 80 x 24      [ OK ]
Ready.

Know what the terminal can do, in one tiny call.

Color depth, unicode, clickable links, size and CI, answered by one consistent rulebook that respects NO_COLOR, FORCE_COLOR and CLICOLOR, with every input injectable for tests.

$ npm i ttyhawk

Runs onNode 18+BunDeno 2Browsers

1Live playground

Flip the environment, watch the hawk adapt

This is the real ttyhawk source running in your browser. Pick a terminal, toggle variables and see the detection and sample output change at every level.

Terminal
  • { p.label }
Platform
CI provider
  • { p.label }
FORCE_COLOR
CLICOLOR
Command line flag (argv: true)
Locale (LANG)
Output is a TTYOff means piped to a file or another program
NO_COLOR=1
CLICOLOR_FORCE=1
{ presetLabel } / { platform }{ ci !== 'none' ? ' / ' + ciLabel : '' }
Environment passed as env Node getColorDepth() equivalent: { depth } bit

Decided by: { decided }

2Why it exists

One question, four packages, four rulebooks

  • Scattered answers

    Color, unicode, hyperlinks and CI each lived in a different package, each with its own idea of which variable wins. Two of them read the same TERM and still disagreed.

  • Standards, followed to the letter

    NO_COLOR, FORCE_COLOR and CLICOLOR are documented conventions. ttyhawk implements them as written, in a precedence order that is printed in the README and pinned by tests.

  • Testable by design

    Pass env, argv, platform, osRelease and isTTY to get a deterministic answer. No global mutation, no re-import, no flaky CI because the runner had a TTY.

one rulebooksh
$ Same input, five answers

  supports-color        NO_COLOR=1               2
  supports-color        FORCE_COLOR=yes, no TTY  0
  is-unicode-supported  LANG=en_US.ISO-8859-1    true
  supports-hyperlinks   Netlify build            true

$ ttyhawk

  detect()              NO_COLOR=1               0
  detect()              FORCE_COLOR=yes, no TTY  1
  detect()              LANG=en_US.ISO-8859-1    false
  detect()              Netlify build            false

  = one rulebook

3Features

Everything a CLI needs to know before it prints

Color level 0 to 3

No color, 16, 256 or truecolor, from TERM, COLORTERM, TERM_PROGRAM, Windows builds and CI log viewers.

Unicode that renders

Knows the Linux console, legacy Windows consoles, Windows Terminal, VS Code and non UTF-8 locales.

Clickable links

OSC 8 support for iTerm, WezTerm, VS Code, ghostty, kitty, VTE, foot and Windows Terminal, with FORCE_HYPERLINK.

Eleven CI providers

GitHub Actions, GitLab, CircleCI, Travis, Buildkite, Azure, Jenkins, TeamCity, Bitbucket, Vercel, Netlify, and CI=false to opt out.

The conventions, done right

NO_COLOR and FORCE_COLOR ignore empty values, FORCE_COLOR=0..3 sets exact levels, CLICOLOR and CLICOLOR_FORCE behave as specified.

NO_COLORFORCE_COLOR=0..3CLICOLORCLICOLOR_FORCEFORCE_HYPERLINK--no-color--color=256

Size with fallbacks

Columns and rows from the stream, then COLUMNS and LINES, then 80 by 24. Never throws.

Every runtime

Node 18+, Bun, Deno 2 with or without permissions, and browsers. ESM, CommonJS and types.

Speaks Node

toColorDepth and fromColorDepth convert levels to the bit depth of Node's getColorDepth, with parity tests.

toColorDepth(colorLevel(stream)); // 1, 4, 8 or 24
fromColorDepth(stream.getColorDepth()); // 0 to 3

4Precedence

Who wins, in order

The first rule that applies decides the color level. Everything below is covered by tests with injected environments.

Precedence
  1. Command line flags such as --no-color and --color=256, only when you pass argv: true.
  2. FORCE_COLOR: 0 or false turns color off, 1 to 3 set the level, true forces color at the detected depth.
  3. NO_COLOR and NODE_DISABLE_COLORS: any non empty value turns color off.
  4. CLICOLOR_FORCE forces color on, then CLICOLOR=0 turns it off.
  5. No TTY means no color, unless a rule above forced it. TERM=dumb means no color.
  6. Windows Terminal and the Windows build number, then CI log viewers.
  7. COLORTERM, TERM_PROGRAM and finally the TERM name.

5How to

Small surface, sharp answers

ttyhawk(3)

NAME

ttyhawk: Check if a terminal supports color, truecolor, unicode and hyperlinks, and detect CI, in one call. Honors NO_COLOR and FORCE_COLOR. Zero dependencies.

SYNOPSIS

import { detect, colorLevel, supportsUnicode, supportsHyperlinks,
  isCI, ciName, terminalSize, toColorDepth, fromColorDepth } from 'ttyhawk';

detect(stream, { env, argv, platform, osRelease, isTTY });
// { isTTY, colorLevel, unicode, hyperlinks, columns, rows, isCI, ciName }

DESCRIPTION

Every function takes the same options: env, argv, platform, osRelease and isTTY. The full reference, with every rule, is in the README.

EXAMPLES

{ tabs[current].file }
import { detect, colorLevel } from 'ttyhawk';const caps = detect(process.stderr);// { isTTY: true, colorLevel: 3, unicode: true, hyperlinks: true,//   columns: 120, rows: 34, isCI: false, ciName: null }const tick = caps.unicode ? '\u2714' : 'v';if (colorLevel(process.stderr) >= 2) {  // 256 colors or more: use the richer palette}
import { test } from 'node:test';import assert from 'node:assert/strict';import { detect } from 'ttyhawk';test('respects NO_COLOR', () => {  const caps = detect(null, {    env: { TERM: 'xterm-256color', NO_COLOR: '1' },    platform: 'linux',    isTTY: true,  });  assert.equal(caps.colorLevel, 0);});
#!/usr/bin/env nodeimport { colorLevel, supportsHyperlinks } from 'ttyhawk';// Only the CLI entry point opts in to --color and --no-color.const level = colorLevel(process.stdout, { argv: true });const links = supportsHyperlinks(process.stdout, { argv: true });const link = (text, url) =>  links ? `\x1b]8;;${url}\x07${text}\x1b]8;;\x07` : `${text} (${url})`;
import { colorLevel, toColorDepth, fromColorDepth } from 'ttyhawk';toColorDepth(colorLevel(process.stdout, { isTTY: true })); // 24// same scale as process.stdout.getColorDepth()fromColorDepth(8); // 2

SEE ALSO

Full API reference

6Comparison

One package instead of four

What each package covers, checked against its source code and the scenarios in the next table.

Capabilityttyhawksupports-coloris-unicode-supportedsupports-hyperlinksci-info
Color level 0 to 3
Honors NO_COLOR
Honors CLICOLOR and CLICOLOR_FORCE
Unicode detection
OSC 8 hyperlink detection
CI provider detection
Injectable env object for tests
Reads command line flags only when asked
Zero dependencies
YesNoPartialNot covered

Partial: supports-color always reads flags in its default export; createSupportsColor accepts sniffFlags: false. 34 scenarios, supports-color 11.0.0, is-unicode-supported 2.1.0, supports-hyperlinks 5.0.0, ci-info 4.5.0, Node v24.16.0

Where ttyhawk answers differently

Each scenario ran through ttyhawk and the popular single purpose packages in a fresh process. These are the cases where the answers differ; the README explains why for each one.

ScenarioPackageTheir answerttyhawk
NO_COLOR=1supports-color20
FORCE_COLOR empty, no TTYsupports-color10
FORCE_COLOR=yes, no TTYsupports-color01
CLICOLOR_FORCE=1, no TTYsupports-color01
CLICOLOR=0supports-color20
TERM=xterm-directsupports-color13
TERM=alacrittysupports-color03
TERM=alacrittysupports-hyperlinksfalsetrue
vscode 1.95supports-color23
WezTermsupports-color23
LANG=en_US.ISO-8859-1is-unicode-supportedtruefalse
Windows, GitHub Actionsis-unicode-supportedfalsetrue
GitLab CI on a TTYsupports-color12
Azure Pipelinessupports-color10
Netlify buildsupports-hyperlinkstruefalse
Netlify buildci-info name"Netlify CI""Netlify"
CI=false with GitHub varssupports-color30

7Benchmarks

Honest numbers

Operations per second, median of five runs, every library reading the same process.env. On Windows each process.env read is slow and ttyhawk reads more variables because it follows more rules, so it trails per call. With a plain env object it is the fastest. Detection runs once at startup either way.

ops/sNode v24.16.0, AMD Ryzen 7 7800X3D, Windows 10

Color level

ttyhawk colorLevel (env object)1,520,363
ttyhawk colorLevel (process.env)159,164
node getColorDepth (process.env)481,718
supports-color 11.0.0376,807

Unicode

ttyhawk supportsUnicode (process.env)171,826
is-unicode-supported 2.1.0219,912

Hyperlinks

ttyhawk supportsHyperlinks (process.env)66,635
supports-hyperlinks 5.0.0109,802

Everything

ttyhawk detect (process.env)47,672

ops/s

Size

Smaller than this paragraph's screenshot

Measured on the ESM entry with terser and gzip. No dependencies, no side effects, tree shakeable named exports.

2.4 kBmin + brotli
0dependencies
9named exports
2.6kB

min + gzip

Compatibility

Runs where your CLI runs

  • Node 18 to 24 Tested in CI on Linux, Node 24 also on Windows and macOS
  • Bun 1.x Smoke tested in CI
  • Deno 2 Smoke tested in CI, with and without --allow-env and --allow-sys
  • Browsers Works: reports no TTY and no color unless you pass options

8FAQ

Questions people ask

CI runners do not attach a TTY to your process. Set FORCE_COLOR=1 (or 2, 3) in the job, as most pipelines already do for other tools.

Yes, as in Node. NO_COLOR is a user wide preference and FORCE_COLOR is usually set for one job or one command, so the more specific setting wins. Command line flags beat both.

A library that reads process.argv reacts to flags meant for someone else. Pass argv: true in your CLI entry point only.

No. It only detects. Pair it with any color library, or write the escape codes yourself.

Yes. Without options it reports no TTY, no color and 80 by 24. The playground above runs the real library in your browser.
logout

Give your CLI a hawk eye view

One import, one call, and your output fits every terminal it lands in.

$ npm i ttyhawk
1Try the playground
ttyhawk
{ msg }