opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Write Tool includes metadata in output and created filecontent

Open rwese opened this issue 1 month ago • 6 comments

Description

Sometimes the write tools includes some of the metadata in its console & write output.

Happens when a completely new file is created.

-> Wrote .agent/Research/txt_record_quote_handling.md
...

somefile.yaml

- Go `%q` verb: Adds Go-style quoting</content>
<parameter name="filePath">.agent/Research/txt_record_quote_handling.md

already had a short discord chat with @rekram1-node.

OpenCode version

1.0.144

Steps to reproduce

Does not always happen.

Ask the AI Agent to produce a long and detailed report in a markdown style.

Screenshot and/or share link

Image

Operating System

macos 26, fedora 43 gnome

Terminal

ghostty

rwese avatar Dec 11 '25 07:12 rwese

I think the issue happens because params.content sometimes contains metadata blocks. A very small fix is to sanitize the content before writing:

await Bun.write(filepath, typeof params.content === "string" ? params.content : "");

can i go ahead with this fix @rwese @rekram1-node

tajbaba999 avatar Dec 11 '25 09:12 tajbaba999

I am uncertain, this would be a band-aid, but the cause is that the write-tool is receiving this wrongly. 🤷

But it is pretty annoying, i run into this couple of times a day.

rwese avatar Dec 11 '25 16:12 rwese

What is the correct/long-term fix instead of the band-aid workaround?

tajbaba999 avatar Dec 11 '25 19:12 tajbaba999

can someone share the session they replicate this in?

opencode export > session.json

rekram1-node avatar Dec 12 '25 02:12 rekram1-node

Here are found session exports, to find the offending tool calls using ripgrep rg '\/content>\\n<par', pattern works for vim too. i created a script to help me parse through my sessions:

uv run https://raw.githubusercontent.com/rwese/opencode_session_analyzer/main/oc_session_analyzer.py --export

here are the found results.

tool_write_artifacts.tgz

rwese avatar Dec 12 '25 06:12 rwese

one shorter example of the recent

opencode --version

1.0.152

write_tool_output_with_metadata.json

rwese avatar Dec 14 '25 11:12 rwese