cli-prompt
Tiny PHP library to prompt for CLI input and optionally hide the characters users type.
Repository Health
Technical Analysis
cli-prompt is a minimal PHP library that solves one focused problem: prompting for user input on the command line, including sensitive input where the typed characters should stay hidden. Reading input with fgets() is easy, but hiding keystrokes for passwords and secrets in a cross-platform way is surprisingly painful — this package handles it for you.
Written by Jordi Boggiano (creator of Composer), it exposes just two static methods for visible and hidden prompts, and bundles a Windows helper executable so hidden input works consistently across Unix-like systems and Windows.
What You Get
- A hiddenPrompt() method that reads input without echoing typed characters
- A prompt() method for standard visible command-line input
- Cross-platform hidden-input support, including a bundled Windows helper executable
- An optional fallback to visible input when hidden prompting is unavailable
- Automatic trimming of the trailing newline from submitted answers
- A zero-dependency footprint that works on PHP 5.3 and above
Common Use Cases
- Prompting for passwords or API tokens in a CLI installer or tool
- Collecting sensitive credentials without leaving them visible on screen
- Reading interactive input in console scripts and setup wizards
- Adding a secure prompt to Composer scripts or custom command-line utilities
Under The Hood
Architecture - The entire library is a single class, Seld\CliPrompt\CliPrompt (src/CliPrompt.php), exposing static hiddenPrompt() and prompt() methods. Hidden input is achieved by toggling terminal echo via stty on Unix-like systems and by shelling out to a bundled hiddeninput.exe helper on Windows, with the class encapsulating platform detection and the fgets() fallback path.
Tech Stack - Pure PHP (100% of the codebase) targeting PHP 5.3+, with no runtime dependencies. PSR-4 autoloading maps Seld\CliPrompt\ to src/, and PHPStan is used for static analysis in development.
Code Quality - The codebase is intentionally tiny (a few kilobytes of PHP) and focused on one concern, which keeps it easy to reason about. It is statically analyzed with PHPStan and authored by an experienced maintainer, though it carries no unit-test suite in the repository and has been in low-maintenance mode with infrequent releases.
API Design - The public surface is two static methods with clear names and a single optional parameter, making the library trivial to adopt: call CliPrompt::hiddenPrompt() and use the returned string. There is essentially no boilerplate or configuration required.