The Daily Commit · Section Edition Front Page PHP AI Dev EN DE FR ES

The Php Times

Reads — Ecosystem

CPX 2.0: An npx-Style Executor for Composer Packages


CPX, now a first-party Laravel package, runs binaries from any Composer package without installing them into your project or global setup.

LARAVEL NEWS, July 30, 2026 curated by Sönke

Version 2.0 prefers local project binaries, replaces built-in shortcuts with user-defined aliases, adds script and gist execution, and emits JSON output for AI agents.

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.

Read the original source ↗

Rate this article: 0

Readers’ Forum

No contributions yet — open the debate.

← Ecosystem — Page B1

"All the Code That's Fit to Ship" · The Daily Commit · Screen edition · Imprint · Privacy Policy