Compaction
Documentation

Output shaping

Task-aware output shaping injects a content-free instruction before generation, so the model writes the terse version instead of a long one being trimmed after the fact. Measured effect: up to ~50–70% fewer output tokens on coding tasks — measured on real sessions, provider-reported, quality held (eval-gated, task-dependent; methodology on Proof and receipts).

A per-turn classifier decides what to shape: planning, reasoning, and extended-thinking turns are held — the shaping instruction is never injected on those turns. Shaping targets the code/answer bulk where terseness was measured safe.

Output shaping is part of Open: it is the one public deterministic method, it needs no account and no engine, and it is what compaction mode basic turns on. It also keeps running on a Community device after the optimized-input allowance for the period is used up.

Two delivery mechanisms

  • Through the gateway: when a request is routed, the gateway attaches the instruction to the request it forwards.
  • Through your tool’s own hook: where a session can’t route through a proxy, Compaction installs that tool’s native hook and attaches the same instruction there.

Per-tool behavior

  • Claude Code — per-prompt (before-call hook). Planning/thinking turns held. The output-shaping figure above was measured here, on a real A/B with quality held.
  • Codex — per-prompt (UserPromptSubmit hook). Each turn is classified; hold on planning/reasoning turns. The Codex-specific end-to-end effect has not been measured, so no Codex figure is claimed.
  • Cursor — session-level (sessionStart hook). Cursor has no per-prompt injecting hook, so shaping is coarse: one instruction at session start, no per-turn hold. Cursor figures are local-estimate only, never provider-reported, and no Cursor-specific reduction figure is claimed.

Install and remove

Running compaction once installs the right hook for each tool it detects. Directly:

compaction hooks install --tool codex
compaction hooks install --tool cursor
compaction hooks status

Install prints exactly what it will write, merges with (never replaces) existing hook settings, backs up before writing, and supports --dry-run. Uninstall removes only Compaction’s own hooks:

compaction hooks uninstall --tool codex

Default-on, kill-switch, fail-open

  • Once a hook is installed, shaping is on by default (subject to the per-turn hold above). Installing the hook is the consent step.
  • Kill-switch: set COMPACTION_SHAPING_HOOKS=0 to disable shaping, or run compaction stop to turn Compaction off persistently (compaction start re-enables it). Both are read fresh on every turn, so either takes effect immediately.
  • Fail-open: any parse or classification error emits nothing — the prompt goes through unchanged. A broken hook can never break your tool.
  • Content-free: prompt bytes are read only to classify the turn and are never logged, stored, or transmitted; the injected instruction is fixed generic text.

What is not claimed

  • no per-tool savings figure for Codex or Cursor until the end-to-end effect is measured on those tools
  • no bill or cost percentage — the measured effect is on output tokens, with the task-dependence stated