> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel PAO — output optimization for AI agents

> An introduction to laravel/pao. The official Laravel package that compresses PHPUnit, Pest, PHPStan, and Artisan output into JSON in AI agent environments, reducing token consumption by up to 99.8%.

## Introduction

[laravel/pao](https://github.com/laravel/pao) is a package that optimizes the output of PHP development tools for AI agents. **PAO (PHP Agent-Optimized output)** automatically transforms verbose output from PHPUnit, Pest, Paratest, PHPStan, and Laravel Artisan into structured, compact JSON.

As many AI agents including GitHub Copilot have moved to token-based pricing, reducing tool output directly translates to cost savings. PAO is designed to solve exactly this problem and is planned to be included by default in the Laravel starter kits.

```mermaid theme={null}
graph TD
    A["Tool run<br>(PHPUnit/Pest/PHPStan/Artisan)"] --> B{"AI agent<br>environment?"}
    B -->|Yes| C["Compress and emit as JSON"]
    B -->|No| D["Normal output<br>(unchanged)"]
    C --> E["AI agent processes<br>while saving tokens"]
    D --> F["Human reads it as usual"]
```

## Why it matters

As AI agents become deeply embedded in the development flow, tool output token count directly affects cost and response time.

In a project with 1,000 tests, PHPUnit's output can be thousands of lines, but all an AI agent needs is "success/failure, counts, and where things failed." PAO compresses this into a single-digit JSON object.

* **Test output**: up to 99.8% token reduction
* **PHPStan output**: structured JSON containing only what's needed
* **Artisan output**: strips ANSI codes, box-drawing characters, and whitespace for up to 75% reduction

## Installation

Requires PHP 8.3+, PHPUnit 12-13 / Pest 4-5 / Paratest / PHPStan / Laravel 12+.

```bash theme={null}
composer require laravel/pao --dev
```

It works after installation—no further setup. PAO auto-hooks into PHPUnit, Pest, Paratest, and PHPStan via Composer's autoloader. In Laravel projects, the service provider is auto-discovered and Artisan output optimization is also enabled.

<Info>
  PAO only activates when an AI agent environment is detected. When a human runs commands directly in a terminal, it's completely disabled and normal output is preserved.
</Info>

## Supported AI agents

PAO auto-detects the following AI agents.

| Agent          | Detection method                           |
| -------------- | ------------------------------------------ |
| GitHub Copilot | Environment variables like `COPILOT_MODEL` |
| Claude Code    | `CLAUDECODE` or `CLAUDE_CODE`              |
| Cursor         | `CURSOR_AGENT`                             |
| Gemini CLI     | `GEMINI_CLI`                               |
| Devin          | `/opt/.devin` file                         |
| Codex          | Environment variables like `CODEX_SANDBOX` |

## Before / after

### Test output (PHPUnit / Pest)

A 1,000-test suite is transformed like this.

**Before (without PAO)**

```
PHPUnit 12.5.14 by Sebastian Bergmann and contributors.

.............................................................   61 / 1002 (  6%)
.............................................................  122 / 1002 ( 12%)
...
..........................                                    1002 / 1002 (100%)

Time: 00:00.321, Memory: 46.50 MB

OK (1002 tests, 1002 assertions)
```

**After (with PAO)**

```json theme={null}
{
  "tool": "phpunit",
  "result": "passed",
  "tests": 1002,
  "passed": 1002,
  "duration_ms": 321
}
```

Regardless of test count, the output stays a constant size. When tests fail, file paths, line numbers, and failure messages are included.

### Coverage and other plugin output

Additional output from Pest plugins like `--coverage` or `--profile` is stripped of ANSI codes and decorations and included in a `raw` array.

```json theme={null}
{
  "tool": "pest",
  "result": "passed",
  "tests": 1002,
  "passed": 1002,
  "duration_ms": 1520,
  "raw": [
    "Http/Controllers/Controller 100.0%",
    "Models/User 0.0%",
    "Total: 33.3 %"
  ]
}
```

### PHPStan output

```json theme={null}
{
  "tool": "phpstan",
  "result": "failed",
  "errors": 2,
  "error_details": {
    "/app/Http/Controllers/Controller.php": [
      {
        "line": 9,
        "message": "Method Controller::index() should return int but returns string.",
        "identifier": "return.type"
      },
      {
        "line": 14,
        "message": "Call to an undefined method Controller::doesNotExist().",
        "identifier": "method.notFound"
      }
    ]
  }
}
```

### Laravel Artisan output

Command output like `php artisan about` has ANSI codes, box-drawing characters, dot separators, and extra whitespace stripped.

**Before (without PAO) — 2,111 characters**

```
  Environment ................................................................
  Application Name ................................................... Laravel
  Laravel Version ..................................................... 13.3.0
  PHP Version .......................................................... 8.5.4
  Debug Mode ......................................................... ENABLED
```

**After (with PAO) — 535 characters**

```
 Environment ..
 Application Name .. Laravel
 Laravel Version .. 13.3.0
 PHP Version .. 8.5.4
 Debug Mode .. ENABLED
```

Expect up to 75% token reduction for commands like `about`, `db:show`, and `migrate:status`.

## Integration with Laravel starter kits

PAO is planned to be included by default in the Laravel starter kits. Creating a new project will install it automatically, letting you start AI-agent-driven development with lower token costs from day one.

## Summary

`laravel/pao` works just by installing, and activates only in AI agent environments—so it doesn't affect your existing development workflow at all. It's worth adopting in any PHP/Laravel project where you want to reduce AI agent development costs.

<Card title="laravel/pao repository" icon="github" href="https://github.com/laravel/pao">
  Source code and the latest list of supported tools and agents.
</Card>


## Related topics

- [May 2026 Laravel updates](/en/blog/changelog/202605.md)
- [laravel/agent-skills — Laravel's official AI agent skills](/en/blog/agent-skills-introduction.md)
- [Laravel AI SDK](/en/ai-sdk.md)
- [Amazon Bedrock driver for Laravel AI SDK](/en/packages/laravel-amazon-bedrock.md)
- [Creating a Custom Agent for Boost](/en/advanced/boost-custom-agent.md)
