CPX is a CLI tool that runs commands from any Composer package without installing that package into your project — the Composer equivalent of what npx is for npm. It installs each package into its own isolated directory, avoiding the dependency conflicts that plague composer global require, and reuses that installation on repeat runs while checking for updates.
You pass a package name (with optional version constraint) plus the command and arguments, e.g. cpx friendsofphp/php-cs-fixer:^3.0 php-cs-fixer fix ./src. If the package has a single binary, the command can be omitted; with multiple binaries, version 2.0 prompts you to choose. Pointing cpx at a local directory with a valid composer.json and installed vendor/autoload.php runs the declared binary directly from that checkout, useful for local package development.
The biggest behavior change from 1.x: cpx now walks up from the current directory to find the nearest Composer project and prefers its bin-dir binary, so cpx pint runs the version your project pins. Version constraints are respected, and --skip-local forces an isolated copy.
The fixed 1.x alias list is gone; users define their own with cpx alias, stored in ~/.cpx/ and managed via cpx aliases and cpx unalias. cpx installed lists executed packages, cpx clean prunes unused ones (--all removes everything), and cpx list now shows cpx commands instead.
cpx exec runs PHP scratch files, inline code via -r, or gists (with revision pinning via SHA and GITHUB_TOKEN support for rate limits). cpx tinker delegates to php artisan tinker in Laravel projects and otherwise opens a PsySH shell. Both auto-detect the Composer autoloader, alias unimported classes, boot Laravel (config, facades, .env, $app) or Symfony ($kernel, $container) applications — skippable with --no-boot — and run code in a separate PHP process with exit-code passthrough. A cpx_require() helper pulls packages on demand inside scripts.
When non-interactive — redirected stdin, -n, or an AI agent detected via laravel/agent-detector — cpx suppresses TTY and progress output and returns single-line JSON from management commands and error reports; --json forces this interactively, and overwriting aliases non-interactively needs --force.
cpx 2.0 requires PHP 8.3+ and installs via composer global require cpx/cpx. Originally created by Liam Hammett, it is now a first-party laravel/cpx package; Taylor Otwell demoed it at Laracon US 2026. An upgrade guide covers the 1.x to 2.x migration, and the docs live on GitHub and cpx.dev.
Comments
No comments yet — be the first.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Waiting for your click …
·