Does the position of an earlier file read in context matter — is denying a later re-read of the same file a mistake? #202557
Unanswered
jayakumarn
asked this question in
Copilot Conversations
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🏷️ Discussion Type
Question
💬 Feature/Topic Area
Copilot Agent Mode
Body
Does the position of an earlier file read in context matter — is denying a later re-read of the same file a mistake?
Hi 👋 I'm using a
preToolUsehook on Coding Agent — to cut token use in long agent sessions. I've got the correctness cases covered, and I'm left with one question about context behaviour I can't answer from the outside.What the hook does
When the agent re-reads a file it has already read, my
preToolUsehook denies the read (permissionDecision: "deny") with a reason saying the file is already in context. That avoids re-sending the file to the model and saves tokens.So the only case my hook denies is: the file is unchanged and still in context.
What I already handle
The case I'm unsure about
Here's a concrete example. The agent reads some file — call it
config.py— early on. Many turns of other work go by. Then, for a different purpose than the first read, it reads that same file again. It hasn't changed and hasn't been evicted, so my hook denies it.My worry: the earlier copy is now sitting far back in context, and models attend less reliably to content deep in a long context ("lost in the middle"). So the re-read might be the model deliberately pulling the file forward for its current task — not a redundant repeat. If so, denying it could quietly degrade the result even though nothing is technically missing.
Questions
Does read position matter? When a file was read many turns ago but is still in context, is a fresh re-read treated as redundant, or does re-reading meaningfully help by placing the content near the model's current reasoning? Put plainly: is denying a far-back re-read of unchanged content safe, or is it a mistake?
Is a repeat read a deliberate signal? Does the agent tend to re-read a file only when it actually needs the content foregrounded for its current step — in which case a deny works against it?
Context position in the hook input. Does the
preToolUseJSON expose anything I could use to make this call — current context size, token counts, or how far back a previous read sits? I only seetoolName,toolArgs,sessionId,timestamp. If there's a way to tell an earlier read is still near the front vs buried deep, I'd deny only in the “still near the front” case.What the model sees on deny. When
preToolUsedenies a read, ispermissionDecisionReasonfed into the agent's context as feedback it reasons over, or is it only shown to the user / logs?Already checked
The hooks docs and reference. Happy to share the hook script or a small repro. If the honest answer is “don't deny re-reads at all,” that's useful to know too.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions