# Vendor binaries and the `vendor/bin` directory ## What is a vendor binary? Any command line script that a Composer package would like to pass along to a user who installs the package should be listed as a vendor binary. If a package contains other scripts that are not needed by the package users (like build or compile scripts) that code should not be listed as a vendor binary. ## How is it defined? It is defined by adding the `bin` key to a project's `composer.json`. It is specified as an array of files so multiple binaries can be added for any given project. ```json { "bin": ["bin/my-script", "bin/my-other-script"] } ``` ## What does defining a vendor binary in composer.json do? It instructs Composer to install the package's binaries to `vendor/bin` for any project that **depends** on that project. This is a convenient way to expose useful scripts that would otherwise be hidden deep in the `vendor/` directory. ## What happens when Composer is run on a composer.json that defines vendor binaries? For the binaries that a package defines directly, nothing happens. ## What happens when Composer is run on a composer.json that has dependencies with vendor binaries listed? Composer looks for the binaries defined in all of the dependencies. A proxy file (or two on Windows/WSL) is created from each dependency's binaries to `vendor/bin`. Say package `my-vendor/project-a` has binaries setup like this: ```json { "name": "my-vendor/project-a", "bin": ["bin/project-a-bin"] } ``` Running `composer install` for this `composer.json` will not do anything with `bin/project-a-bin`. Say project `my-vendor/project-b` has requirements setup like this: ```json { "name": "my-vendor/project-b", "require": { "my-vendor/project-a": "*" } } ``` Running `composer install` for this `composer.json` will look at all of project-a's binaries and install them to `vendor/bin`. In this case, Composer will make `vendor/my-vendor/project-a/bin/project-a-bin` available as `vendor/bin/project-a-bin`. ## Finding the Composer autoloader from a binary As of Composer 2.2, a new `$_composer_autoload_path` global variable is defined by the bin proxy file, so that when your binary gets executed it can use it to easily locate the project's autoloader. This global will not be available however when running binaries defined by the root package itself, so you need to have a fallback in place. This can look like this for example: ```php