Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

pi-token-killer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pi-token-killer

Token Killer for Pi -- reduce LLM token consumption by 60-90% on common dev commands

latest
Source
npmnpm
Version
0.1.6
Version published
Maintainers
1
Created
Source

pi-rtk -- Token Killer for Pi

pi-rtk

Token Killer for Pi -- cut LLM token consumption by 60-90% on common dev commands

npm version npm downloads CI License: MIT TypeScript PRs Welcome

Install · Quick Start · How It Works · Features · Filters · Contributing

A Pi extension that intercepts tool output and strips noise before the LLM sees it. Pure TypeScript, no binary dependency. Uses Pi's tool_call/tool_result hooks to filter output in-process.

Install

pi install npm:pi-token-killer

That's it. RTK activates automatically on your next session.

Quick Start

Once installed, pi-rtk works transparently. When the LLM runs git status and gets back 2,400 tokens of output, pi-rtk compresses it to ~320 tokens:

# Before (raw git status -- 2,400 tokens)
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   src/foo.ts
        modified:   src/bar.ts
        new file:   src/baz.ts
...

# After (pi-rtk filters it -- 320 tokens)
📌 main (up to date)
✅ Staged: 3 files
   src/foo.ts  src/bar.ts  src/baz.ts
❓ Untracked: 1 files
   new-file.txt

The LLM gets all the information it needs with 87% fewer tokens.

How It Works

pi-rtk hooks into Pi's extension API at two points:

  • tool_call -- Stores the command being executed (e.g., git diff, bun test) by toolCallId.
  • tool_result -- Receives the raw output, matches it against 22 filter modules, applies the matching filter, tracks savings in SQLite, and returns the compressed output.
LLM requests "git diff"
  → Pi fires tool_call → RTK stores command
  → Bash executes git diff → 8,000 tokens of output
  → Pi fires tool_result → RTK matches git-diff filter
  → Filter compresses to ~1,600 tokens (80% reduction)
  → LLM sees compact diff with stat summary + key hunks
  → SQLite records: 8000 raw → 1600 filtered
  → Status footer updates: "rtk ~6Kt"

Safety: if any filter throws, RTK passes through the raw output unchanged. The LLM never loses information.

Tee Recovery

When a command fails (non-zero exit), RTK saves the raw unfiltered output to ~/.pi/agent/rtk/tee/ and appends a hint:

[full output: ~/.pi/agent/rtk/tee/2026-03-17_001234_git-diff.txt]

The agent can read this file if the filter was too aggressive.

Features

  • 22 filter modules covering git, directory listings, test runners, linters, grep, JSON, Docker, package managers, HTTP, file reads, and log dedup
  • Post-execution filtering -- works on actual output, not predicted format
  • Read tool filtering -- strips comments from source files, extracts JSON schemas
  • SQLite analytics -- tracks every filtered command with raw/filtered token counts
  • Tee recovery -- saves raw output on failures so the agent can recover
  • TUI settings panel -- toggle filters, configure tee, per-project or global
  • Status footer -- shows cumulative session savings in the Pi status bar
  • Zero config -- works out of the box with sensible defaults
  • Config layers -- env vars > settings.json > defaults

Filter Reference

FilterCommandsWhat It DoesTypical Savings
git-statusgit statusEmoji-grouped compact output with branch tracking87%
git-diffgit diffStat summary + compact hunks with file:line headers80%
git-loggit logOneline format, max 20 commits, 80-char truncation92%
git-actiongit push/pull/fetch/add/commitSingle "ok" summary line95%
git-branchgit branchCompact branch list with current marker75%
lsls, find, fd, tree, ezaDirectory grouping, noise hiding, extension summary80%
test-jsbun test, vitest, jest, npm testPass/fail summary, failing test names + first error line95%
test-pypytest, python -m pytestPass/fail summary with failure details90%
test-rscargo testPass/fail summary85%
test-gogo testPass/fail summary85%
lint-tsctsc, bunx tscErrors grouped by TS code, 5 per group cap87%
lint-jseslint, biomeErrors grouped by rule, suggestion stripping70%
lint-pyruffErrors grouped by rule code75%
lint-rscargo clippy, cargo buildWarnings grouped by lint name80%
greprg, grepFile grouping, match capping, dedup, summary84%
json-schemaJSON file readsType replacement, array/object collapse, max depth 393%
docker-listdocker ps, docker imagesCompact table with short IDs80%
docker-logsdocker logsLog dedup with line collapsing90%
npm-installbun/npm/pnpm/yarn installSingle summary line, preserves vulnerability warnings90%
pip-installpip installSingle summary line90%
read-filterFile reads via read toolComment stripping per language, preserves doc comments60%
log-dedupAny output with repeated linesConsecutive line collapsing with (xN) suffix70%
httpcurl, wget, xhStatus code + response summary80%

Commands

/rtk gain [period]

Shows a token savings dashboard with per-filter breakdown, bar charts, and totals.

RTK Token Savings -- All time

Command          Runs  Raw      Filtered  Saved
──────────────────────────────────────────────────
git diff           12  45.2K    8.1K      82%  ████████░░
git status         28   8.4K    2.1K      75%  ███████░░░
bun test            6  32.0K    3.2K      90%  █████████░
──────────────────────────────────────────────────
Total              46  85.6K   13.4K      84%

Session: ~72K tokens saved

Periods: 24h, 7d, 30d, all (default).

/rtk discover

Finds commands that ran without filtering and estimates how much they could save:

RTK Discover -- Missed Optimization Opportunities

