piagent_
← ~/map

$ cat ~/map/pi-loop-guard.md

pi-loop-guard

Stops pi when the model loops — repeated tool-call cycles and repetitive streamed output cut off before they burn tokens.

extensions✓ Nov 8

Facts

repository
github.com/huytd/pi-loop-guard ↗
GitHub Stars
★ 0
Forks
0
license
MIT
npm / mo
—
last push
Nov 7, 2026

install

ln -s ~/code/pi-loop-guard ~/.pi/agent/extensions/pi-loop-guard (auto-discovered globally, hot-reloads with /reload; or try one session with pi -e ~/code/pi-loop-guard/src/index.ts — pi loads the TypeScript source directly, so there is no build step).

## TL;DR

A pi extension that stops the agent when the model gets stuck in a loop: tool-call cycles of one to four calls repeated three times are blocked at the completing call, and repetitive streamed output — a unit repeated at least three times over at least 300 chars, or a line appearing eight times within sixty — aborts the stream so local servers stop generating too.

## Key points

## FAQ

Q When does a loop guard matter most?

The README pins it on small or heavily quantized local models, where the agent getting stuck repeating the same tool call or the same phrase happens often.

Q What happens when a text loop is stopped?

The stream is aborted and the repeated text stays in the session; saying continue may start the loop again, so the README suggests /tree or /fork to branch from before the loop or telling the model what to do differently.

Q Are triggers visible to the model?

No — each trigger is recorded in the session as a loop-guard custom entry, which is not sent to the model.

Q pi keeps polling a service and the guard fires — what do I change?

Raise tool.minRepeats in loop-guard.json; the README names a legitimate repeated polling bash call as the case to tune for.

Q Does the guard check arguments of streamed file writes?

Yes, streamed tool-call arguments are scanned, but with 4x the character threshold and no line check because file contents often repeat lines legitimately.

## References

## Related entries

## Guides

Last updated: Nov 7, 2026