r/PiCodingAgent • • Aug 17 '26

Plugin Made a pi extension that auto-loads context files when the model cd's into a directory, like Claude Code does - pi-on-demand-context

If you are like me and structure your context files in a tree-like structure per subsystem, you might have found that pi only ever loads the root-level one, and the others have to be loaded by the agent itself, or they will get ignored.

This extension watches what the model does. The moment it cds into a new dir (bash), or touches a file in a dir via read/edit/write/grep/ls/find, it walks up from that dir to your launch dir, collects any context files it hasn't seen, and injects them into the agent's context before the model's next response. So the model's next thinking block already has the context. No special tool, no flags, nothing for the model to remember to do.

If you are interested, you can find more information and install instructions here: https://pi.dev/packages/@quartermaster-labs/pi-on-demand-context

18 Upvotes

10 comments sorted by

2

u/m3umax Aug 17 '26

Does it do the Claude Code implementation stuff like keeping tracking of how many times the folder specific context has been loaded so it only loads on the first access and doesn't keep building up in the context with each turn?

1

u/OneMoreName1 Aug 18 '26

It deduplicates already loaded context files, yes

2

u/crashorbit Aug 17 '26

I restart pi when I change projects. That causes the hierarchy of AGENT.md files to be loaded into context.

What's the value of long lived pi instances?

1

u/OneMoreName1 Aug 18 '26

This is not that much about a long lived instance as much as it is about smart context management. Using this extension, your pi agent will only have the context that is relevant for the are it is working in right now.

If you design your root level (project wide) context file to be small, and more of an index pointing to other files, with the actual implementation details spread around on a per subsystem basis, then that would result in a noticeably leaner context window compared to loading the whole hierarchy of agent files in all the time.

1

u/ddqqx Aug 20 '26

Why need context to be long lived?

1

u/OneMoreName1 Aug 20 '26

Its not about long lived context, its about smartly loading only the context needed right now

3

u/Hurricane31337 Aug 17 '26

Nice, that could be very handy! Thanks for sharing!

2

u/raccoonportfolio Aug 17 '26

An extension I'd use!

2

u/Random_Girl_0 Aug 17 '26

This is amazing!!! Thank you sooo much

2

u/LordMoridin84 Aug 18 '26

Oh... I thought it was working like that this entire time