These commands ran without filtering and could save tokens:

  cargo build (ran 4x, ~12K tokens each) -> lint-rs filter would save ~80%
  docker compose up (ran 2x, ~8K tokens) -> docker-compose filter would save ~90%

Estimated additional savings: ~52K tokens/session

/rtk settings

Opens a TUI overlay panel where you can toggle individual filter groups, configure tee recovery, and switch between project and global scope.

Configuration

pi-rtk stores settings in Pi's settings.json under the rtk key. Project settings override global settings, and environment variables override both.

Settings file

Global: ~/.pi/agent/settings.json Project: .pi/settings.json

{
  "rtk": {
    "enabled": true,
    "filters": {
      "git": true,
      "ls": true,
      "test": true,
      "lint": true,
      "grep": true,
      "json": true,
      "docker": true,
      "npm": true,
      "read": true,
      "logDedup": true,
      "http": true
    },
    "tee": {
      "enabled": true,
      "mode": "failures",
      "maxFiles": 20,
      "maxFileSize": 1048576
    },
    "minOutputChars": 100,
    "excludeCommands": [],
    "debugMode": false
  }
}

Environment variables

VariableDescription
RTK_ENABLED0/1 -- master kill switch
RTK_FILTER_GIT0/1 -- toggle git filter group
RTK_FILTER_LS0/1 -- toggle ls filter group
RTK_FILTER_TEST0/1 -- toggle test filter group
RTK_FILTER_LINT0/1 -- toggle lint filter group
RTK_FILTER_GREP0/1 -- toggle grep filter group
RTK_FILTER_JSON0/1 -- toggle json filter group
RTK_FILTER_DOCKER0/1 -- toggle docker filter group
RTK_FILTER_NPM0/1 -- toggle npm filter group
RTK_FILTER_READ0/1 -- toggle read filter group
RTK_FILTER_LOG_DEDUP0/1 -- toggle log dedup filter group
RTK_FILTER_HTTP0/1 -- toggle http filter group
RTK_TEE_ENABLED0/1 -- toggle tee recovery
RTK_TEE_MAX_FILESMax tee files to keep (default: 20)
RTK_TEE_MAX_FILE_SIZEMax file size in bytes (default: 1048576)
RTK_MIN_OUTPUT_CHARSMin output length to filter (default: 100)
RTK_DEBUG0/1 -- enable debug notifications

excludeCommands

Array of substring patterns. Commands matching any pattern skip filtering:

{
  "rtk": {
    "excludeCommands": ["my-special-script", "cat /etc/"]
  }
}

Interaction with pi-lcm

pi-rtk and pi-lcm are complementary:

  • pi-rtk reduces the size of each message entering the context (fewer tokens per tool result)
  • pi-lcm manages what happens when the context window fills up (hierarchical DAG summarization)

Together, a session that would normally burn through 200K tokens and lose everything after compaction instead uses ~40K tokens (pi-rtk) and preserves everything via searchable DAG (pi-lcm).

Install both:

pi install npm:pi-lcm npm:pi-rtk

Architecture

pi-rtk/
├── index.ts                    # Extension entry point, event wiring
├── src/
│   ├── pipeline.ts             # tool_call/tool_result handler logic
│   ├── matcher.ts              # Command pattern matching
│   ├── config.ts               # Config resolution (env > settings > defaults)
│   ├── settings.ts             # Load/save from Pi's settings.json
│   ├── settings-panel.ts       # TUI overlay for /rtk settings
│   ├── tracker.ts              # SQLite analytics (record/query savings)
│   ├── tee.ts                  # Raw output recovery on failure
│   ├── gain.ts                 # /rtk gain dashboard formatting
│   ├── discover.ts             # /rtk discover opportunity analysis
│   ├── utils.ts                # ANSI stripping, token estimation, helpers
│   ├── db/
│   │   ├── connection.ts       # SQLite connection management
│   │   └── schema.ts           # Table migrations
│   └── filters/
│       ├── index.ts            # Filter registry (22 filters, first-match)
│       ├── git-status.ts       # git status -> compact emoji format
│       ├── git-diff.ts         # git diff -> stat + compact hunks
│       ├── git-log.ts          # git log -> oneline, max 20
│       ├── git-action.ts       # push/pull/fetch/add/commit -> "ok" line
│       ├── git-branch.ts       # branch list -> compact
│       ├── ls.ts               # ls/find/fd/tree -> grouped
│       ├── test-js.ts          # bun/vitest/jest -> pass/fail summary
│       ├── test-py.ts          # pytest -> pass/fail summary
│       ├── test-rs.ts          # cargo test -> pass/fail summary
│       ├── test-go.ts          # go test -> pass/fail summary
│       ├── lint-tsc.ts         # tsc -> grouped by error code
│       ├── lint-js.ts          # eslint/biome -> grouped by rule
│       ├── lint-py.ts          # ruff -> grouped by rule
│       ├── lint-rs.ts          # clippy/build -> grouped
│       ├── grep.ts             # rg/grep -> grouped by file
│       ├── json-schema.ts      # JSON -> schema extraction
│       ├── docker.ts           # docker ps/images/logs
│       ├── npm-install.ts      # package install -> summary
│       ├── read-filter.ts      # Comment stripping for file reads
│       ├── log-dedup.ts        # Repeated line collapsing
│       └── http.ts             # curl/wget -> status + summary
└── test/                       # 24 test files, 754 tests

Contributing

See CONTRIBUTING.md for development setup, test commands, and PR guidelines.

License

MIT

Keywords

pi-package

FAQs

Package last updated on 02 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts