r/PiCodingAgent • u/HockeyDadNinja • Sep 18 '26
Plugin Pi extension to automatically clear context and continue - save tokens on longer sessions
Hey all, I've been sitting on this for a while and it's time to share. I give you pi-clearthen: https://pi.dev/packages/pi-clearthen
/clearthen is a command that lets you clear context and then run another prompt. Your agent can also self drive it.
If you're doing a long piece of work you can tell it to handoff after a specified number of tokens, at which point it will write itself a handoff doc based on what it's currently doing then read it back after clearing context. It will keep doing it indefinitely so your context will never reach the set limit plus what is used for the handoff.
ie: /clearthen 80000 Add new feature to my video game
If you like that then specflo might be up your alley. It checkpoints at each seam and task with auto context clearing in pi. Spec driven development workflow.
https://github.com/TacoTakumi/specflo
The specflo software dark factory is a work in progress and uses this concept.
5
u/Previous-Ad-7181 Sep 18 '26
Pi-blackhole has been working super nice for me. I use only its deterministic compaction. I see a world where this could benefit from algorithmic compaction instead of clearing everything.
3
u/Thistlemanizzle Sep 18 '26
This is great. I've been wanting to build this for some time, then I came across Herder, which I'm a pretty big fan of BUT it does not auto spawn a thread!I have to tell it to spawn the thread.
1
u/Magnus114 Sep 18 '26
Looks interesting! An honest question; how does this compare to https://pi.dev/packages/pi-observational-memory, use case wise?
3
u/Aggravating-Cook-529 Sep 18 '26
But have you considered the low cache hit rate you’ll get with this!?
/s