detect-terminal

Detect the terminal program currently being used, with support for iTerm, Terminal.app, Hyper, iTerm2, ConEmu, Cmde,r Alacritty, Xterm, Terminator, Termux, Kitty, and others. Detection is based on environment variables and process-level indicators to identify the terminal in use. This can't be done reliably in all cases, but it's useful when available.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
$ npm install --save detect-terminal
Usage
import detectTerminal from 'detect-terminal';
// or
import { detectTerminal } from 'detect-terminal';
console.log(detectTerminal()) //=> "iterm" (or whatever terminal you're using)
Supported Terminals
The following terminals are supported. Detection is based on environment variables and process-level indicators to identify the terminal in use.
- bash
- zsh
- windows_cmd
- powershell
- vscode
- gnome_terminal
- iterm
- windows_terminal
- xterm
- tmux
- terminal_app
- terminal
- konsole
- xfce4_terminal
- terminator
- alacritty
- wezterm
- putty
- node
- sh
- fish
- mate_terminal
- rxvt
- csh
- tcsh
- linux_console
- hyper
- warp
- qterminal
- screen
- eterm
- dopamine
- conhost
- ksh
- truecolor_terminal
- termux
- vt100
- kitty
Note:
- Some items are shell names (like
cmd
,sh
(Bourne Shell),bash
,zsh
,fish
, etc.) because the code's process-title detection maps those as possible values, and the code wasn't able to find a better terminal identifier. - The names are as returned by the detection methods (i.e.,
terminal_app
,gnome_terminal
, etc.) and not the terminal program's real executable names. This approach was takenn to avoid confusion with the actual executable names, which can vary across platforms and installations. - Fallback/auto-generated names (using sanitized env values) are also possible in the code but are not explicitly named in the code.
Terminal Detection
Terminal | Detection (ENV / Process) | Description |
---|---|---|
Alacritty | TERM=alacritty or TERM_PROGRAM=alacritty |
Cross-platform, GPU-accelerated terminal emulator |
Apple Terminal | TERM_PROGRAM=Apple_Terminal |
macOS default terminal emulator |
Cmd.exe | process.title=cmd or COMSPEC=cmd.exe |
Windows Command Prompt |
Eterm | TERM_PROGRAM=Eterm |
Enlightened Terminal Emulator |
Gnome Terminal | TERM_PROGRAM=gnome-terminal , TERM_PROGRAM=gnome-terminal-server , or VTE_VERSION detection |
GNOME terminal emulator |
Hyper | TERM_PROGRAM=Hyper |
JS/HTML/CSS terminal emulator |
iTerm2 | TERM_PROGRAM=iTerm.app or iTerm or iTerm2 |
Advanced terminal for macOS |
Kitty | TERM_PROGRAM=kitty or TERM=kitty |
GPU-accelerated terminal emulator |
Konsole | TERM_PROGRAM=konsole or environment variables containing "konsole" |
KDE terminal emulator |
MATE Terminal | TERM_PROGRAM=mate-terminal |
MATE terminal emulator |
PowerShell | TERM_PROGRAM=powershell or process.title=powershell or COMSPEC=powershell.exe or process.title=pwsh |
Powerful Windows/macOS/Linux shell |
PuTTY | TERM_PROGRAM=putty |
Popular SSH/Telnet client for Windows |
QTerminal | TERM_PROGRAM=qterminal |
Lightweight terminal for LXQt |
rxvt/rxvt-unicode | TERM=rxvt* , TERM_PROGRAM=rxvt |
Lightweight terminal emulator and its Unicode variant |
screen | TERM=screen |
Terminal multiplexer |
Terminator | TERM_PROGRAM=terminator |
Multiple terminals per window |
Termux | TERM_PROGRAM=termux or TERMUX_VERSION on Android |
Android terminal emulator |
tmux | TERM=tmux |
Terminal multiplexer |
VS Code | TERM_PROGRAM=vscode or VSCODE_PID or TERM_PROGRAM_VERSION contains vscode |
Visual Studio Code integrated terminal |
Warp | TERM_PROGRAM=warp |
Modern Rust-based terminal |
WezTerm | TERM_PROGRAM=wezterm |
GPU-accelerated terminal emulator |
Windows Terminal | WT_SESSION present or COMSPEC=wt.exe |
Modern tabbed terminal for Windows 10+ |
Xfce4 Terminal | TERM_PROGRAM=xfce4-terminal |
Xfce terminal emulator |
Xterm | TERM=xterm or TERM=xterm-256color |
X Window System terminal emulator |
VT100/VT220 | TERM=vt100 or TERM=vt220 |
DEC VT100 and VT220 (and compatible emulators) |
Notes:
- Detection uses the
TERM
andTERM_PROGRAM
environment variables, as well as process-level indicators such asprocess.title
on some platforms, to identify the running terminal. - Variable values are normalized to provide a consistent terminal identifier, regardless of differences in capitalization or formatting.
- Some Windows terminals are detected using Windows-specific variables such as
COMSPEC
orWT_SESSION
. - Terminal multiplexers such as
tmux
andGNU Screen
are identified through theTERM
variable when active. - When running inside Visual Studio Code's integrated terminal, detection relies on specific environment variables set by VS Code.
- Distinctions are maintained between terminal emulators (e.g., iTerm2, Konsole) and shells (e.g., bash, zsh), with shells excluded from the main detection table.
- In the absence of a recognized terminal, a fallback sanitizer produces a normalized identifier or
unknown
as a last resort. - The detection logic is designed to cover terminals across UNIX-like systems (Linux, macOS) and Windows, providing broad compatibility for diverse development environments.
History
v1.1.0
- Improved terminal detection accuracy with more advanced detection methods
- Added
VTE_VERSION
detection to properly identifyGNOME
Terminal when it masquerades as xterm - Implemented environment variable scanning to detect Konsole terminals that advertise as xterm
- Enhanced
COLORTERM
precedence handling for better terminal identification - Added macOS path parsing to extract application names from full paths
- Improved Android/Termux detection with
TERMUX_VERSION
checks - Enhanced Windows Terminal detection with
WT_SESSION
prioritization and pwsh support - Added better error handling with timeouts for shell execution
- Refined process title matching with more precise regex patterns
Related
You might also be interested in:
- open-file-manager-dialog: Cross-platform library for opening a file manager dialog window programmatically on MacOS, Windows, or Linux. | homepage
- open-file-manager: Cross-platform utility to open a file or directory in the system's default file manager (Finder… more | homepage
- open-finder-dialog: Open a finder dialog window (finder prompt) programmatically. Only works on MacOS. | homepage
- open-linux-file-dialog: Open a file dialog window programmatically to allow the user to select one or more… more | homepage
- open-windows-file-dialog: Programmatically open a file dialog window (explorer) for picking files. Only works on Windows. Also… more | homepage
About
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Author
Jon Schlinkert
License
Copyright © 2025, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on May 25, 2025.