Pi coding-agent extension that mirrors the pi-context-prune pattern, but targets assistant thinking blocks instead of toolResult messages.
It keeps the session JSONL file intact. Pruning only changes future LLM context through Pi's context event.
- Detects assistant message content blocks where
type === "thinking". - Stores the original full thinking text in a persistent local index.
- Summarizes the thinking blocks with a configured model.
- Appends a hidden
thinking-prune-summarycustom message that participates in LLM context. - Removes indexed raw thinking blocks from future context windows.
- Registers
thinking_tree_queryso the agent can recover originals by short refs liketh1.
Before pruning:
{
"role": "assistant",
"content": [
{ "type": "thinking", "thinking": "raw reasoning..." },
{ "type": "text", "text": "visible answer" }
]
}Future context after pruning:
{
"role": "assistant",
"content": [
{ "type": "text", "text": "visible answer" }
]
}The model also sees a hidden summary message with refs:
Summarized thinking refs: `th1`, `th2`
Use `thinking_tree_query` with these refs to retrieve the original full thinking blocks.
Local validation:
pi install -l /path/to/pi-thinking-pruneFrom GitHub:
pi install -l git:github.com/ch0udry/pi-thinking-pruneTry without installing:
pi -e /path/to/pi-thinking-prune/thinking-pruner settings
/thinking-pruner status
/thinking-pruner on
/thinking-pruner off
/thinking-pruner now
/thinking-pruner model [default|provider/model-id]
/thinking-pruner model provider/model-id:low
/thinking-pruner thinking [default|off|minimal|low|medium|high|xhigh]
/thinking-pruner min-raw-chars [1000]
/thinking-pruner prune-on [every-turn|on-demand|agent-message]
/thinking-pruner batching [turn|agent-message]
/thinking-pruner tree
/thinking-pruner stats
/thinking-pruner help
Retrieves original thinking blocks that were summarized and pruned.
Input:
{
"thinkingIds": ["th1", "th2"]
}Stored globally at:
~/.pi/agent/thinking-prune/settings.json
Default:
{
"enabled": false,
"showStatusLine": true,
"summarizerModel": "default",
"summarizerThinking": "default",
"pruneOn": "agent-message",
"batchingMode": "turn",
"minRawCharsToPrune": 1000,
"skipOversizedSummary": true
}minRawCharsToPrune defaults to 1000, so small thinking blocks are ignored by default. Change it with /thinking-pruner min-raw-chars 1000, or from /thinking-pruner settings by opening Minimum raw chars and typing a number. skipOversizedSummary defaults to true, matching pi-context-prune: if a generated summary is larger than the raw thinking it would replace, the extension skips indexing/pruning that batch and advances a local thinking-prune-frontier so it is not summarized repeatedly.
Lifecycle behavior also mirrors pi-context-prune: pending batches are restored on summarizer/persistence failure, final-message auto flush uses session delivery, manual/runtime flush can inject hidden steer messages, and stale extension contexts return a stale-context result instead of corrupting state.
enabled defaults to false for safety. Run:
/thinking-pruner on
| Mode | Meaning |
|---|---|
agent-message |
Summarize/prune when the agent sends a final assistant text response. Recommended default. |
every-turn |
Summarize/prune after every assistant message with thinking. Useful for testing. |
on-demand |
Never auto-prune. Use /thinking-pruner now. |
Raw thinking is sent once to the configured summarizer model. Future main-model calls receive only the summary plus visible assistant text.
For local-only summarization, set:
{
"summarizerModel": "local-provider/model-id"
}npm install
npm test
npm run checkpi-context-prune prunes entire toolResult messages.
pi-thinking-prune prunes only thinking blocks inside assistant messages and keeps assistant text/tool calls intact.