Skip to content

Incomplete JSON when writing out files #5890

Description

@rdentato

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

Activity

  1. github-actions commented on Dec 21, 2025

    @github-actions
    Contributor

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

    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.

  2. julioocamargoo commented on Jan 8, 2026

    @julioocamargoo

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

  3. madisonbullard commented on Jan 9, 2026

    @madisonbullard

    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

  4. rdentato commented on Jan 12, 2026

    @rdentato
    Author

    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?

  5. julioocamargoo commented on Jan 12, 2026

    @julioocamargoo

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

  6. thuduc commented on Jan 27, 2026

    @thuduc

    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.

  7. Starlight0798 commented on Jan 31, 2026

    @Starlight0798

    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
  8. Snow-Crash commented on Mar 5, 2026

    @Snow-Crash

    Getting same issue. Error persists among different models. When outoput is too long model is not able to get correct json format.
    A workarond is to direct agent to write to file in chunks.

  9. pchasco commented on Mar 22, 2026

    @pchasco

    Also getting this error. It is frustrating, too, because it falls into a loop trying different solutions and burning tokens the entire time, unfairly spending my money. In my case, it complains of a missing closing brace as well.

  10. removed
    bugSomething isn't working
    on May 3, 2026
  11. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions