Incomplete JSON when writing out files #3720

Open
opened 2026-02-16 17:41:13 -05:00 by yindo · 7 comments
Owner

Originally created by @rdentato on GitHub (Dec 21, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

Very often (but not always) when using Claude Opus as a model to generate files, I get an error that the file can't be created due to a JSON error:

⚙ invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"filePath": "/mnt/c/Sync/rootnode/TMP-action2/manuscript/action-ontology-guide.tex".
Error message: JSON Parse error: Expected '}']

It clearly misses the '}' at the end.

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @rdentato on GitHub (Dec 21, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description Very often (but not always) when using Claude Opus as a model to generate files, I get an error that the file can't be created due to a JSON error: ``` ⚙ invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"filePath": "/mnt/c/Sync/rootnode/TMP-action2/manuscript/action-ontology-guide.tex". Error message: JSON Parse error: Expected '}'] ``` It clearly misses the '}' at the end. ### OpenCode version _No response_ ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:41:13 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 21, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #1803: [aws bedrock: anthropic opus 4.1] The arguments provided to the tool are invalid: Invalid input for tool write: JSON parsing failed: Text - Same error with JSON parsing in write tool with incomplete closing braces
  • #2188: JSON parsing failed: Text - Identical error message showing truncated JSON in write tool arguments with missing closing brace
  • #2002: JSON Parse error: Expected '}' with the write tool after updating to v0.5.5 - Previously reported issue with incomplete JSON causing write tool failure

All three issues report the same root cause: incomplete/truncated JSON being generated for the write tool with missing closing braces, resulting in 'JSON Parse error: Expected '}'.

Feel free to ignore if this is a new variation of the issue or if you have more specific details to add.

@github-actions[bot] commented on GitHub (Dec 21, 2025): This issue might be a duplicate of existing issues. Please check: - #1803: [aws bedrock: anthropic opus 4.1] The arguments provided to the tool are invalid: Invalid input for tool write: JSON parsing failed: Text - Same error with JSON parsing in write tool with incomplete closing braces - #2188: JSON parsing failed: Text - Identical error message showing truncated JSON in write tool arguments with missing closing brace - #2002: JSON Parse error: Expected '}' with the write tool after updating to v0.5.5 - Previously reported issue with incomplete JSON causing write tool failure All three issues report the same root cause: incomplete/truncated JSON being generated for the write tool with missing closing braces, resulting in 'JSON Parse error: Expected '}'. Feel free to ignore if this is a new variation of the issue or if you have more specific details to add.
Author
Owner

@julioocamargoo commented on GitHub (Jan 7, 2026):

Same hapenning here. It often happens when I'm using superpowers:writing-plans, but solves when I say to break file on smaller ones.

@julioocamargoo commented on GitHub (Jan 7, 2026): Same hapenning here. It often happens when I'm using superpowers:writing-plans, but solves when I say to break file on smaller ones.
Author
Owner

@madisonbullard commented on GitHub (Jan 8, 2026):

This happens for me occasionally with opus 4.5 as well. A few variables in my current session that could be factors:

  • A lot of subagent calls
  • 48% context used
  • Trying to write 500 lines

once the tool fails, it doesnt seem to be able to recover, even if I describe the missing bracket, or reboot opencode and rejoin the session and ask again

@madisonbullard commented on GitHub (Jan 8, 2026): This happens for me occasionally with opus 4.5 as well. A few variables in my current session that could be factors: - A lot of subagent calls - 48% context used - Trying to write 500 lines once the tool fails, it doesnt seem to be able to recover, even if I describe the missing bracket, or reboot opencode and rejoin the session and ask again
Author
Owner

@rdentato commented on GitHub (Jan 12, 2026):

I believe this is a size issue. I didn't have it for weeks and suddenly got it today. I asked to proceed in chunks and it worked.
It's not just the size of the output, I had worked with bigger files, there must be something else at play.
What is strange is that it only does it with Opus on GH Copilot, not with Opus on Bedrock (which goes by token).
Might it be some size limitation on the GH Copilot part?

@rdentato commented on GitHub (Jan 12, 2026): I believe this is a size issue. I didn't have it for weeks and suddenly got it today. I asked to proceed in chunks and it worked. It's not just the size of the output, I had worked with bigger files, there must be something else at play. What is strange is that it only does it with Opus on GH Copilot, not with Opus on Bedrock (which goes by token). Might it be some size limitation on the GH Copilot part?
Author
Owner

@julioocamargoo commented on GitHub (Jan 12, 2026):

Probably Opus write bigger files. I'm my case it happens using GH copilot Sonnet

@julioocamargoo commented on GitHub (Jan 12, 2026): Probably Opus write bigger files. I'm my case it happens using GH copilot Sonnet
Author
Owner

@thuduc commented on GitHub (Jan 27, 2026):

This happened to me the last couple of days also (GHCP license with Opus 4.5) when opencode was trying to create a design doc of about 110K+ in size. It also failed when I asked it to write out in chunks. However, after exiting from opencode and then resuming (opencode --c), writing out in chunks worked.
This also happened randomly when opencode was working on an implementation task and failed to create a file (same exact error message). The failure caused opencode to stop working. However, prompting it to resume usually works.

@thuduc commented on GitHub (Jan 27, 2026): This happened to me the last couple of days also (GHCP license with Opus 4.5) when opencode was trying to create a design doc of about 110K+ in size. It also failed when I asked it to write out in chunks. However, after exiting from opencode and then resuming (opencode --c), writing out in chunks worked. This also happened randomly when opencode was working on an implementation task and failed to create a file (same exact error message). The failure caused opencode to stop working. However, prompting it to resume usually works.
Author
Owner

@Starlight0798 commented on GitHub (Jan 31, 2026):

the same problem, when I switch model to GLM4.7, this disappears. So I think it maybe because of the written text is too long, and failed.

Image
@Starlight0798 commented on GitHub (Jan 31, 2026): the same problem, when I switch model to GLM4.7, this disappears. So I think it maybe because of the written text is too long, and failed. <img width="1371" height="1489" alt="Image" src="https://github.com/user-attachments/assets/1f328454-2fd2-4c5f-bb5e-c3a4a792d85c" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3720