CPX 2.0: Run Composer Packages Without Installing Them | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://www.msaied.com/public) - [Home](https://www.msaied.com/public)
- [Projects](https://www.msaied.com/public/projects)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [About](https://www.msaied.com/public#about)

           [  Contact](https://www.msaied.com/public#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://www.msaied.com/public)
- [ProjectsCase studies](https://www.msaied.com/public/projects)
- [ArticlesEngineering notes](https://www.msaied.com/public/articles)
- [CertificatesCredentials](https://www.msaied.com/public/certificates)
- [AboutHow I work](https://www.msaied.com/public#about)
- [ContactGet in touch](https://www.msaied.com/public#contact)

  [Start a conversation](https://www.msaied.com/public#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://www.msaied.com/public)
2. /
3. [Articles](https://www.msaied.com/public/articles)
4. /
5. [Laravel](https://www.msaied.com/public/articles?category=laravel)
6. /
7. CPX 2.0: The Composer Package Executor for PHP

   [Laravel](https://www.msaied.com/public/articles?category=laravel) [Composer Pacakge](https://www.msaied.com/public/articles?category=composer-pacakge) 

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

 CPX is a CLI tool that runs any Composer package without installing it in your project—think npx for PHP. Version 2.0 brings local binary resolution, user-defined aliases, a REPL, and AI-agent-aware JSON output.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://www.msaied.com/public#person) Published 30 Jul 2026 · Updated 1 Aug 2026 · 4 min read

ShareCopy linkCopied

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

  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)

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

- [CPX](https://www.msaied.com/public/articles?search=CPX)
- [Composer](https://www.msaied.com/public/articles?search=Composer)
- [PHP CLI](https://www.msaied.com/public/articles?search=PHP%20CLI)
- [Laravel](https://www.msaied.com/public/articles?search=Laravel)
- [Developer Tools](https://www.msaied.com/public/articles?search=Developer%20Tools)

 Frequently asked questions 
---------------------------

  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.

   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.

   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.

   ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)About the author
----------------

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

[About](https://www.msaied.com/public#about) [GitHub ↗](https://github.com/EG-Mohamed) [LinkedIn ↗](https://www.linkedin.com/in/msaiedm/) [WhatsApp ↗](https://wa.me/201094619204) [Email Address ↗](mailto:hello@msaied.com) [My CV ↗](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)  

   [Previous articleEverything Announced at Laracon US 2026: Laravel Framework, Cloud &amp; AI Updates](https://www.msaied.com/public/articles/everything-announced-at-laracon-us-2026-laravel-framework-cloud-ai-updates) [Next articleLaravel AI SDK Adds Human-in-the-Loop Tool Approval](https://www.msaied.com/public/articles/laravel-ai-sdk-adds-human-in-the-loop-tool-approval)  

   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)

 ###  Have a technical challenge?

 Tell me what you’re building. I reply within two working days.

[Start a conversation](https://www.msaied.com/public#contact) 

   Related articles
-----------------

 [ ![](https://cdn.msaied.com/740/cce86edc21eddcbdd2f2454fadaf9c70.png)  · 3 min read### The Pipeline Pattern in Laravel: Custom Pipelines Beyond Middleware

5 Oct 2026 ](https://www.msaied.com/public/articles/the-pipeline-pattern-in-laravel-custom-pipelines-beyond-middleware-1) [ ![](https://cdn.msaied.com/739/2d6897fdcdcf090613f96f72a64b8a78.png)  · 4 min read### MySQL Full-Text Search in Laravel: Indexes, Relevance Scoring, and Boolean Mode

4 Oct 2026 ](https://www.msaied.com/public/articles/mysql-full-text-search-in-laravel-indexes-relevance-scoring-and-boolean-mode) [ ![](https://cdn.msaied.com/738/073696a3fefe18bec825beec5ac658f5.png)  · 4 min read### Laravel Queue Rate-Limited Middleware: Throttling Jobs Without Losing Work

4 Oct 2026 ](https://www.msaied.com/public/articles/laravel-queue-rate-limited-middleware-throttling-jobs-without-losing-work) 

  Have a technical challenge?
----------------------------

Tell me what you’re building. I reply within two working days.

 [Discuss your project ↗](https://www.msaied.com/public#contact) 

  © 2026 Mohamed Said · Built with Laravel, meant to last.Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

 - [Home](https://www.msaied.com/public)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [GitHub](https://github.com/EG-Mohamed)
- [LinkedIn](https://www.linkedin.com/in/msaiedm/)
- [WhatsApp](https://wa.me/201094619204)
- [Email Address](mailto:hello@msaied.com)
- [My CV](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
- [Sitemap](https://www.msaied.com/public/sitemap.xml)
