pi-reduce is a Pi package that rebuilds the current branch into a smaller session.
It keeps only the message types you want, drops the rest, and writes the result into a brand new Pi session that you continue from immediately.
No summaries are generated in v1. The reduction is deterministic: keep, drop, and truncate only.
pi install npm:pi-reduceOr from git:
pi install git:github.com/toorusr/pi-reduce/reduce [chat|reasoning|tools|no-tools|advanced|last]/reduce-advanced
chat— keep user messages and final assistant output onlyreasoning— keep user messages, assistant thinking, assistant comments, and final outputtools— keep user messages plus tool calls and tool resultsno-tools— keep user messages plus assistant comments and final outputlast— rerun the last reduce configadvanced— open the full reducer UI
/reduce always starts from the current active branch context. It does not rewrite your source session. Instead it:
- reads the current branch context
- filters messages by type
- optionally filters tools by name
- optionally truncates tool arguments and tool results
- creates a new session
- switches into the new session immediately
The current model and thinking level are copied to the new session.
/reduce-advanced lets you configure:
- user messages
- assistant thinking
- assistant comments from tool-using turns
- assistant final messages
- assistant status / aborted / error messages
- tool calls
- tool results
- user bash executions (
!/!!) - custom / extension messages
- existing branch summaries
- existing compaction summaries
- keep all tools
- keep only selected tools
- exclude selected tools
- tool call approx-token budget
- tool call char budget
- tool call line budget
- tool result approx-token budget
- tool result char budget
- tool result line budget
- head or tail truncation for tool results
The final notification shows a compact before/after summary with:
- context reduction bar
- approximate context tokens before vs after
- kept vs removed messages
- key block reductions (thinking, tool calls, tool results)
- recorded source usage totals
The new reduced session also stores provenance in a reduce-source custom entry.
- Copied messages do not preserve historical assistant usage tags, so the new session starts with
0recorded usage until you continue chatting. - Approximate token counts use Pi's own conservative
chars / 4heuristic. - Tool-result
detailsare replaced with compact reduced metadata so the new session stays light.
npm install
npm run checkFor a quick local test without installing the package:
pi -e /absolute/path/to/pi-reduce