pi-compact is a Pi package for scheduling future context compactions by rule.
Instead of only compacting immediately, it lets Pi compact:
- after this task
- after N turns
- when context usage crosses a threshold
- after
agent_end - after
turn_end - after a specific tool call
pi install git:github.com/williamleong/pi-compactThen reload Pi:
/reload
- tool:
compact_control - commands:
/compact-after <when>/compact-rules/compact-clear [id|all]
- skill:
pi-compact
Natural language:
compact after this taskcompact after 3 turnscompact when context > 80%compact after tool bashwhat compact rules are active?clear compact rule 2
Direct commands:
/compact-after this task
/compact-after 2 turns
/compact-after context > 75%
/compact-after tool read
/compact-rules
/compact-clear 1
/compact-clear all
this taskthis turnN turnscontext > N%agent_endturn_endtool <name>
this task,this turn,agent_end,turn_end, andtool <name>are one-shot rules.N turnscounts down at eachturn_endand fires once.context > N%remains active until cleared.- tool-triggered rules are armed when the tool is observed, then compact safely at
turn_end. - compaction runs at safe checkpoints rather than in the middle of a tool execution.
Useful checks:
npm run check
npm testMIT