pi-mono-context-guard
v1.6.0
Published
Pi extension that guards context window growth by auto-limiting read and rg output
Readme
context-guard extension
Keeps pi sessions lean by preventing common context-window waste during tool use.
What it does
This extension intercepts tool calls and applies three safeguards:
Auto-limit
readcalls
If the model callsreadwithout alimit,context-guardinjects a default limit of120lines and shows a notification. The model can continue withoffsetto paginate.Deduplicate unchanged
readcalls
If the same file is read again with the sameoffsetandlimit, and the file has not changed on disk, the extension blocks the duplicate read and returns a short stub instead of sending the file content again.Bound raw
rgoutput inbash
If abashcommand usesrgwithout an output-bounding operator such ashead,tail, orwc, the extension appends| head -60automatically.
Why it helps
These guards reduce unnecessary token usage and make it harder for long sessions to burn context on repeated or unbounded file output.
Current defaults
readauto-limit:120rghead limit:60- read guard: enabled
- read dedup guard: enabled
- raw
rgguard: enabled
Read dedup behavior
The dedup cache is scoped to the current session.
A cached read entry is only reused when all of the following are true:
- the same file path is requested
- the same
offsetis requested - the same
limitis requested - the file's modification time has not changed
When a file changes, the cache entry is invalidated. The extension also listens for the context-guard:file-modified event so companion extensions such as multi-edit can evict stale cache entries immediately after writes.
Example behaviors
read without a limit
Input:
{ "path": "src/index.ts" }Effective call:
{ "path": "src/index.ts", "limit": 120 }Duplicate read of an unchanged file
Instead of re-sending the file contents, the extension returns a short message telling the agent to reuse the earlier read result.
Raw rg inside bash
Input:
rg "TODO" srcEffective command:
rg "TODO" src | head -60Files
index.ts— extension entry pointpackage.json— package metadataCHANGELOG.md— release history
