CPX 2.0: Run Composer Packages Without Installing Them | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com) [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles  ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

  [ home ](https://msaied.com)    [ articles ](https://msaied.com/articles)    CPX 2.0: The Composer Package Executor for PHP        On this page       1. [  What Is CPX? ](#what-is-cpx)
2. [  Running a Package Without Installing It ](#running-a-package-without-installing-it)
3. [  Local Binaries Win by Default ](#local-binaries-win-by-default)
4. [  User-Defined Aliases ](#user-defined-aliases)
5. [  Running PHP Files, Gists, and a REPL ](#running-php-files-gists-and-a-repl)
6. [  AI-Agent-Aware Output ](#ai-agent-aware-output)
7. [  Installing CPX 2.0 ](#installing-cpx-20)
8. [  Key Takeaways ](#key-takeaways)

  ![CPX 2.0: The Composer Package Executor for PHP](https://cdn.msaied.com/494/a02397af83eb385e105f0783debcd08b.png)

 [  Laravel ](https://msaied.com/articles?category=laravel) [  Composer Pacakge ](https://msaied.com/articles?category=composer-pacakge)  #CPX   #Composer   #PHP CLI   #Laravel   #Developer Tools  

 CPX 2.0: The Composer Package Executor for PHP 
================================================

     30 Jul 2026      4 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   What Is CPX?  ](#what-is-cpx)
2. [  02   Running a Package Without Installing It  ](#running-a-package-without-installing-it)
3. [  03   Local Binaries Win by Default  ](#local-binaries-win-by-default)
4. [  04   User-Defined Aliases  ](#user-defined-aliases)
5. [  05   Running PHP Files, Gists, and a REPL  ](#running-php-files-gists-and-a-repl)
6. [  06   AI-Agent-Aware Output  ](#ai-agent-aware-output)
7. [  07   Installing CPX 2.0  ](#installing-cpx-20)
8. [  08   Key Takeaways  ](#key-takeaways)

 What Is CPX?
------------

CPX is a CLI tool that does for Composer what `npx` does for npm: it lets you run a binary from any Composer package without installing that package into your project or your global Composer setup. Each package gets its own isolated directory, so dependency conflicts between globally installed tools become a thing of the past. Repeated runs of the same version reuse the cached installation, and CPX checks for updates automatically.

CPX 2.0 is now a first-party `laravel/cpx` package maintained by the Laravel team. It requires **PHP 8.3 or higher**.

Running a Package Without Installing It
---------------------------------------

Pass the package name followed by the command and any arguments. Version constraints work exactly as they do in `composer.json`:

```bash
cpx friendsofphp/php-cs-fixer php-cs-fixer fix ./src
cpx friendsofphp/php-cs-fixer:^3.0 php-cs-fixer fix ./src

```

When a package exposes a single binary, or the binary name matches the package name, you can omit the command:

```bash
cpx friendsofphp/php-cs-fixer fix ./src

```

You can also point CPX at a local directory, which is handy when developing a package:

```bash
cpx ../my-package --version

```

The directory must contain a valid `composer.json` and an installed `vendor/autoload.php`. CPX runs the declared binary directly from that checkout without copying or caching anything.

Local Binaries Win by Default
-----------------------------

This is the most significant behavior change from 1.x. CPX now walks up from the current directory to find the nearest Composer project and prefers its `vendor/bin` binaries:

```bash
cpx pint                  # runs vendor/bin/pint when present
cpx phpunit --filter=Foo  # runs vendor/bin/phpunit when present
cpx laravel/pint:^2.0     # uses local pint only if it satisfies ^2.0

```

When no matching local binary exists, CPX falls back to an isolated installation. To force the isolated copy regardless, pass `--skip-local`.

User-Defined Aliases
--------------------

The hardcoded shortcut list from 1.x is gone. You now define your own aliases:

```bash
cpx alias phpstan/phpstan phpstan
cpx alias laravel/pint          # defaults to the short name "pint"

```

Aliases are stored in `~/.cpx/`. Use `cpx aliases` to list them and `cpx unalias ` to remove one. `cpx installed` shows every package you have run through CPX, and `cpx clean` removes packages not used recently (`--all` clears everything).

Running PHP Files, Gists, and a REPL
------------------------------------

`cpx exec` and `cpx tinker` handle scratch files and quick experiments:

```bash
cpx exec script.php
cpx exec -r 'echo PHP_VERSION;'
cpx exec https://gist.github.com/user/id
cpx tinker

```

Gist support downloads the file and runs it in your current directory context. In a Laravel project, `cpx tinker` hands off to `php artisan tinker`; elsewhere it opens a PsySH shell with your project booted.

Inside these scripts, `cpx_require()` pulls in a Composer package on demand:

```php
cpx_require('nesbot/carbon');
echo Carbon\Carbon::now();

```

AI-Agent-Aware Output
---------------------

CPX detects non-interactive environments—redirected stdin, `--no-interaction`, or an AI agent identified via `laravel/agent-detector`. In that mode, management commands return structured JSON:

```json
{
  "success": true,
  "errors": [],
  "summary": {
    "packages": [
      { "name": "laravel/pint", "last_run": "2024-01-02 03:04:05" }
    ]
  }
}

```

Package runs stream only the underlying tool's output. Pass `--json` to get the same format in an interactive terminal.

Installing CPX 2.0
------------------

```bash
composer global require cpx/cpx

```

Make sure Composer's global `bin` directory is on your `PATH`.

Key Takeaways
-------------

- CPX runs any Composer package in isolation—no global dependency conflicts.
- Local project binaries take priority by default; use `--skip-local` to override.
- User-defined aliases replace the old hardcoded shortcut list.
- `cpx exec` supports local files, inline code, and GitHub Gists.
- `cpx tinker` boots your Laravel or Symfony project automatically.
- Non-interactive and AI-agent environments receive clean JSON output.
- Requires PHP 8.3+; install with `composer global require cpx/cpx`.

---

*Source: [CPX: The Composer Package Executor for PHP — Laravel News](https://laravel-news.com/cpx-the-composer-package-executor-for-php)*

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fcpx-20-the-composer-package-executor-for-php&text=CPX+2.0%3A+The+Composer+Package+Executor+for+PHP) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fcpx-20-the-composer-package-executor-for-php) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  What is CPX and how does it differ from `composer global require`?        CPX runs a Composer package binary in an isolated directory without adding it to your project or global Composer setup. Unlike `composer global require`, each package CPX manages has its own dependency tree, so there are no version conflicts between tools. 

      Q02  Does CPX 2.0 work with packages already installed in my Laravel project?        Yes. By default, CPX 2.0 looks for a matching binary in your project's `vendor/bin` directory first. If it finds one, it runs that version. You can force CPX to use an isolated copy instead by passing `--skip-local` before the package name. 

      Q03  What PHP version does CPX 2.0 require?        CPX 2.0 requires PHP 8.3 or higher. Install it globally with `composer global require cpx/cpx` and ensure Composer's global `bin` directory is on your system PATH. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://msaied.com/articles) 

 [ ![PhpStorm 2026.2 Released: Laravel Tool Window, PHP 8.5 Pipe Operator, and AI Agents](https://cdn.msaied.com/505/151a0bba66cc27064e090e69e55d7c92.png) PhpStorm JetBrains PHP 8.5 

### PhpStorm 2026.2 Released: Laravel Tool Window, PHP 8.5 Pipe Operator, and AI Agents

PhpStorm 2026.2 ships a dedicated Laravel tool window with Artisan, error logs, and Laravel Cloud tabs, plus P...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 3 Aug 2026     3 min read  

  Read    

 ](https://msaied.com/articles/phpstorm-20262-released-laravel-tool-window-php-85-pipe-operator-and-ai-agents) [ ![Laravel Doctor: Diagnose Your Laravel App With One Artisan Command](https://cdn.msaied.com/504/d72224689abc7b396bce187535008272.png) Laravel Artisan Health Checks 

### Laravel Doctor: Diagnose Your Laravel App With One Artisan Command

Laravel Doctor is a first-party package announced at Laracon US 2026 that adds an `artisan doctor` command to...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 3 Aug 2026     4 min read  

  Read    

 ](https://msaied.com/articles/laravel-doctor-diagnose-your-laravel-app-with-one-artisan-command) [ ![Livewire v4.3.5 Released: Fix for SFC Detection with PHP Attribute Array Arguments](https://cdn.msaied.com/503/9678ed8dbf5d7a6f4f19ca7694cf241b.png) Livewire Laravel PHP 

### Livewire v4.3.5 Released: Fix for SFC Detection with PHP Attribute Array Arguments

Livewire v4.3.5 ships a targeted bug fix for Single File Component (SFC) detection when PHP attributes contain...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 3 Aug 2026     2 min read  

  Read    

 ](https://msaied.com/articles/livewire-v435-released-fix-for-sfc-detection-with-php-attribute-array-arguments) 

   [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

Explore

- [Home](https://msaied.com)
- [Projects](https://msaied.com/projects)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [Contact](https://msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
