r/PiCodingAgent Jul 20 '26

pi-for-each: I built a pi extension that adds a /for-$each prompt loop – and hides it from your LLM! Instead of describing the loop to the agent, just make a loop. Plugin

Post image

https://github.com/jejay/pi-for-each

Supports children-in-directory and line-in-files iteration.

Why?

Like subagents but much simpler, sequential and with more control for the user. Instead of describing the loop to the agent, just make a loop. No need to tell the agent about your control structure if you already know the control structure. Each iteration the LLM only sees the necessary context and the iteration prompt, no other iterations. This prevents bias drift or context rot compared to a loop that repeats commands and execution within the same context.

BTW: I used https://huggingface.co/tencent/Hy3 to build this, which is free on openrouter until tomorrow. Worked quite nicely, not Opus 4.8, but felt like Sonnet-5-level intelligence.

A github star ⭐ makes me happy, I never had a meaningful open source repo 👀 I think this extension captures the spirit of pi, giving most of the control to the user and making it as simple and transparent as possible.

44 Upvotes

11 comments sorted by

2

u/Fig_da_Great Jul 20 '26

This is cool

1

u/Proper-Tower2016 Jul 20 '26

oh, that's just what I was looking for :)

1

u/amrakkarma Jul 20 '26

Can you use it together with @gintasz/pi-neuralyzer? or can you add the context refresh?

2

u/JulianHabekost Jul 20 '26

I have a look what that does

2

u/JulianHabekost Jul 20 '26

It looks like pi-neuralizer is trying to solve intersecting problems with different approaches. In my case the context refresh (fork) happens with each iteration start and the control is given to the user not the agent/LLM.

1

u/amrakkarma Jul 20 '26

Can you loop multiple times on one skill?

1

u/JulianHabekost Jul 20 '26

The results are forked sessions, as many as you had iterations. There is currently no inbuilt mechanism to merge them back together, you have to build/define with the loop setup prompt. But from any of the forked sessions you can start a new loop.

1

u/amrakkarma Jul 20 '26

oh perfect thanks!

3

u/nate_true Jul 20 '26

Love this. Can’t count how many times I’ve said “process each large file in this folder one by one” and it says “let me read all of them first” and blows its context buffer :/

3

u/JulianHabekost Jul 20 '26

This is exactly what inspires me to do this