Why must the read tool be executed before the edit tool
Question
I've read the description of the edit tool and found it states: "You must use your Read tool at least once in the conversation before editing." I wonder, if a file is created by AI and its content is already present in the context, would using the Read tool again unnecessarily increase token costs?
This issue might be a duplicate of existing issues. Please check:
- #4405: Exact same title and question about read tool requirement before edit tool and token cost concerns
Feel free to ignore if none of these address your specific case.
@mooneal I think you accidentally created the same issue twice (#4405).
@mooneal we should handle that case, currently unhandled should be an easy fix
Couldn't reproduce. Are we sure it happens?
Write tool seems to mark the file as read after creating it: https://github.com/sst/opencode/blob/5d25758400e546775f7300dc883b0e039df303e9/packages/opencode/src/tool/write.ts#L75
Thanks for jumping in @renanliberato
@mooneal can you provide reproduction steps?
Main thing I can think of is that we store the file read time in memory so If the llm reads a file, I quit, restart, then it tries to edit, it will be forced to read again (annoyingly)
Happens for me too, can we just have an option of disabling it? as tokens are being wasted. The error "You must use your Read tool at least once in the conversation before editing." appears when the model is attempting to edit a file again. I simply use Opencode as usual; I don't have a replication step. look at the attached image, the time diff between last read and edited is 0.2 seconds
Yeah we could add some flag to disable that, I think often you'll find it saving tokens since the LLM is forced to re-read and makes it less likely to corrupt the file.
Ofc that's the idea behind it at least
took a stab at this.
Oh, across sessions, nice @rodnnnney