Skip to content

Error message: JSON Parse error: Expected '}' #12425

Closed

Description

@Starlight0798

Description

Image

invalid [tool=write, error=Invalid input for tool write: JSON parsing failed:

Error message: JSON Parse error: Expected '}’

I simply asked the agent to complete a project, and it started writing code on its own, which then frequently resulted in this error.

Once this happens, the agent will continuously report errors and retry writing, getting stuck in an infinite loop and unable to continue working. It seems unaware that the write tool call failed.

This issue occurs with both Gemini3 (flash or pro) and Claude (4.5 or 4.6). Why is this?

Plugins

oh-my-opencode-slim, opencode-dcp

OpenCode version

1.1.53

Steps to reproduce

1.ask agent to write a project.
2.Randomly, when writing to a file, it occurs.

Screenshot and/or share link

No response

Operating System

macOS 26.2

Terminal

No response

Activity

  1. github-actions commented on Feb 6, 2026

    @github-actions
    Contributor

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

    These issues share your core symptoms:

    1. JSON parsing errors in write tool payloads
    2. Agent generating malformed JSON and unable to recover
    3. Infinite retry loops when write tool fails
    4. Affects multiple LLM models (Claude, Gemini, etc.)
    5. Same version patterns and error signatures

    Feel free to ignore if your specific case differs, but these likely share the same root cause.

  2. NachoFLizaur commented on Feb 6, 2026

    @NachoFLizaur
    Contributor

    I've encountered this error in the past and the cause of this is most likely that the agent is trying to write more than the model's output token limit (the global default is set to 32K tokens in opencode).

    You could try getting the model to write in smaller chunks or if not setting OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX to a higher value to see if that solves the issue.

  3. Starlight0798 commented on Feb 6, 2026

    @Starlight0798
    Author

    I've encountered this error in the past and the cause of this is most likely that the agent is trying to write more than the model's output token limit (the global default is set to 32K tokens in opencode).

    You could try getting the model to write in smaller chunks or if not setting OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX to a higher value to see if that solves the issue.

    thanks, i will try

  4. github-actions commented on Apr 8, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 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

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions