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 (New in 2.0) ](#local-binaries-win-by-default-new-in-20)
4. [  User-Defined Aliases ](#user-defined-aliases)
5. [  Running PHP Files, Gists, and a REPL ](#running-php-files-gists-and-a-repl)
6. [  Agent-Aware JSON Output ](#agent-aware-json-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/510/bc9e54c2003e340c780fa1d28872e88c.png)

 [  Composer Pacakge ](https://msaied.com/articles?category=composer-pacakge) [  PHP ](https://msaied.com/articles?category=php)  #cpx   #composer   #php   #laravel   #cli   #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 (New in 2.0)  ](#local-binaries-win-by-default-new-in-20)
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   Agent-Aware JSON Output  ](#agent-aware-json-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 lets you run a command from any Composer package without adding that package to your project's `composer.json`. If you've ever reached for `composer global require` and hit a dependency conflict, `cpx` solves that by installing each package into its own isolated directory and reusing that installation on repeat runs.

The analogy is intentional: `cpx` is to Composer what `npx` is to npm.

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

Pass the package name followed by the command and any arguments. Version constraints are supported:

```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 has a single binary, or its 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 instead of a package name, which is handy when developing a package locally:

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

```

Local Binaries Win by Default (New in 2.0)
------------------------------------------

This is the most significant behavioral change from 1.x. `cpx` now walks up from the current directory to find the nearest Composer project and prefers the binary from that project's `bin-dir`:

```bash
cpx pint                  # runs vendor/bin/pint when the project has it
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. Pass `--skip-local` to force the isolated copy regardless.

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

Version 1.x shipped a hardcoded list of shortcuts. That list is gone in 2.0—you define your own:

```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` lists packages you have run through `cpx`, and `cpx clean` removes ones you haven't used recently (`--all` removes everything).

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

`cpx exec` and `cpx tinker` cover scratch files and quick one-offs:

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

```

Both commands detect Composer's autoloader, alias unimported classes where possible, and fully boot a Laravel or Symfony application when one is present. Pass `--no-boot` to skip that. Inside these scripts, `cpx_require()` pulls in a package on demand:

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

```

In a Laravel project with `laravel/tinker` installed, `cpx tinker` delegates to `php artisan tinker`. Everywhere else it opens a PsySH shell.

Agent-Aware JSON 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 instead of formatted terminal output:

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

```

Pass `--json` to get the same output from an interactive terminal.

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

CPX 2.0 requires PHP 8.3 or higher. Install it globally and ensure Composer's global `bin` directory is on your `PATH`:

```bash
composer global require cpx/cpx

```

If you are on 1.x, review the [1.x to 2.x upgrade guide](https://github.com/laravel/cpx/blob/2.x/UPGRADE.md) before upgrading.

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

- `cpx` runs Composer package binaries in isolation—no project or global dependency conflicts.
- 2.0 prefers local project binaries by default; use `--skip-local` to override.
- The hardcoded alias list is replaced by user-defined aliases stored in `~/.cpx/`.
- `cpx exec` and `cpx tinker` support PHP files, remote Gists, and on-demand package loading via `cpx_require()`.
- Non-interactive and AI-agent environments receive structured JSON output automatically.
- Requires PHP 8.3+; now a first-party `laravel/cpx` package.

---

*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-1&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-1) 

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

  3 questions  

     Q01  How is CPX different from using `composer global require`?        `composer global require` installs packages into a shared global directory, which can cause dependency conflicts between tools. CPX installs each package into its own isolated directory, so tools never interfere with each other or with your project's dependencies. 

      Q02  Does CPX 2.0 use the version of a tool already installed in my project?        Yes. By default, CPX 2.0 walks up from the current directory to find the nearest Composer project and runs the matching binary from that project's `bin-dir`. You can force an isolated installation 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 with `composer global require cpx/cpx` and make sure Composer's global `bin` directory is on your `PATH`. 

  Continue reading

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

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

 [ ![Official Laravel Zed Extension: LSP Support for PHP and Blade Files](https://cdn.msaied.com/511/9a507c942d0051cc70a4c6769b27f734.png) Laravel Zed LSP 

### Official Laravel Zed Extension: LSP Support for PHP and Blade Files

The Laravel team has released an official Zed extension (v0.1.0) that wires Laravel LSP into the editor, bring...

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

 4 Aug 2026     3 min read  

  Read    

 ](https://msaied.com/articles/official-laravel-zed-extension-lsp-support-for-php-and-blade-files) [ ![Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD in Laravel 13](https://cdn.msaied.com/512/4b4bedfc34f26b38c69fed3a3b5813e9.png) Laravel SEO Open Graph 

### Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD in Laravel 13

Laravel Head is a new first-party package that gives you a fluent API for titles, meta descriptions, Open Grap...

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

 4 Aug 2026     4 min read  

  Read    

 ](https://msaied.com/articles/laravel-head-manage-meta-tags-open-graph-and-json-ld-in-laravel-13) [ ![PostgreSQL CTEs, Window Functions, and Lateral Joins in Laravel](https://cdn.msaied.com/506/7d5fcddaf6c26c87a749a20b8bdffbfa.png) laravel postgresql sql 

### PostgreSQL CTEs, Window Functions, and Lateral Joins in Laravel

Go beyond basic Eloquent queries. Learn how to leverage PostgreSQL CTEs, window functions, and LATERAL joins d...

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

 4 Aug 2026     1 min read  

  Read    

 ](https://msaied.com/articles/postgresql-ctes-window-functions-and-lateral-joins-in-laravel-4) 

   [  ![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)
