Same-session, high-fidelity compaction for pi-coding-agent.
/handofffidelity, but it stays in your session — no/new, no restart.
pi-continue-better hooks pi's session_before_compact and replaces the default
summarizer with a curated continuation handoff, then hooks session_compact
to automatically resume the task in the same session — so you don't have to
type "continue" after every compaction. It combines the best ideas
from three community packages into one:
| Source idea | What it contributes here |
|---|---|
pi-continue |
Disciplined 7-slot ledger (task, done_when, established+anchors, learned, open, forbid, next) that accumulates across compactions |
/handoff skill |
Explicit secret/PII redaction + verbatim-quote allowance (preserve exact paths, identifiers, commands, snippets) |
pi-grounded-compaction |
Deterministic files-touched tracking + summarizer model presets |
| this package | A higher tool-result budget than pi's stock 2000-char serialization, so the summarizer actually sees enough of long bash/read outputs to quote them verbatim — the concrete fidelity boost |
Same task, same session, no restart, no manual "continue". It fires on /compact,
on the auto-compaction threshold, and on overflow recovery.
pi install git:github.com/1am2syman/pi-continue-betterUpdate later:
pi update --extension git:github.com/1am2syman/pi-continue-betterTry it once without installing:
pi -e git:github.com/1am2syman/pi-continue-betterThen just run /compact (or let auto-compaction fire). Run /continue-better to
see the active config and the last run.
⚠ Mutual exclusion. This extension owns
session_before_compactand returns its own compaction result. Enable only one compaction-owning extension at a time (pi-continue,pi-grounded-compaction,pi-agenticoding, or this one). Two active at once race and the last handler wins.
/handoff gives you a curated summary but forces a new session. pi-continue
keeps you in the same session but sees messages through pi's stock serializer,
which truncates every tool result to 2000 chars before the summarizer ever sees
it — so long bash/read outputs (often where the critical detail lives) are
already gone. pi-continue-better keeps you in the same session and raises that
budget (default 8000, configurable), then instructs the model to preserve critical
values verbatim and redact secrets. You get /handoff's fidelity without leaving
the session.
Defaults ship in settings.json. Override per-user or per-project
(no code edits needed):
- global:
~/.pi/agent/extensions/pi-continue-better.json - project (wins):
<project>/.pi/extensions/pi-continue-better.json
Your session can run on Opus while compaction runs on Flash:
{ "summarizerModel": "google/gemini-2.5-flash" }Because compaction serializes messages to text first, there is no prefix-cache cost to routing the summary to a cheaper/faster model.
Every compaction produces a structured markdown handoff. The model is required to
emit these sections (full rules in assets/compaction-prompt.md):
## Task — one-sentence active goal
## Done when — one-sentence completion criterion
## Established — anchored facts (path:line / test:name / cmd:... / user@msg-id) + reopen conditions
## Learned — derived insights, preferences, dead ends (with reason)
## Open — unverified questions + what evidence would close them
## Forbid — hard prohibitions + known-bad paths, with attribution
## Next — ordered next actions; next[0] is the immediate resume action
followed by an optional cumulative files-touched manifest and <read-files> /
<modified-files> blocks.
The summarizer fails open. If the summarizer model can't be resolved, auth
fails, the call errors, or the response is empty, it returns nothing and pi falls
back to its built-in compaction. No raw directive text is leaked. Aborts are
honored via the shared signal.
After a successful extension-owned compaction, pi-continue-better injects a
labeled pi-continue-better-resume message with triggerTurn: true so the agent
keeps working in the same session — no manual "continue" needed. This is the
feature pi-continue is known for, now combined with the higher-fidelity
handoff.
Rules:
- Fires after manual
/compactand threshold auto-compaction. - Never fires on
overflow— pi already auto-retries the aborted turn (willRetry: true), so we never double-resume. - Only fires when this extension produced the compaction (
fromExtension: true). - Opt out anytime:
{ "autoResume": false }.
If you'd rather drive compaction yourself and have the agent wait (pi's default),
disable autoResume.
/continue-better
Prints the resolved config, the summarizer model, the tool-result budget, and the last run (ok/failed, reason, message count, error if any).
- It does not patch pi or vendor code.
- It does not fork, switch, or create sessions — that's the point.
- It does not rewrite transcript history or interrupt running tools.
- It is not a memory system or a context pruner; it only customizes compaction.
- It does not auto-load past summaries into future sessions beyond the standard
previousSummarypi passes tosession_before_compact.
pi-continue-better/
├── package.json # npm metadata + pi manifest
├── settings.json # package-local defaults
├── tsconfig.json # typecheck config (no build needed; pi loads .ts)
├── extensions/
│ └── index.ts # the extension (hooks session_before_compact)
├── assets/
│ └── compaction-prompt.md # the 7-slot handoff prompt (redaction + verbatim)
└── examples/
└── settings-compaction-75pct.json
MIT © 1am2syman
{ "enabled": true, // set false to fall through to pi's default compaction "summarizerModel": "inherit", // "inherit" = active session model; or "provider/modelId" // e.g. "google/gemini-2.5-flash" for a cheap compactor "toolResultBudget": 8000, // chars of each tool result fed to the summarizer (pi stock = 2000) "maxTokens": 8192, // summarizer output budget "appendFilesTouched": true, // cumulative files-touched manifest in the summary "appendReadFileTags": true, // <read-files> block (pi-native shape) "appendModifiedFileTags": true, // <modified-files> block (pi-native shape) "redactSecrets": true, // instructs the model + scrubs obvious patterns after "autoResume": true, // after compaction, auto-send a resume prompt so the agent continues "notify": true // info/warning notifications }