Better Compact
Install ·
Commands ·
How it works ·
Architecture
Edited and maintained by Claude. Provided as-is.
Most coding agents wait until the context is full, then replace the old conversation with one summary. Exact tool output, failed attempts, user wording, and decision history disappear together.
Better Compact reduces context in stages. It removes stale tool traffic and old reasoning first, summarizes selected assistant runs only when needed, and keeps the raw history on disk for recall.
| Plain compaction | Better Compact |
|---|
| One summary replaces the old conversation | Each pruning stage runs only when needed |
| Tool calls and failures lose their structure | Removed tools leave action stubs with status and errors |
| Exact old output is unavailable | Raw history stays on disk with a model-readable reference |
| Every compaction changes the prefix | Validated plans replay the same stable prefix |
Install
Oh My Pi
Requires @better-compact/pi 0.3.1 or newer.
omp plugin install @better-compact/pi
omp plugin doctor
Better Compact handles OMP's manual and automatic compaction. OMP still controls when compaction runs, along with retry, rollback, and accounting.
pi
pi install npm:@better-compact/pi
OpenCode
Requires OpenCode 1.17.13 or newer.
opencode plugin better-compact --global
Restart OpenCode after installation.
Claude Code
Install the CLI:
npm install -g @better-compact/cli
Compact a closed session and reopen it:
better-compact claude <session-id> --resume
Install the companion plugin for /better-compact:compact:
claude plugin marketplace add AshishKumar4/better-compact
claude plugin install better-compact@better-compact
Launch Claude Code through the wrapper to compact and reopen automatically after exit:
better-compact claude --run
Commands
| Platform | Command | Action |
|---|
| OMP | /better-compact | Run the selected committed compaction |
| pi, OpenCode | /better-compact | Run Better Compact now |
| OMP | /better-compact-report | Show the active plan |
| OMP, pi, OpenCode | /better-compact-settings | Open settings |
| OMP, pi | /better-compact-preset <light|moderate|max> | Change the pruning preset |
| OMP | /better-compact-mode <better-compact|omp> | Choose the owner for new sessions |
| OpenCode | /better-compact context | Show context usage |
| OpenCode | /better-compact stats | Show the active plan |
| Claude Code | /better-compact:compact | Queue compaction for session exit |
Presets
| Preset | Trigger | Target | Recent tool budget |
|---|
light | 85% | 35% | 40k tokens |
moderate | 75% | 25% | 30k tokens |
max | 60% | 15% | 12k tokens |
The trigger starts a pruning pass. The target is the desired context size after the pass.
For pi and OMP, create <agent-dir>/better-compact.json: