r/PiCodingAgent • u/Snoo-56267 • 10h ago
Resource pi-freehand: a pi extension implementing Microsoft's Freehand harness
https://github.com/seandavi/pi-freehandI've been reading Microsoft Research's Freehand paper. The idea is to give a frontier model one bash tool, a tiny prompt, and a cost meter, and get out of its way. They report that this beats harnesses with long prompts and lots of tools, on both score and cost. pi is already pretty lean and is my go-to harness, so I built out Freehand as an extension: pi --freehand gives the model only bash and a ~135-word prompt (by default), and adds a cost/token meter line after every turn showing context, cache share, cost and budget.
One thing I left out on purpose is Freehand's transcript editing. Edits that hit context break the prompt cache, and I'm not convinced they pay for themselves in pi, particularly for interactive sessions. Of course, pi has plugins for context management, anyway. I
I've also found subagents pretty useful, not just for parallel work, but also to help frontier models protect their own contexts. My little addition to Freehand's premise is sub-agent accounting. In Freehand, the model gets help by running pi -p from the shell. pi-freehand passes the mode and the remaining budget down to those child runs. Each child reports its usage back up through stdout, so the parent's meter and your /session totals include everything, at any depth. You can also set a hard dollar budget or a max depth. Not bulletproof, but....
Microsoft is clear to point out that Freehand only provides improvements with high-end frontier models, so use pi-freehand only with frontier models, and keep in mind that it runs everything through bash and has no built-in guardrails besides the model itself.
pi install npm:@seandavi/pi-freehand
Repo: https://github.com/seandavi/pi-freehand
(There's also an unrelated unscoped pi-freehand by u/xiyanzhou that does include transcript editing but not subagent accounting. Both use --freehand, so pick one.)
3
u/backyard_tractorbeam 4h ago
Cool to see that pi was already the best harness (of the other options) in the paper :)
8
u/snow_schwartz 7h ago
Back in the earlier days when the code harnesses were only just starting to get kind of good I had this idea for a “diff changes” circuit breaker built an early claude plugin for it.
The general idea was to limit how much Claude could change and inform it that it was approaching the circuit breaker. This would steer it towards atomic changes and create human reviewable PRs.
Few people adopted it and I didn’t keep working on it because the culture completely shifted away from reading all the code. But the context meter here reminds me of that early project. Thanks for bringing freehand to my attention!
4
u/Androoideka 5h ago
Thanks for this, I also turned off all the tools in my pi besides bash and put a 100 word system prompt cause I had a feeling that they must've been trained on bash and programming languages and that it would give better results. Anecdotally it did so far
I use a custom bash that has different permission tiers (default is sandboxed) and I also use only local models so Ill see if this works for me, but very cool
2
u/Extreme_Perception58 5h ago
v
-5
u/kantorcodes1 9h ago
Passing the remaining budget down to child pi runs, then rolling their usage back into the parent meter, makes the number on screen the whole job. Most meters only count the top run.
I help run the awesome-ai-plugins catalog, a public list people use to find agent tools. pi-freehand would get its own entry there, in front of pi users looking for extensions.
Want a listing?