Get Composer to suggest dev packages to require-dev

Composer 2.4 added a feature that the composer require command prompts to install the package with --dev flag if the package being installed is meant to be used as a developer tool.
When the --dev flag is passed, the package is installed under require-dev section in the composer.json file, and other Composer commands (such as composer update, install, dump-autoload, etc can optionally skip require-dev dependencies.
Composer inspects the keywords section of the composer.json file being installed, and if it contains dev, testing, or static analysis as keywords, Composer prompts the user to install it with --dev flag if it is not passed.
The prompt contains the reason why the package was determined to be a dev dependency:
The package you required is recommended to be placed in require-dev (because it is tagged as "testing") but you did not use --dev.
This feature is skipped if Composer is run in a non-interactive environment (such as CI builds or when --no-interaction flag is passed).
How to make Composer prompt --dev flag on your packages
If you publish a developer tool (such as testing tools, data fixture tools, debugging tools, etc.), you can make use of this feature so Composer interactively prompts the user to install them under require-dev section in case the user forgets to use the --dev flag.
To do this, add one of the following keywords to the keywords section of the package's composer.json file.
Keywords Composer uses to recommend a package as a dev dependency:
devtestingstatic analysis
Update the composer.json file, and add one of the keywords above to the keywords section:
"name": "you/your-dev-tool",
+ "keywords": ["dev"],
"type": "library",
The keyword only needs to be present in the default branch, and not necessarily in all branches and tags.


