PHPackages                             papi-ai/rtk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. papi-ai/rtk

ActiveLibrary

papi-ai/rtk
===========

RTK token-optimisation proxy adapter for PapiAI

v0.11.0(yesterday)00MITPHP ^8.2

Since Jul 19Compare

[ Source](https://github.com/papi-ai/rtk)[ Packagist](https://packagist.org/packages/papi-ai/rtk)[ RSS](/packages/papi-ai-rtk/feed)WikiDiscussions Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

papi-ai/rtk
===========

[](#papi-airtk)

RTK token-optimisation proxy adapter for [PapiAI](https://papi-ai.org).

Wraps the [RTK](https://github.com/rtk-ai/rtk) CLI (a proxy that compresses verbose developer output before it reaches an LLM) behind PapiAI's `LLMTokenOptimisationProxyInterface`, so agents and tools can shrink tool/command output — often by 60–90% — before it enters the context window.

Install
-------

[](#install)

```
composer require papi-ai/rtk
```

Requires `papi-ai/papi-core` `^0.11` and the [`rtk`](https://github.com/rtk-ai/rtk) binary on your `PATH` (`brew install rtk`, or see the RTK install docs).

Usage
-----

[](#usage)

```
use PapiAI\Rtk\RtkProxy;

$rtk = new RtkProxy();               // or new RtkProxy('/custom/path/to/rtk')

// Compress captured text (e.g. a tool's stdout) through a named RTK filter
$result = $rtk->optimise($grepOutput, ['filter' => 'grep']);
echo $result->optimised;             // compact text
echo $result->savingsPercent();      // e.g. 62.5

// Or run a read-only command through RTK's specialised filter and measure the saving
$result = $rtk->optimiseCommand('git status');
echo $result->tokensBefore, ' -> ', $result->tokensAfter;
```

Use it inside a tool so a command's output is compressed before it re-enters the agent's context:

```
use PapiAI\Core\Tool;

$tool = Tool::make(
    name: 'git_status',
    description: 'Show the working tree status, token-optimised',
    parameters: [],
    handler: fn () => (new RtkProxy())->optimiseCommand('git status')->optimised,
);
```

API
---

[](#api)

`RtkProxy implements LLMTokenOptimisationProxyInterface`:

MethodPurpose`optimise(string $content, array $options = [])`Pipe text through `rtk pipe` (`filter`, `ultraCompact` options)`optimiseCommand(string $command, array $options = [])`Run a read-only command through RTK and measure the saving`estimateTokens(string $content)`Cheap ~4-bytes-per-token estimateAll return an `OptimisationResult` (`optimised`, `tokensBefore`, `tokensAfter`, `tokensSaved()`, `savingsPercent()`, `strategy`). Token counts are estimates, not a real tokenizer.

> `optimiseCommand()` executes the command (raw, then via RTK) to measure the saving — only pass side-effect-free commands (git status, grep, ls, test runners).

License
-------

[](#license)

MIT © Marcello Duarte

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/70713?v=4)[md](/maintainers/md)[@md](https://github.com/md)

###  Code Quality

TestsPest

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/papi-ai-rtk/health.svg)

```
[![Health](https://phpackages.com/badges/papi-ai-rtk/health.svg)](https://phpackages.com/packages/papi-ai-rtk)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
