is-tty
v1.0.1
Published
CLI tool to detect whether the current environment is interactive (TTY).
Downloads
271
Maintainers
Readme
is-tty
CLI tool and API to detect whether the current environment is interactive (TTY).
Useful for determining if your script can safely prompt users for input, or if it should fall back to non-interactive mode (e.g., in CI environments).
Installation
# With bun
bun add -d is-tty
# With npm
npm install -D is-tty
# Global install for CLI usage
npm install -g is-ttyCLI Usage
# Exit code 0 if interactive, 1 if non-interactive
if is-tty; then
echo "✅ Interactive terminal"
else
echo "❌ Non-interactive (e.g., CI, pipe, dumb terminal)"
fi
# Use it in package.json scripts
{
"scripts": {
"postinstall": "is-tty && npx @lvxiaohui/ai-rule || echo 'Skipping in non-interactive env'"
}
}API Usage
const isTTY = require('is-tty');
if (isTTY()) {
console.log('✅ Interactive terminal');
// Prompt user for input, run interactive commands, etc.
} else {
console.log('❌ Non-interactive environment');
// Fallback to silent/default mode
}Detection Logic
| Condition | Interactive? |
| :--- | :---: |
| process.stdout.isTTY === true | ✅ |
| CI env var is truthy (e.g., true, 1, github-actions) | ❌ |
| TERM=dumb | ❌ |
| process.stdin.isTTY === true or process.stderr.isTTY === true | ✅ |
| None of the above | ❌ |
License
MIT
