New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

pi-codex-compaction

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pi-codex-compaction

Use OpenAI Codex RemoteCompactionV2 for supported Pi sessions.

Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

pi-codex-compaction

Keep long Pi sessions usable on OpenAI Codex models by replacing Pi's local summary request with Codex's provider-side RemoteCompactionV2 checkpoint when the current model supports the Codex Responses API.

Features

  • Uses the current openai-codex model for each compaction; it never silently changes the session model.
  • Sends only the history Pi is discarding, plus the previous Codex checkpoint, so the incoming/kept user message is not duplicated.
  • Retains the normal Codex Responses request envelope, including system instructions, active tool schemas, reasoning settings, prompt-cache fields, and routing fields.
  • Persists Codex's opaque encrypted checkpoint and rehydrates it only for supported Codex requests.
  • Reuses checkpoints only for the same model, trusted endpoint, Codex account, and authentication mode.
  • Bounds input with a UTF-8-aware token estimate, trims tool output when necessary, retries transient failures, and honors cancellation.
  • Falls back to standard Pi compaction on failure or when custom compaction instructions are requested.
  • Keeps a bounded readable transcript excerpt so switching models or providers remains usable.

The current Codex catalog includes gpt-6-astra, gpt-5.6-sol, gpt-5.6-terra, and gpt-5.6-luna. Capability detection follows the provider/API contract (openai-codex + openai-codex-responses) rather than a brittle model-name list. Use Pi 0.85.1 or later.

Installation

pi install npm:pi-codex-compaction

For local development:

pi install /path/to/pi-mono/packages/pi-codex-compaction

Or load it for one run:

pi -e /path/to/pi-mono/packages/pi-codex-compaction

Behavior

When Pi starts compaction on a supported Codex model, the extension sends a streamed Responses request whose input contains only discardable history, any compatible prior checkpoint, and a compaction_trigger item. The normal request envelope is retained because Codex's compaction path is parity-tested against ordinary Responses requests; this includes the effective system prompt, active tool definitions, reasoning level, prompt-cache fields, and routing fields. The request uses the remote_compaction_v2 beta feature, and the returned opaque checkpoint and bounded provider usage are stored in the Pi compaction entry. Later requests rehydrate the raw checkpoint only when the model, endpoint, account, and authentication mode match; other providers/models receive the bounded textual fallback instead.

Compaction uses the model active when Pi triggers it. If a session switches from a larger to a smaller model, the remote request is bounded against the new model's context window and tool outputs are reduced before sending. A previous opaque checkpoint is treated as incompatible after a model, endpoint, account, or authentication-mode switch; Pi's readable previous summary is sent instead. If the full request still cannot fit, the extension leaves compaction to Pi's normal implementation.

If the remote request fails, is cancelled, or returns an unexpected response, Pi's standard compaction path runs. Custom compaction instructions also use Pi's standard path because RemoteCompactionV2 has no documented custom-instructions field. The direct checkpoint request is restricted to https://chatgpt.com, rejects redirects, limits request/response size, and never decodes or logs encrypted_content. No configuration is required.

Development

Other Codex extensions

With pi-fast installed, direct compaction requests use the current Fast toggle. With pi-codex-tools installed, apply_patch keeps its raw grammar definition, custom-tool calls, and custom-tool results during compaction. Neither package is required. No package reads a private Pi tool registry. With pi-openai-reasoning installed, verified Astra requests keep the original request effort and receive the current effort as a configuration update. Failed compaction does not change saved reasoning state.

Pi 0.85.1 does not expose grammar metadata in getAllTools(). Two synchronous, versioned pi.events contracts let cooperating extensions supply it:

  • pi-codex-compaction:tools:v1: { model, tools }, before provider serialization. A tool owner can attach its own constrainedSampling metadata.
  • pi-codex-compaction:request:v1: { ctx, messages, payload }, after input assembly and before size checks. A listener can replace payload. This event is not the general before_provider_request chain and does not carry auth.

Other extensions' private request changes are not applied automatically. Unknown third-party grammar metadata needs cooperation through the tools event. The checkpoint entry includes standard Pi usage, including cache reads and cache writes, as well as the original bounded token counters in details. Costs follow Pi's catalog estimates. They are not a ChatGPT subscription bill.

Reference and smoke test

Behavior was checked against openai/codex commit 654b0a77d0d2f81aa21f61caf7af4be88fe550bb (2026-09-11), notably core/src/compact_remote_v2{,_attempt}.rs. No Codex code was copied. RemoteCompactionV2 is a changing Codex protocol, not the public /responses/compact API. Async tools and mid-turn steering require upstream Pi support.

For a small live test, load this package and select openai-codex/gpt-6-astra. Send two short messages, run /compact, then ask about the first message. Repeat with /fast on and pi-codex-tools loaded. Check that compaction succeeds, the continuation retains context, and session usage includes compaction tokens. Use only a temporary file if you test apply_patch. Do not generate images.

npm install
npm run -w packages/pi-codex-compaction check
npm test -w packages/pi-codex-compaction
npm run -w packages/pi-codex-compaction pack:dry-run

Keywords

pi-package

FAQs

Package last updated on 11 Sep 2026

Related posts